You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/widget/picker/bee_house_cascade_picker.dart

171 lines
5.6 KiB

3 years ago
import 'package:aku_new_community/models/sars_model/my_house/estate_cascade_model.dart';
import 'package:aku_new_community/models/sars_model/my_house/picked_house.dart';
import 'package:aku_new_community/widget/picker/bee_picker_box.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class BeeHouseCascadePicker extends StatefulWidget {
final List<EstateCascadeModel> buildings;
3 years ago
3 years ago
static Future<PickedHouseModel> pick(
BuildContext context, List<EstateCascadeModel> buildings) async {
var result = await showModalBottomSheet(
context: context,
builder: (context) {
return BeeHouseCascadePicker(buildings: buildings);
});
return result;
}
const BeeHouseCascadePicker({Key? key, required this.buildings})
: super(key: key);
@override
_BeeHouseCascadePickerState createState() => _BeeHouseCascadePickerState();
}
class _BeeHouseCascadePickerState extends State<BeeHouseCascadePicker> {
List<EstateCascadeModel> _buildings = [];
int _pickBuildingIndex = 0;
3 years ago
EstateCascadeModel? get _pickedBuilding {
if (_buildings.isEmpty) {
return null;
}
return _buildings[_pickBuildingIndex];
}
3 years ago
int _pickUnitIndex = 0;
3 years ago
Unit? get _pickedUnit {
if ((_pickedBuilding?.childList ?? []).isEmpty) {
return null;
}
return _pickedBuilding?.childList[_pickUnitIndex];
}
3 years ago
3 years ago
Floor? get _pickedFloor => _pickedUnit?.floors[_pickFloorIndex];
3 years ago
int _pickFloorIndex = 0;
3 years ago
House? get _pickedHouse => _pickedFloor?.houses[_pickHouseIndex];
3 years ago
int _pickHouseIndex = 0;
PickedHouseModel get pickedHouseModel => PickedHouseModel(
building: _pickedBuilding,
unit: _pickedUnit,
floor: _pickedFloor,
house: _pickedHouse,
);
FixedExtentScrollController _unitController = FixedExtentScrollController();
FixedExtentScrollController _floorController = FixedExtentScrollController();
FixedExtentScrollController _houseController = FixedExtentScrollController();
@override
void initState() {
_buildings = widget.buildings;
super.initState();
}
@override
void dispose() {
_unitController.dispose();
_floorController.dispose();
_houseController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BeePickerBox(
onPressed: () {
Get.back(result: pickedHouseModel);
},
child: Row(
children: [
Flexible(
child: CupertinoPicker(
onSelectedItemChanged: (int value) {
_pickBuildingIndex = value;
3 years ago
// _pickUnitIndex = 0;
// _pickFloorIndex = 0;
// _pickHouseIndex = 0;
3 years ago
_unitController.jumpToItem(0);
_floorController.jumpToItem(0);
_houseController.jumpToItem(0);
setState(() {});
},
3 years ago
itemExtent: 100.w,
3 years ago
children: _buildings
.map((e) => Center(
child: Padding(
padding: EdgeInsets.only(left: 20.w, right: 20.w),
child: Text(e.name, textAlign: TextAlign.center),
),
))
.toList(),
),
),
Flexible(
child: CupertinoPicker(
onSelectedItemChanged: (int value) {
_pickUnitIndex = value;
3 years ago
// _pickFloorIndex = 0;
// _pickHouseIndex = 0;
3 years ago
_floorController.jumpToItem(0);
_houseController.jumpToItem(0);
setState(() {});
},
3 years ago
itemExtent: 100.w,
children: (_pickedBuilding?.childList ?? [])
3 years ago
.map((e) => Center(
child: Padding(
padding: EdgeInsets.only(left: 20.w, right: 20.w),
child: Text(e.name, textAlign: TextAlign.center),
),
))
.toList(),
),
),
Flexible(
child: CupertinoPicker(
onSelectedItemChanged: (int value) {
_pickFloorIndex = value;
3 years ago
// _pickHouseIndex = 0;
3 years ago
_houseController.jumpToItem(0);
setState(() {});
},
itemExtent: 80.w,
3 years ago
children: (_pickedUnit?.floors ?? [])
3 years ago
.map((e) => Center(
child: Padding(
padding: EdgeInsets.only(left: 20.w, right: 20.w),
child: Text(e.name, textAlign: TextAlign.center),
),
))
.toList(),
),
),
Flexible(
child: CupertinoPicker(
onSelectedItemChanged: (int value) {
_pickHouseIndex = value;
setState(() {});
},
itemExtent: 80.w,
3 years ago
children: (_pickedFloor?.houses ?? [])
3 years ago
.map((e) => Center(
child: Padding(
padding: EdgeInsets.only(left: 20.w, right: 20.w),
child: Text(e.name, textAlign: TextAlign.center),
),
))
.toList(),
),
)
],
));
}
}