summaryrefslogtreecommitdiffstats
path: root/packages/flutter_calendar_carousel/lib/src/calendar_header.dart
diff options
context:
space:
mode:
Diffstat (limited to 'packages/flutter_calendar_carousel/lib/src/calendar_header.dart')
-rw-r--r--packages/flutter_calendar_carousel/lib/src/calendar_header.dart73
1 files changed, 73 insertions, 0 deletions
diff --git a/packages/flutter_calendar_carousel/lib/src/calendar_header.dart b/packages/flutter_calendar_carousel/lib/src/calendar_header.dart
new file mode 100644
index 0000000..7fcfd81
--- /dev/null
+++ b/packages/flutter_calendar_carousel/lib/src/calendar_header.dart
@@ -0,0 +1,73 @@
+import 'package:flutter/material.dart';
+import 'default_styles.dart' show defaultHeaderTextStyle;
+
+class CalendarHeader extends StatelessWidget {
+ /// Passing in values for [leftButtonIcon] or [rightButtonIcon] will override [headerIconColor]
+ CalendarHeader(
+ {required this.headerTitle,
+ this.headerMargin,
+ required this.showHeader,
+ this.headerTextStyle,
+ this.showHeaderButtons = true,
+ this.headerIconColor,
+ this.leftButtonIcon,
+ this.rightButtonIcon,
+ required this.onLeftButtonPressed,
+ required this.onRightButtonPressed,
+ this.onHeaderTitlePressed})
+ : isTitleTouchable = onHeaderTitlePressed != null;
+
+ final String headerTitle;
+ final EdgeInsetsGeometry? headerMargin;
+ final bool showHeader;
+ final TextStyle? headerTextStyle;
+ final bool showHeaderButtons;
+ final Color? headerIconColor;
+ final Widget? leftButtonIcon;
+ final Widget? rightButtonIcon;
+ final VoidCallback onLeftButtonPressed;
+ final VoidCallback onRightButtonPressed;
+ final bool isTitleTouchable;
+ final VoidCallback? onHeaderTitlePressed;
+
+ TextStyle get getTextStyle => headerTextStyle ?? defaultHeaderTextStyle;
+
+ Widget _leftButton() => IconButton(
+ onPressed: onLeftButtonPressed,
+ icon:
+ leftButtonIcon ?? Icon(Icons.chevron_left, color: headerIconColor),
+ );
+
+ Widget _rightButton() => IconButton(
+ onPressed: onRightButtonPressed,
+ icon: rightButtonIcon ??
+ Icon(Icons.chevron_right, color: headerIconColor),
+ );
+
+ Widget _headerTouchable() => TextButton(
+ onPressed: onHeaderTitlePressed,
+ child: Text(
+ headerTitle,
+ semanticsLabel: headerTitle,
+ style: getTextStyle,
+ ),
+ );
+
+ @override
+ Widget build(BuildContext context) => showHeader
+ ? Container(
+ margin: headerMargin,
+ child: DefaultTextStyle(
+ style: getTextStyle,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: <Widget>[
+ showHeaderButtons ? _leftButton() : Container(),
+ isTitleTouchable
+ ? _headerTouchable()
+ : Text(headerTitle, style: getTextStyle),
+ showHeaderButtons ? _rightButton() : Container(),
+ ])),
+ )
+ : Container();
+}