14.1 顶部导航
 
实现步骤:
第 1 步:i18n
lib/common/i18n/locale_keys.dart
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | static const searchPlaceholder = "search_placeholder";
 static const searchOrder = "search_order";
 static const searchFilter = "search_filter";
 static const searchFilterPrice = "search_filter_price";
 static const searchFilterSize = "search_filter_size";
 static const searchFilterColor = "search_filter_color";
 static const searchFilterReview = "search_filter_review";
 static const searchFilterBrand = "search_filter_brand";
 static const searchFilterGender = "search_filter_gender";
 static const searchFilterCondition = "search_filter_condition";
 
 | 
lib/common/i18n/locales/locale_en.dart
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | LocaleKeys.searchPlaceholder: 'Search Product',
 LocaleKeys.searchOrder: 'Best Match',
 LocaleKeys.searchFilter: 'Filter',
 LocaleKeys.searchFilterPrice: 'Price',
 LocaleKeys.searchFilterSize: 'Size',
 LocaleKeys.searchFilterColor: 'Color',
 LocaleKeys.searchFilterReview: 'Review',
 LocaleKeys.searchFilterBrand: 'Brand',
 LocaleKeys.searchFilterGender: 'Gender',
 LocaleKeys.searchFilterCondition: 'Condition',
 
 | 
lib/common/i18n/locales/locale_zh.dart
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | LocaleKeys.searchPlaceholder: '搜索商品',
 LocaleKeys.searchOrder: '最佳匹配',
 LocaleKeys.searchFilter: '筛选',
 LocaleKeys.searchFilterPrice: '价格',
 LocaleKeys.searchFilterSize: '尺寸',
 LocaleKeys.searchFilterColor: '颜色',
 LocaleKeys.searchFilterReview: '星级',
 LocaleKeys.searchFilterBrand: '品牌',
 LocaleKeys.searchFilterGender: '性别',
 LocaleKeys.searchFilterCondition: '状况',
 
 | 
第 2 步:mainAppBar 主导航栏组件
 
lib/common/components/appbar.dart
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 
 | import 'package:flutter/material.dart';
 import '../index.dart';
 
 
 AppBar mainAppBarWidget({
 Key? key,
 Function()? onTap,
 Widget? leading,
 String? hintText,
 String? titleString,
 double? titleSpace,
 double? iconSize,
 }) {
 return AppBar(
 
 leading: leading,
 
 titleSpacing: titleSpace ?? AppSpace.listItem,
 
 title: hintText != null
 ? InputWidget.textBorder(
 hintText: hintText,
 readOnly: true,
 onTap: onTap,
 )
 : Text(titleString ?? ""),
 
 actions: [
 
 IconWidget.svg(
 AssetsSvgs.iSearchSvg,
 size: iconSize ?? 20,
 ).paddingRight(AppSpace.listItem),
 
 
 IconWidget.svg(
 AssetsSvgs.iNotificationsSvg,
 size: iconSize ?? 20,
 isDot: true,
 ).unconstrained().paddingRight(AppSpace.listItem),
 
 
 IconWidget.svg(
 AssetsSvgs.iIndicatorsSvg,
 size: iconSize ?? 20,
 ).paddingRight(AppSpace.page),
 ],
 );
 }
 
 
 | 
第 3 步:视图
lib/pages/search/search_filter/view.dart
| 12
 3
 4
 
 | Widget _buildFilterBar() {
 return Text("搜索过滤栏");
 }
 
 | 
| 12
 3
 4
 
 | Widget _buildListView() {
 return Text("数据列表");
 }
 
 | 
| 12
 3
 4
 5
 6
 7
 8
 9
 
 | Widget _buildView() {
 return <Widget>[
 
 _buildFilterBar(),
 
 _buildListView(),
 ].toColumn();
 }
 
 | 
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 
 | @overrideWidget build(BuildContext context) {
 return GetBuilder<SearchFilterController>(
 init: SearchFilterController(),
 id: "search_filter",
 builder: (_) {
 return Scaffold(
 
 appBar: mainAppBarWidget(
 
 leading: ButtonWidget.icon(
 IconWidget.icon(
 Icons.arrow_back,
 color: AppColors.primary,
 ),
 onTap: () => Get.back(),
 ),
 
 hintText: LocaleKeys.searchPlaceholder.tr,
 
 onTap: () => Get.back(),
 ),
 
 
 body: _buildView(),
 );
 },
 );
 }
 
 | 
第 4 步:搜索结果进入筛选页面
lib/pages/search/search_index/controller.dart
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 
 | void onListItemTap(TagsModel model) {
 
 Get.toNamed(
 RouteNames.searchSearchFilter,
 arguments: {
 "tagId": model.id,
 },
 );
 }
 
 | 
提交代码到 git