app_bar.dart
3.51 KB
1
2
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';
import '../utils/utils.dart';
class MyAppBar extends StatelessWidget {
MyAppBar(this.title,
{this.showBack = true,
this.backgroundColor = MyColours.color_ffffff,
this.fontColor = MyColours.color_131313,
this.callback,
this.rightImgName,
this.onTapRight});
final VoidCallback? callback; //返回回调
final String title; //标题文字
final bool showBack; //是否显示返回按钮
final Color backgroundColor; //背景色
final Color fontColor; //字体颜色
final String? rightImgName;
final GestureTapCallback? onTapRight;
@override
Widget build(BuildContext context) {
// TODO: implement build
return Container(
width: double.infinity,
color: backgroundColor,
padding: EdgeInsets.symmetric(vertical: ScreenUtil().setHeight(30)),
child: Stack(alignment: Alignment.center, children: <Widget>[
Positioned(
left: 0,
child: showBack
? GestureDetector(
onTap: () {
if (this.callback != null) {
this.callback!();
} else {
Navigator.of(context).pop();
}
},
behavior: HitTestBehavior.opaque,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
vertical: ScreenUtil().setHeight(15)),
child: Image.asset(
"assets/icon_back.png",
width: ScreenUtil().setWidth(20),
height: ScreenUtil().setHeight(31),
),
),
)
: Container(),
),
Center(
child: Text(
title,
style: TextStyle(
color: fontColor,
fontSize: ScreenUtil().setSp(34),
fontWeight: FontWeight.normal,
decoration: TextDecoration.none),
),
),
Positioned(
right: 0,
child: ObjectUtil.isNotEmpty(rightImgName)
? InkWell(
onTap: onTapRight,
child: Padding(
padding:
EdgeInsets.only(right: ScreenUtil().setWidth(40)),
child: rightImgName!.endsWith('png')
? Image.asset(
Utils.getImgPath(
rightImgName!.replaceAll('.png', '')),
width: ScreenUtil().setWidth(48))
: Container(
// color: Colors.red,
alignment: Alignment.center,
child: Text(
rightImgName!,
style: TextStyle(
color: MyColours.color_199095,
fontSize: ScreenUtil().setSp(34)),
),
)),
)
: Text(''))
]));
}
}