1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_template/util/platform/platform_util.dart' ;
3
+ import 'package:flutter_template/widget/general/simple_screen/base_screen_header_safe_area.dart' ;
2
4
import 'package:flutter_template/widget/general/styled/flutter_template_back_button.dart' ;
3
5
import 'package:flutter_template/widget/provider/data_provider_widget.dart' ;
4
6
5
7
class BaseScreenHeader extends StatelessWidget {
8
+ final bool ? centerTitle;
6
9
final String ? title;
7
10
final List <Widget > trailingItems;
8
11
final VoidCallback ? onBackTapped;
9
12
10
13
const BaseScreenHeader ({
11
14
this .onBackTapped,
15
+ this .centerTitle,
12
16
this .title,
13
17
this .trailingItems = const [],
14
18
super .key,
@@ -17,33 +21,58 @@ class BaseScreenHeader extends StatelessWidget {
17
21
@override
18
22
Widget build (BuildContext context) {
19
23
return DataProviderWidget (
20
- childBuilder: (context, theme, localization) => Container (
21
- padding: const EdgeInsets .symmetric (
22
- horizontal: 16 ,
23
- vertical: 12 ,
24
- ),
25
- color: theme.colorsTheme.primary,
26
- child: SafeArea (
27
- bottom: false ,
28
- child: Row (
29
- children: [
30
- if (ModalRoute .of (context)? .impliesAppBarDismissal ?? false ) ...[
31
- FlutterTemplateBackButton .light (onClick: onBackTapped),
32
- const SizedBox (width: 24 ),
33
- ],
34
- if (title != null ) ...[
35
- Expanded (
36
- child: Text (
37
- title! .toUpperCase (),
38
- style: theme.inverseCoreTextTheme.bodyNormal,
39
- ),
24
+ childBuilder: (context, theme, localization) {
25
+ final leading = [
26
+ if (ModalRoute .of (context)? .impliesAppBarDismissal ?? false ) ...[
27
+ FlutterTemplateBackButton .light (onClick: onBackTapped),
28
+ const SizedBox (width: 24 ),
29
+ ],
30
+ ];
31
+ final isTitleCentered = centerTitle ?? PlatformUtil .isIOS;
32
+ final titleWidget = title == null
33
+ ? null
34
+ : Text (
35
+ title! .toUpperCase (),
36
+ style: theme.inverseCoreTextTheme.bodyNormal,
37
+ textAlign: isTitleCentered ? TextAlign .center : TextAlign .start,
38
+ );
39
+
40
+ return Container (
41
+ padding: const EdgeInsets .symmetric (
42
+ horizontal: 16 ,
43
+ vertical: 12 ,
44
+ ),
45
+ color: theme.colorsTheme.primary,
46
+ child: SafeArea (
47
+ bottom: false ,
48
+ child: Stack (
49
+ alignment: Alignment .center,
50
+ children: [
51
+ Row (
52
+ children: [
53
+ ...leading,
54
+ if (titleWidget != null && ! isTitleCentered) ...[
55
+ Expanded (
56
+ child: titleWidget,
57
+ ),
58
+ ] else ...[
59
+ const Spacer (),
60
+ ],
61
+ ...trailingItems,
62
+ ],
40
63
),
64
+ if (isTitleCentered && titleWidget != null ) ...[
65
+ BaseScreenHeaderSafeArea (
66
+ leading: leading,
67
+ actions: trailingItems,
68
+ child: titleWidget,
69
+ ),
70
+ ]
41
71
],
42
- ...trailingItems,
43
- ],
72
+ ),
44
73
),
45
- ),
46
- ) ,
74
+ );
75
+ } ,
47
76
);
48
77
}
49
78
}
0 commit comments