mAppBar function
PreferredSizeWidget
mAppBar({
- String? route,
- String title = '',
- bool? centerTitle,
- Color? titleColor,
- double? titleFontSize,
- FontWeight? titleFontWeight,
- int titleMaxLine = 1,
- double height = 0,
- double? elevation,
- bool backEnable = false,
- bool autoBackEnable = true,
- Color? backgroundColor,
- IconData? backIconData,
- Color? backIconColor,
- Widget? leading,
- VoidCallback? backPressed,
- List<
Widget> ? actions, - PreferredSizeWidget? bottom,
- double? titleSpacing,
- double? leadingWidth,
- double? backIconSize = 20,
- Widget? titleView,
- SystemUiOverlayStyle? systemOverlayStyle,
- bool automaticallyImplyLeading = true,
- String? semanticsLabel,
- double? scrolledUnderElevation,
- dynamic backResult,
- EdgeInsetsGeometry? padding,
统一appbar
Implementation
PreferredSizeWidget mAppBar({
String? route,
String title = '',
bool? centerTitle,
Color? titleColor,
double? titleFontSize,
FontWeight? titleFontWeight,
int titleMaxLine = 1,
double height = 0,
double? elevation,
bool backEnable = false,
bool autoBackEnable = true,
Color? backgroundColor,
IconData? backIconData,
Color? backIconColor, // 左侧返回按钮
Widget? leading, // 自定义左侧按钮
VoidCallback? backPressed,
List<Widget>? actions,
PreferredSizeWidget? bottom,
double? titleSpacing,
double? leadingWidth,
double? backIconSize = 20,
Widget? titleView,
SystemUiOverlayStyle? systemOverlayStyle,
bool automaticallyImplyLeading = true,
String? semanticsLabel,
double? scrolledUnderElevation,
dynamic backResult,
EdgeInsetsGeometry? padding,
}) {
if (autoBackEnable) {
backEnable = Nav.isPopEnable(route: route);
}
/// 默认返回按钮
final Widget leadingDefault = IconButton(
icon: Icon(
backIconData ?? Icons.arrow_back_ios_new,
color: backIconColor,
size: backIconSize,
),
onPressed: backPressed ??
() {
clickBack(result: backResult, route: route);
},
);
Widget? leadingReal;
if (leading != null) {
leadingReal = leading;
} else if (backEnable || backPressed != null) {
leadingReal = leadingDefault;
} else {
leadingReal = const SizedBox.shrink();
leadingWidth = 0;
}
var bar = AppBar(
leading: leadingReal,
elevation: elevation,
scrolledUnderElevation: scrolledUnderElevation,
backgroundColor: backgroundColor,
centerTitle: centerTitle,
automaticallyImplyLeading: automaticallyImplyLeading,
title: titleView ??
Builder(
builder: (ctx) => mText(
title,
maxLines: titleMaxLine,
semanticsLabel: semanticsLabel,
style: Theme.of(ctx).appBarTheme.titleTextStyle?.copyWith(
fontWeight: titleFontWeight,
color: titleColor,
fontSize: titleFontSize,
),
),
),
actions: actions,
bottom: bottom,
titleSpacing: titleSpacing,
leadingWidth: leadingWidth,
systemOverlayStyle: systemOverlayStyle ?? getSystemOverlayStyle(),
);
double pHeight = (height != 0 ? height : BaseDimens.dAppBarHeight) + (bottom?.preferredSize.height ?? 0);
return PreferredSize(
preferredSize: Size.fromHeight(pHeight),
child: padding == null
? bar
: Container(
padding: padding,
child: bar,
));
}