91 lines
3.5 KiB
Dart
91 lines
3.5 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:get/get.dart';
|
||
|
import 'package:sk_base_mobile/app_theme.dart';
|
||
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
||
|
import 'package:sk_base_mobile/widgets/core/sk_cascade_picker.dart';
|
||
|
import 'package:sk_base_mobile/widgets/gradient_button.dart';
|
||
|
|
||
|
class DeptPicker extends StatelessWidget {
|
||
|
DeptPicker({super.key});
|
||
|
|
||
|
final _cascadeController = Get.put(CascadeController());
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Container(
|
||
|
decoration: BoxDecoration(color: AppTheme.nearlyWhite),
|
||
|
height: ScreenAdaper.height(400),
|
||
|
child: Column(
|
||
|
children: [
|
||
|
GradientButton(
|
||
|
buttonText: '确定',
|
||
|
onPressed: () {
|
||
|
if (_cascadeController.isCompleted()) {
|
||
|
// 已选中的titles
|
||
|
List<String> selectedTitles =
|
||
|
_cascadeController.selectedTitles;
|
||
|
print("已选中的titles: $selectedTitles");
|
||
|
// 已选中的序号
|
||
|
List<int> selectedIndexes =
|
||
|
_cascadeController.selectedIndexes;
|
||
|
print("已选中的序号:$selectedIndexes");
|
||
|
|
||
|
Item item = _cascadeController
|
||
|
.items[selectedIndexes[0]]
|
||
|
.children![selectedIndexes[1]]
|
||
|
.children![selectedIndexes[2]];
|
||
|
print("已选择item( ${item.name} )");
|
||
|
}
|
||
|
},
|
||
|
),
|
||
|
SizedBox(
|
||
|
height: 10,
|
||
|
),
|
||
|
Expanded(
|
||
|
child: CascadePicker(
|
||
|
initialPageData:
|
||
|
_cascadeController.items.map((e) => e.name!).toList(),
|
||
|
nextPageData: (pageCallback, currentPage, selectIndex) async {
|
||
|
print("当前选择: 第$currentPage页, 第$selectIndex项");
|
||
|
if (currentPage == 1) {
|
||
|
// 在第一页选中,返回第二页列表数据
|
||
|
List<String>? nextPageData = _cascadeController
|
||
|
.items[selectIndex].children
|
||
|
?.map((e) => e.name!)
|
||
|
.toList();
|
||
|
if (nextPageData != null) pageCallback(nextPageData);
|
||
|
} else if (currentPage == 2) {
|
||
|
// 在第二页选中,返回第二页列表数据
|
||
|
// 先获取已选中的序号
|
||
|
List<int> selectedIndexes =
|
||
|
_cascadeController.selectedIndexes;
|
||
|
// 根据已选中的序号在items中获取下一级页面的列表数据
|
||
|
List<String>? nextPageData = _cascadeController
|
||
|
.items[selectedIndexes[0]].children?[selectIndex].children
|
||
|
?.map((e) => e.name!)
|
||
|
.toList();
|
||
|
if (nextPageData != null) pageCallback(nextPageData);
|
||
|
}
|
||
|
},
|
||
|
controller: _cascadeController,
|
||
|
maxPageNum: 3,
|
||
|
tabTitleStyle: TextStyle(
|
||
|
fontSize: ScreenAdaper.height(26), color: Colors.black),
|
||
|
itemTitleStyle: TextStyle(
|
||
|
fontSize: ScreenAdaper.height(26), color: Colors.black),
|
||
|
selectedIcon:
|
||
|
Icon(Icons.check, color: AppTheme.primaryColorLight),
|
||
|
))
|
||
|
],
|
||
|
));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class Item {
|
||
|
String? name;
|
||
|
String? code;
|
||
|
String? fatherCode;
|
||
|
String? remark;
|
||
|
List<Item>? children;
|
||
|
}
|