|
18 | 18 | import 'package:flutter/material.dart'; |
19 | 19 |
|
20 | 20 | class LockinAppBar extends StatelessWidget implements PreferredSizeWidget { |
21 | | - const LockinAppBar({required this.title, this.actions, super.key}); |
| 21 | + const LockinAppBar({ |
| 22 | + required this.title, |
| 23 | + this.actions, |
| 24 | + this.leading, |
| 25 | + this.bottom, |
| 26 | + this.centerTitle = false, |
| 27 | + this.elevation, |
| 28 | + this.backgroundColor, |
| 29 | + super.key, |
| 30 | + }); |
| 31 | + |
22 | 32 | final String title; |
23 | 33 | final List<Widget>? actions; |
| 34 | + final Widget? leading; |
| 35 | + final PreferredSizeWidget? bottom; |
| 36 | + final bool centerTitle; |
| 37 | + final double? elevation; |
| 38 | + final Color? backgroundColor; |
| 39 | + |
| 40 | + static const List<Widget> _defaultActions = [_SettingsAction()]; |
24 | 41 |
|
25 | 42 | @override |
26 | 43 | Widget build(BuildContext context) { |
27 | | - final defaultActions = [ |
28 | | - IconButton.filledTonal( |
29 | | - icon: const Icon(Icons.settings), |
30 | | - onPressed: () => Navigator.of(context).pushNamed('/settings'), |
31 | | - ), |
32 | | - ]; |
33 | | - return SafeArea( |
34 | | - bottom: false, |
35 | | - child: Column( |
36 | | - mainAxisSize: MainAxisSize.min, |
37 | | - children: [ |
38 | | - Flexible( |
39 | | - child: Padding( |
40 | | - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), |
41 | | - child: Row( |
42 | | - mainAxisAlignment: MainAxisAlignment.spaceBetween, |
43 | | - children: [ |
44 | | - Expanded( |
45 | | - child: Text( |
46 | | - title, |
47 | | - maxLines: 1, |
48 | | - overflow: TextOverflow.ellipsis, |
49 | | - style: Theme.of( |
50 | | - context, |
51 | | - ).textTheme.headlineSmall?.copyWith(letterSpacing: 1.1), |
52 | | - ), |
53 | | - ), |
54 | | - Row( |
55 | | - mainAxisSize: MainAxisSize.min, |
56 | | - children: actions ?? defaultActions, |
57 | | - ), |
58 | | - ], |
59 | | - ), |
60 | | - ), |
61 | | - ), |
62 | | - // Subtle divider |
63 | | - Container(height: 1, color: Colors.white.withValues(alpha: 0.08)), |
64 | | - ], |
| 44 | + final actionsList = actions ?? _defaultActions; |
| 45 | + |
| 46 | + return AppBar( |
| 47 | + title: Text( |
| 48 | + title, |
| 49 | + style: Theme.of( |
| 50 | + context, |
| 51 | + ).textTheme.headlineSmall?.copyWith(letterSpacing: 1.1), |
65 | 52 | ), |
| 53 | + actionsPadding: const EdgeInsets.symmetric(horizontal: 16), |
| 54 | + centerTitle: centerTitle, |
| 55 | + leading: leading, |
| 56 | + actions: actionsList, |
| 57 | + bottom: bottom, |
| 58 | + elevation: elevation, |
| 59 | + toolbarHeight: 64, |
66 | 60 | ); |
67 | 61 | } |
68 | 62 |
|
69 | 63 | @override |
70 | | - Size get preferredSize => const Size.fromHeight(64); |
| 64 | + Size get preferredSize { |
| 65 | + var height = 64.0; |
| 66 | + if (bottom != null) { |
| 67 | + height += bottom!.preferredSize.height; |
| 68 | + } |
| 69 | + return Size.fromHeight(height); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +class _SettingsAction extends StatelessWidget { |
| 74 | + const _SettingsAction(); |
| 75 | + |
| 76 | + @override |
| 77 | + Widget build(BuildContext context) { |
| 78 | + return IconButton.filledTonal( |
| 79 | + icon: const Icon(Icons.settings), |
| 80 | + onPressed: () => Navigator.of(context).pushNamed('/settings'), |
| 81 | + ); |
| 82 | + } |
71 | 83 | } |
0 commit comments