You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.4 KiB
158 lines
4.4 KiB
import 'package:flutter/material.dart'; |
|
import 'package:flutter/services.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
class MyAppBar extends StatelessWidget implements PreferredSizeWidget { |
|
final Function? onTap; |
|
final Widget? action; |
|
List<Widget>? actions; |
|
final PreferredSizeWidget? bottom; |
|
final Widget? titleChild; |
|
final String? title; |
|
final double titleSize; |
|
final Color titleColor; |
|
final Color leadingColor; |
|
final Color background; |
|
final Size preferredSize; |
|
final double toolbarHeight; |
|
final bool leading; |
|
final bool centerTitle; |
|
final SystemUiOverlayStyle systemUiOverlayStyle; |
|
final Function? exit; |
|
|
|
MyAppBar( |
|
{this.onTap, |
|
this.action, |
|
this.actions, |
|
this.bottom, |
|
this.titleChild, |
|
this.title, |
|
this.toolbarHeight = kToolbarHeight, |
|
this.background = const Color(0xFFF7F7F7), |
|
this.leadingColor = Colors.black, |
|
this.titleColor = Colors.black, |
|
this.titleSize = 18, |
|
this.systemUiOverlayStyle = SystemUiOverlayStyle.dark, |
|
this.leading = true, |
|
this.centerTitle = true, |
|
this.exit}) |
|
: preferredSize = |
|
Size.fromHeight(toolbarHeight + (bottom != null ? 35 : 0)) { |
|
if (actions == null) actions = []; |
|
if (action != null) { |
|
actions!.add( |
|
Container( |
|
margin: EdgeInsets.only(right: 15), |
|
alignment: Alignment.center, |
|
child: GestureDetector( |
|
onTap: onTap?.call(), |
|
child: action, |
|
), |
|
), |
|
); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return AppBar( |
|
backgroundColor: background, |
|
elevation: 0, |
|
scrolledUnderElevation: 0, |
|
systemOverlayStyle: systemUiOverlayStyle, |
|
leading: leading |
|
? GestureDetector( |
|
behavior: HitTestBehavior.opaque, |
|
onTap: () { |
|
if (exit == null) |
|
Navigator.of(context).pop(); |
|
else |
|
exit!.call(); |
|
}, |
|
child: Icon( |
|
Icons.arrow_back_ios, |
|
color: leadingColor, |
|
size: 22, |
|
), |
|
) |
|
: Container(), |
|
title: ((title == null || title == "") && titleChild != null) |
|
? titleChild |
|
: GestureDetector( |
|
onTap: () { |
|
if (exit == null) |
|
Navigator.of(context).pop(); |
|
else |
|
exit!.call(); |
|
}, |
|
child: Text( |
|
title ?? "", |
|
style: TextStyle( |
|
color: titleColor, |
|
fontWeight: MyFontWeight.medium, |
|
fontSize: titleSize, |
|
), |
|
), |
|
), |
|
actions: actions, |
|
bottom: bottom, |
|
); |
|
} |
|
} |
|
|
|
// MyAppBar( |
|
// leading: false, |
|
// centerTitle: false, |
|
// toolbarHeight: kToolbarHeight + 58, |
|
// titleChild: PreferredSize( |
|
// preferredSize: Size( |
|
// MediaQuery.of(context).size.width - 60.w, |
|
// kToolbarHeight, |
|
// ), |
|
// child: Theme( |
|
// data: ThemeData( |
|
// splashColor: Colors.transparent, // 点击时的水波纹颜色设置为透明 |
|
// highlightColor: Colors.transparent, // 点击时的背景高亮颜色设置为透明 |
|
// ), |
|
// child: Container( |
|
// alignment: Alignment.bottomCenter, |
|
// child: TabBar( |
|
// controller: tabcontroller, |
|
// automaticIndicatorColorAdjustment: true, |
|
// isScrollable: true, |
|
// indicatorWeight: 2, |
|
// indicatorColor: Color(0xFF39B54A), |
|
// labelPadding: EdgeInsets.only(left: 8.w, right: 8.w), |
|
// indicatorSize: TabBarIndicatorSize.label, |
|
// unselectedLabelStyle: TextStyle( |
|
// fontSize: MediaQuery.of(context).size.width >= 650 ? 10.sp : 15.sp, |
|
// fontWeight: FontWeight.w400, |
|
// ), |
|
// labelStyle: TextStyle( |
|
// color: Colors.black, |
|
// fontSize: |
|
// MediaQuery.of(context).size.width >= 650 ? 12.sp : 18.sp, |
|
// fontWeight: FontWeight.bold, |
|
// ), |
|
// labelColor: Colors.black, |
|
// tabs: lables.map((e) => MyTab(text: e)).toList(), |
|
// ), |
|
// ), |
|
// ), |
|
// ), |
|
// // onTap: () { |
|
// // _toRelease(); |
|
// // }, |
|
// // action: GestureDetector( |
|
// // behavior: HitTestBehavior.opaque, |
|
// // child: Container(color: Colors.transparent, |
|
// // padding: EdgeInsets.only(left: 20,right: 20), |
|
// // child: SvgPicture.asset( |
|
// // "assets/svg/shequ_fabu.svg", |
|
// // fit: BoxFit.contain, |
|
// // width: 24, |
|
// // height: 24, |
|
// // ),) |
|
// // ) |
|
// )
|
|
|