my_app_bar.dart
2.45 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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:Parlando/util/theme_utils.dart';
import 'package:Parlando/res/resources.dart';
/// 自定义AppBar
class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
const MyAppBar({
Key? key,
this.backgroundColor,
this.onPressed,
this.isBack = true,
this.homeMenuHeader,
this.homeActionWidgets,
this.isTransparent = false,
}) : super(key: key);
final Color? backgroundColor;
final VoidCallback? onPressed;
final bool isBack;
final bool isTransparent;
final Widget? homeMenuHeader;
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;
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: Icon(
Icons.arrow_back_ios_outlined,
color: isTransparent ? Colors.black54 : Colors.white,
),
)
: Gaps.empty;
return AnnotatedRegion<SystemUiOverlayStyle>(
value: _overlayStyle,
child: Material(
color: isTransparent ? Colors.transparent : Colors.black,
child: SafeArea(
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
left: 5,
child: back,
),
SizedBox(
width: MediaQuery.of(context).size.width,
child: homeMenuHeader,
),
SizedBox(
child: Container(
padding: const EdgeInsets.only(top: 10.0),
alignment: Alignment.centerRight,
child: homeActionWidgets,
),
),
],
),
),
),
);
}
@override
Size get preferredSize => const Size.fromHeight(48.0);
}