my_app_bar.dart
5.37 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:one_poem/util/theme_utils.dart';
import 'package:one_poem/res/resources.dart';
/// 自定义AppBar
class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
const MyAppBar({
Key? key,
this.backgroundColor,
this.onPressed,
this.isBack = true,
this.homeTitleHeader,
this.homeActionWidgets,
this.isTransparent = false,
}) : super(key: key);
final Color? backgroundColor;
final VoidCallback? onPressed;
final bool isBack;
final bool isTransparent;
final Widget? homeTitleHeader;
final Widget? homeActionWidgets;
@override
Widget build(BuildContext context) {
final Color _backgroundColor = backgroundColor ?? context.backgroundColor;
final SystemUiOverlayStyle _overlayStyle =
ThemeData.estimateBrightnessForColor(_backgroundColor) ==
Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark;
<<<<<<< HEAD
final Widget action = actionName.isNotEmpty
? Positioned(
right: 0.0,
child: Theme(
data: Theme.of(context).copyWith(
buttonTheme: const ButtonThemeData(
padding: EdgeInsets.symmetric(horizontal: 16.0),
minWidth: 60.0,
),
),
child: Row(
children: [
Icon(
Icons.star,
color: Colors.white.withOpacity(0.66),
),
Gaps.hGap10,
Icon(
Icons.ios_share,
color: Colors.white.withOpacity(0.66),
),
Gaps.hGap10,
Icon(
Icons.more_horiz,
color: Colors.white.withOpacity(0.66),
),
Gaps.hGap10,
],
),
),
)
: Gaps.empty;
=======
>>>>>>> 9fecb8a6ef8a0360e7ff66980f084c393cc257ed
final Widget back = isBack
? IconButton(
onPressed: () async {
FocusManager.instance.primaryFocus?.unfocus();
final isBack = await Navigator.maybePop(context);
if (!isBack) {
await SystemNavigator.pop();
}
},
tooltip: '返回',
padding: const EdgeInsets.all(12.0),
icon: const Icon(Icons.arrow_back_ios_outlined),
)
: Gaps.empty;
<<<<<<< HEAD
// TODO 复用组件
final Widget titleWidget = Semantics(
namesRoute: true,
header: true,
child: isShowButtons
? Container(
width: double.infinity,
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
//交叉轴的布局方式,对于column来说就是水平方向的布局方式
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () => funcLeft!(),
child: Text(
buttonLeft ?? "一言",
style: const TextStyle(color: Colors.white),
),
),
const Text("|"),
TextButton(
onPressed: () => funcCenter!(),
child: Text(
buttonCenter ?? "译解",
style: const TextStyle(color: Colors.white),
),
),
const Text("|"),
TextButton(
onPressed: () => funcRight!(),
child: Text(
buttonRight ?? "临境",
style: const TextStyle(color: Colors.white),
),
),
],
),
)
: Gaps.hGap10,
);
=======
>>>>>>> 9fecb8a6ef8a0360e7ff66980f084c393cc257ed
return AnnotatedRegion<SystemUiOverlayStyle>(
value: _overlayStyle,
child: Material(
color: isTransparent ? Colors.transparent : Colors.black,
child: SafeArea(
<<<<<<< HEAD
child: Flex(
direction: Axis.horizontal,
children: [
Expanded(
child: back,
flex: 1,
),
Expanded(
child: titleWidget,
flex: 4,
),
Expanded(
child: action,
flex: 2,
=======
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
left: 5,
child: back,
),
SizedBox(
width: MediaQuery.of(context).size.width,
child: homeTitleHeader,
),
SizedBox(
child: Container(
alignment: Alignment.centerRight,
child: homeActionWidgets,
),
>>>>>>> 9fecb8a6ef8a0360e7ff66980f084c393cc257ed
),
],
),
),
),
);
}
@override
Size get preferredSize => const Size.fromHeight(48.0);
}