14.3 过滤面板 - 显示
实现步骤:
第 1 步:控制器
lib/pages/search/search_filter/controller.dart
1
| final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
1 2 3 4
| void onFilterOpenTap() { scaffoldKey.currentState?.openEndDrawer(); }
|
1 2 3 4
| void onFilterCloseTap() { Get.back(); }
|
第 2 步:FilterView 视图
lib/pages/search/search_filter/widgets/filter_view.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class FilterView extends GetView<SearchFilterController> { const FilterView({Key? key}) : super(key: key);
Widget _buildView() { return <Widget>[ _buildTopBar(), ] .toColumn( crossAxisAlignment: CrossAxisAlignment.start, ) .paddingHorizontal(AppSpace.page); }
@override Widget build(BuildContext context) { return GetBuilder<SearchFilterController>( id: "filter_view", builder: (_) { return _buildView(); }, ); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Widget _buildTopBar() { return <Widget>[ TextWidget.title3(LocaleKeys.searchFilter.tr),
ButtonWidget.icon( IconWidget.icon( Icons.close, size: 15, color: AppColors.secondary, ), onTap: controller.onFilterCloseTap, ) ] .toRow( mainAxisAlignment: MainAxisAlignment.spaceBetween, ) .paddingBottom(AppSpace.listRow); }
|
第 3 步:视图
lib/pages/search/search_filter/view.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Widget _buildFilterBar() { return <Widget>[ ...
ButtonWidget.dropdown( LocaleKeys.searchFilter.tr, IconWidget.icon( Icons.expand_more, color: AppColors.primary, ), onTap: controller.onFilterOpenTap, textSize: 15, textColor: AppColors.secondary, textWeight: FontWeight.w400, borderColor: AppColors.surfaceVariant, height: 40.h, ).expanded(), ].toRow(); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| @override Widget build(BuildContext context) { return GetBuilder<SearchFilterController>( init: SearchFilterController(), id: "search_filter", builder: (_) { return Scaffold( key: controller.scaffoldKey,
...
...
endDrawer: const Drawer( child: SafeArea(child: FilterView()), ), ); }, ); }
|
提交代码到 git