myAppBar function
自定义AppBar
canPop是否显示返回按钮backgroundColor背景色titleappBar标题leadingwidget类型,如果为空默认返回ios风格返回按钮actions右侧图标,List
Implementation
PreferredSizeWidget myAppBar(
{bool canPop = true,
Color? backgroundColor,
required String title,
List<Widget>? actions,
Widget? leading,
bool? centerTitle,
double? leadingWidth,
required bool defaultFlexibleSpace,
double? toolbarHeight,
PreferredSizeWidget? bottom,
Function? back}) {
return AppBar(
backgroundColor: backgroundColor ?? Colors.white,
toolbarHeight: toolbarHeight ?? 44.w,
elevation: 0,
centerTitle: centerTitle ?? true,
title: SizedBox(
height: 44.w,
child: Column(
children: [
const Spacer(),
Container(
// color: Colors.blue,
margin: EdgeInsets.only(bottom: 10.w),
child: Text(
title,
style: TextStyle(
fontSize: 18.sp,
color: defaultFlexibleSpace ? Colors.white : AppColor.mainText,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
leadingWidth: 50.h,
leading: canPop
? IconButton(
iconSize: 18.w,
// splashRadius: 25.w,
// padding: EdgeInsets.zero,
alignment: Alignment.center,
onPressed: () {
if (back != null) {
back.call();
} else {
Get.back();
}
},
icon: Icon(
Icons.arrow_back_ios_new,
color: defaultFlexibleSpace ? Colors.white : AppColor.mainText,
size: 18.w,
),
)
: null,
actions: actions,
// flexibleSpace: defaultFlexibleSpace
// ? Container(
// decoration: BoxDecoration(
// gradient: LinearGradient(
// colors: [
// AppColor.radientStart,
// AppColor.radientEnd,
// ],
// begin: Alignment.topCenter,
// end: Alignment.bottomCenter,
// ),
// ),
// )
// : null,
automaticallyImplyLeading: false,
bottom: bottom,
);
}