|
1 | 1 | import 'package:flutter/material.dart'; |
2 | | - |
| 2 | +import 'package:common/date.dart'; |
| 3 | +import 'package:intl/intl.dart'; |
3 | 4 | import 'appbar_button.dart'; |
4 | 5 |
|
| 6 | +const APP_BAR_HEIGHT = 80.0; |
| 7 | + |
| 8 | +class DateRangeAppBar extends StatelessWidget implements PreferredSizeWidget { |
| 9 | + final Icon leadingIcon; |
| 10 | + final Icon actionIcon; |
| 11 | + final void Function()? onLeadingTap; |
| 12 | + final void Function()? onActionTap; |
| 13 | + final DateRange dateRange; |
| 14 | + final void Function(DateRange)? onRangeChanged; |
| 15 | + final DateFormat dateFormat; |
| 16 | + |
| 17 | + DateRangeAppBar( |
| 18 | + {required this.dateRange, |
| 19 | + this.leadingIcon = const Icon(Icons.menu), |
| 20 | + this.onLeadingTap, |
| 21 | + this.actionIcon = const Icon(Icons.edit), |
| 22 | + this.onActionTap, |
| 23 | + this.onRangeChanged, |
| 24 | + DateFormat? dateFormat}) |
| 25 | + : this.dateFormat = dateFormat ?? DateFormat('MM/dd'); |
| 26 | + |
| 27 | + @override |
| 28 | + Size get preferredSize => Size.fromHeight(APP_BAR_HEIGHT); |
| 29 | + |
| 30 | + @override |
| 31 | + Widget build(BuildContext context) { |
| 32 | + final appBarTheme = Theme.of(context).appBarTheme; |
| 33 | + final osTopPadding = MediaQuery.of(context).padding.top; |
| 34 | + |
| 35 | + return Stack( |
| 36 | + children: [ |
| 37 | + Material( |
| 38 | + elevation: appBarTheme.elevation ?? 0, |
| 39 | + child: Container( |
| 40 | + height: osTopPadding, |
| 41 | + color: appBarTheme.backgroundColor, |
| 42 | + ), |
| 43 | + ), |
| 44 | + AppBar( |
| 45 | + toolbarHeight: 100, |
| 46 | + title: ElevatedButton( |
| 47 | + style: ElevatedButton.styleFrom( |
| 48 | + backgroundColor: appBarTheme.backgroundColor, |
| 49 | + elevation: 0, |
| 50 | + textStyle: appBarTheme.titleTextStyle, |
| 51 | + foregroundColor: appBarTheme.titleTextStyle!.color, |
| 52 | + ), |
| 53 | + child: Row( |
| 54 | + mainAxisAlignment: MainAxisAlignment.center, |
| 55 | + children: [ |
| 56 | + Icon(Icons.calendar_month), |
| 57 | + Text( |
| 58 | + '${dateRange.start.format(dateFormat)} - ${dateRange.end.format(dateFormat)}') |
| 59 | + ], |
| 60 | + ), |
| 61 | + onPressed: () {}, |
| 62 | + ), |
| 63 | + leading: Transform.scale( |
| 64 | + scale: 0.85, |
| 65 | + child: AppBarButton( |
| 66 | + icon: leadingIcon, |
| 67 | + onPressed: () => onLeadingTap?.call(), |
| 68 | + ), |
| 69 | + ), |
| 70 | + actions: <Widget>[ |
| 71 | + AppBarButton( |
| 72 | + icon: actionIcon, |
| 73 | + onPressed: () => onActionTap?.call(), |
| 74 | + ) |
| 75 | + ], |
| 76 | + ), |
| 77 | + ], |
| 78 | + ); |
| 79 | + } |
| 80 | +} |
| 81 | + |
5 | 82 | class SearchAppBar extends StatefulWidget implements PreferredSizeWidget { |
6 | 83 | final Icon leadingIcon; |
7 | 84 | final void Function()? onLeadingTap; |
|
0 commit comments