10.1 导航栏组件抽取
发现很多界面都用到了这个导航功能,抽取到 lib/common/components 下面
 
实现步骤:
第 1 步:mainAppBar 组件编写
注意组件内不要用 .w .h 这种动态计算的方式,我们只有在 业务 UI 层调用时才传入,详见代码规范。
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
 
 | 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),
 ],
 );
 }
 
 | 
第 2 步:全局样式定制
lib/common/style/theme.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
 
 | class AppTheme {
 
 static ThemeData light = ThemeData(
 colorScheme: lightColorScheme,
 fontFamily: "Montserrat",
 appBarTheme: const AppBarTheme(
 
 systemOverlayStyle: SystemUiOverlayStyle.dark,
 
 backgroundColor: Colors.transparent,
 
 elevation: 0,
 
 iconTheme: IconThemeData(
 color: Color(0xFF5F84FF),
 ),
 
 titleTextStyle: TextStyle(
 color: Color(0xFF4D4D4D),
 fontSize: 24,
 fontWeight: FontWeight.w600,
 ),
 ),
 );
 
 | 
我们这边调整了 appBar 的透明、图标颜色、标题样式
提交代码到 git