From 82f7935d4a68e95057d04c3c2275f993b516e946 Mon Sep 17 00:00:00 2001 From: Edgar Date: Fri, 15 Feb 2019 11:10:28 +0700 Subject: [PATCH 01/15] create calendar header --- lib/src/calendar_header.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/src/calendar_header.dart diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart new file mode 100644 index 0000000..a3c9752 --- /dev/null +++ b/lib/src/calendar_header.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; +import 'default_styles.dart'; + +class CalendarHeader extends StatelessWidget { + + @override + Widget build(BuildContext context) { + // TODO: implement build + return null; + } +} \ No newline at end of file From 79b15c5a6ccd6fc77e39eede4bcc988f29de9bd7 Mon Sep 17 00:00:00 2001 From: Edgar Date: Fri, 15 Feb 2019 11:18:10 +0700 Subject: [PATCH 02/15] define header variables --- lib/src/calendar_header.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index a3c9752..9f22801 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -2,6 +2,24 @@ import 'package:flutter/material.dart'; import 'default_styles.dart'; class CalendarHeader extends StatelessWidget { + CalendarHeader({ + this.showHeader, + this.headerStyle, + this.showHeaderButtons, + this.headerIconColor, + this.onLeftButtonPressed, + this.onRightButtonPressed, + this.isTitleTouchable, + this.onHeaderTitlePressed + }); + final bool showHeader; + final TextStyle headerStyle; + final bool showHeaderButtons; + final Color headerIconColor; + final VoidCallback onLeftButtonPressed; + final VoidCallback onRightButtonPressed; + final bool isTitleTouchable; + final VoidCallback onHeaderTitlePressed; @override Widget build(BuildContext context) { From 7a8dcad5146d0e9ba207c8ccc0b6fecbcf367229 Mon Sep 17 00:00:00 2001 From: Edgar Date: Fri, 15 Feb 2019 12:06:05 +0700 Subject: [PATCH 03/15] create composable header widget --- lib/src/calendar_header.dart | 58 +++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index 9f22801..6659462 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -3,17 +3,22 @@ import 'default_styles.dart'; class CalendarHeader extends StatelessWidget { CalendarHeader({ + this.headerTitle, + this.headerMargin, this.showHeader, - this.headerStyle, + this.headerTextStyle, this.showHeaderButtons, this.headerIconColor, this.onLeftButtonPressed, this.onRightButtonPressed, this.isTitleTouchable, this.onHeaderTitlePressed - }); + }) : assert (onHeaderTitlePressed != null, headerTitle != null); + + final String headerTitle; + final EdgeInsetsGeometry headerMargin; final bool showHeader; - final TextStyle headerStyle; + final TextStyle headerTextStyle; final bool showHeaderButtons; final Color headerIconColor; final VoidCallback onLeftButtonPressed; @@ -21,9 +26,48 @@ class CalendarHeader extends StatelessWidget { final bool isTitleTouchable; final VoidCallback onHeaderTitlePressed; + Widget _leftButton() => IconButton( + onPressed: onLeftButtonPressed, + icon: Icon(Icons.chevron_left, + color: headerIconColor + ), + ); + + Widget _rightButton() => IconButton( + onPressed: onRightButtonPressed, + icon: Icon(Icons.chevron_right, + color: headerIconColor + ), + ); + + Widget _headerTouchable() => FlatButton( + onPressed: onHeaderTitlePressed, + child: Text(headerTitle, style: headerTextStyle), + ); + @override - Widget build(BuildContext context) { - // TODO: implement build - return null; - } + Widget build(BuildContext context) => + showHeader ? + Container( + margin: headerMargin, + child: DefaultTextStyle( + style: headerTextStyle != null + ? headerTextStyle + : defaultHeaderTextStyle, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + showHeaderButtons + ? _leftButton() + : Container(), + isTitleTouchable + ? _headerTouchable() + : Text(headerTitle, style: headerTextStyle), + showHeaderButtons + ? _rightButton() + : Container(), + ] + ) + ), + ) : Container(); } \ No newline at end of file From a780dd39fcd6888c0c8ebdcae584c8eb03981fce Mon Sep 17 00:00:00 2001 From: Edgar Date: Fri, 15 Feb 2019 12:21:48 +0700 Subject: [PATCH 04/15] use calendar header widget --- lib/flutter_calendar_carousel.dart | 62 ++++++++---------------------- lib/src/calendar_header.dart | 10 ++--- 2 files changed, 21 insertions(+), 51 deletions(-) diff --git a/lib/flutter_calendar_carousel.dart b/lib/flutter_calendar_carousel.dart index f6beafe..63123a8 100644 --- a/lib/flutter_calendar_carousel.dart +++ b/lib/flutter_calendar_carousel.dart @@ -6,6 +6,7 @@ import 'package:date_utils/date_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_calendar_carousel/classes/event_list.dart'; import 'package:flutter_calendar_carousel/src/default_styles.dart'; +import 'package:flutter_calendar_carousel/src/calendar_header.dart'; import 'package:intl/date_symbol_data_local.dart'; import 'package:intl/intl.dart' show DateFormat; @@ -188,16 +189,6 @@ class _CalendarState extends State> { @override Widget build(BuildContext context) { - Widget headerText = DefaultTextStyle( - style: TextStyle(fontSize: 16.0, color: Colors.black), - child: widget.headerText != null - ? widget.headerText - : Text( - widget.weekFormat - ? '${_localeDate.format(_weeks[1].first)}' - : '${_localeDate.format(this._dates[1])}', - style: widget.headerTextStyle, - )); if (_isReloadSelectedDate) { if (widget.selectedDateTime != null) _selectedDate = widget.selectedDateTime; @@ -210,42 +201,21 @@ class _CalendarState extends State> { height: widget.height, child: Column( children: [ - widget.showHeader - ? Container( - margin: widget.headerMargin, - child: DefaultTextStyle( - style: widget.headerTextStyle != null - ? widget.headerTextStyle - : defaultHeaderTextStyle, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - widget.showHeaderButton - ? IconButton( - onPressed: () => _setDate(0), - icon: Icon(Icons.chevron_left, - color: widget.iconColor), - ) - : Container(), - widget.headerTitleTouchable - ? FlatButton( - onPressed: - widget.onHeaderTitlePressed != null - ? widget.onHeaderTitlePressed - : () => _selectDateFromPicker(), - child: headerText, - ) - : headerText, - widget.showHeaderButton - ? IconButton( - onPressed: () => _setDate(2), - icon: Icon(Icons.chevron_right, - color: widget.iconColor), - ) - : Container(), - ])), - ) - : Container(), + CalendarHeader( + showHeader: widget.showHeader, + headerMargin: widget.headerMargin, + headerTitle: widget.weekFormat + ? '${_localeDate.format(_weeks[1].first)}' + : '${_localeDate.format(this._dates[1])}', + headerTextStyle: widget.headerTextStyle, + showHeaderButtons: widget.showHeaderButton, + headerIconColor: widget.iconColor, + onLeftButtonPressed: () => _setDate(0), + onRightButtonPressed: () => _setDate(2), + isTitleTouchable: widget.headerTitleTouchable, + onHeaderTitlePressed: widget.onHeaderTitlePressed != null + ? widget.onHeaderTitlePressed : () => _selectDateFromPicker(), + ), Container( child: !widget.showWeekDays ? Container() diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index 6659462..e93b953 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -26,6 +26,8 @@ class CalendarHeader extends StatelessWidget { final bool isTitleTouchable; final VoidCallback onHeaderTitlePressed; + TextStyle get getTextStyle => headerTextStyle != null ? headerTextStyle : defaultHeaderTextStyle; + Widget _leftButton() => IconButton( onPressed: onLeftButtonPressed, icon: Icon(Icons.chevron_left, @@ -42,7 +44,7 @@ class CalendarHeader extends StatelessWidget { Widget _headerTouchable() => FlatButton( onPressed: onHeaderTitlePressed, - child: Text(headerTitle, style: headerTextStyle), + child: Text(headerTitle, style: getTextStyle), ); @override @@ -51,9 +53,7 @@ class CalendarHeader extends StatelessWidget { Container( margin: headerMargin, child: DefaultTextStyle( - style: headerTextStyle != null - ? headerTextStyle - : defaultHeaderTextStyle, + style: getTextStyle, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -62,7 +62,7 @@ class CalendarHeader extends StatelessWidget { : Container(), isTitleTouchable ? _headerTouchable() - : Text(headerTitle, style: headerTextStyle), + : Text(headerTitle, style: getTextStyle), showHeaderButtons ? _rightButton() : Container(), From 05462b76feff34727fd35726c3ab37d0dd45356d Mon Sep 17 00:00:00 2001 From: edgar Date: Tue, 19 Feb 2019 13:12:46 +0700 Subject: [PATCH 05/15] create basic test --- test/src/header_test.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/src/header_test.dart diff --git a/test/src/header_test.dart b/test/src/header_test.dart new file mode 100644 index 0000000..7f6163c --- /dev/null +++ b/test/src/header_test.dart @@ -0,0 +1,12 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_calendar_carousel/src/calendar_header.dart'; + +void main() { + + testWidgets('Test Header', (WidgetTester tester) async { + + await tester.pumpWidget(CalendarHeader( + )); + + }); +} \ No newline at end of file From 80a8156434bb427993935d755ab9f63dcdc2d7cd Mon Sep 17 00:00:00 2001 From: edgar Date: Tue, 19 Feb 2019 13:25:38 +0700 Subject: [PATCH 06/15] move defaults into header file --- lib/flutter_calendar_carousel.dart | 10 +++++----- lib/src/calendar_header.dart | 20 +++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/flutter_calendar_carousel.dart b/lib/flutter_calendar_carousel.dart index 63123a8..40760b5 100644 --- a/lib/flutter_calendar_carousel.dart +++ b/lib/flutter_calendar_carousel.dart @@ -94,7 +94,7 @@ class CalendarCarousel extends StatefulWidget { this.daysHaveCircularBorder, this.onDayPressed, this.weekdayTextStyle, - this.iconColor = Colors.blueAccent, + this.iconColor, this.headerTextStyle, this.headerText, this.weekendTextStyle, @@ -111,13 +111,13 @@ class CalendarCarousel extends StatefulWidget { this.markedDateMoreCustomDecoration, this.markedDateMoreCustomTextStyle, this.markedDateWidget, - this.headerMargin = const EdgeInsets.symmetric(vertical: 16.0), + this.headerMargin, this.childAspectRatio = 1.0, this.weekDayMargin = const EdgeInsets.only(bottom: 4.0), this.showWeekDays = true, this.weekFormat = false, - this.showHeader = true, - this.showHeaderButton = true, + this.showHeader, + this.showHeaderButton, this.customGridViewPhysics, this.onCalendarChanged, this.locale = "en", @@ -125,7 +125,7 @@ class CalendarCarousel extends StatefulWidget { this.maxSelectedDate, this.inactiveDaysTextStyle, this.inactiveWeekendTextStyle, - this.headerTitleTouchable = false, + this.headerTitleTouchable, this.onHeaderTitlePressed, this.weekDayFormat = WeekdayFormat.short, this.staticSixWeekFormat = false, diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index e93b953..1d391e1 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -4,14 +4,14 @@ import 'default_styles.dart'; class CalendarHeader extends StatelessWidget { CalendarHeader({ this.headerTitle, - this.headerMargin, - this.showHeader, - this.headerTextStyle, - this.showHeaderButtons, - this.headerIconColor, + this.headerMargin = const EdgeInsets.symmetric(vertical: 16.0), + this.showHeader = true, + this.headerTextStyle = defaultHeaderTextStyle, + this.showHeaderButtons = true, + this.headerIconColor = Colors.blueAccent, this.onLeftButtonPressed, this.onRightButtonPressed, - this.isTitleTouchable, + this.isTitleTouchable = false, this.onHeaderTitlePressed }) : assert (onHeaderTitlePressed != null, headerTitle != null); @@ -26,8 +26,6 @@ class CalendarHeader extends StatelessWidget { final bool isTitleTouchable; final VoidCallback onHeaderTitlePressed; - TextStyle get getTextStyle => headerTextStyle != null ? headerTextStyle : defaultHeaderTextStyle; - Widget _leftButton() => IconButton( onPressed: onLeftButtonPressed, icon: Icon(Icons.chevron_left, @@ -44,7 +42,7 @@ class CalendarHeader extends StatelessWidget { Widget _headerTouchable() => FlatButton( onPressed: onHeaderTitlePressed, - child: Text(headerTitle, style: getTextStyle), + child: Text(headerTitle, style: headerTextStyle), ); @override @@ -53,7 +51,7 @@ class CalendarHeader extends StatelessWidget { Container( margin: headerMargin, child: DefaultTextStyle( - style: getTextStyle, + style: headerTextStyle, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -62,7 +60,7 @@ class CalendarHeader extends StatelessWidget { : Container(), isTitleTouchable ? _headerTouchable() - : Text(headerTitle, style: getTextStyle), + : Text(headerTitle, style: headerTextStyle), showHeaderButtons ? _rightButton() : Container(), From e70d02920cfe762e5ee229b009bc9adf81dc11de Mon Sep 17 00:00:00 2001 From: edgar Date: Tue, 19 Feb 2019 13:26:51 +0700 Subject: [PATCH 07/15] format code --- lib/src/calendar_header.dart | 114 ++++++++++++++++------------------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index 1d391e1..7917a0a 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -2,70 +2,60 @@ import 'package:flutter/material.dart'; import 'default_styles.dart'; class CalendarHeader extends StatelessWidget { - CalendarHeader({ - this.headerTitle, - this.headerMargin = const EdgeInsets.symmetric(vertical: 16.0), - this.showHeader = true, - this.headerTextStyle = defaultHeaderTextStyle, - this.showHeaderButtons = true, - this.headerIconColor = Colors.blueAccent, - this.onLeftButtonPressed, - this.onRightButtonPressed, - this.isTitleTouchable = false, - this.onHeaderTitlePressed - }) : assert (onHeaderTitlePressed != null, headerTitle != null); + CalendarHeader( + {this.headerTitle, + this.headerMargin = const EdgeInsets.symmetric(vertical: 16.0), + this.showHeader = true, + this.headerTextStyle = defaultHeaderTextStyle, + this.showHeaderButtons = true, + this.headerIconColor = Colors.blueAccent, + this.onLeftButtonPressed, + this.onRightButtonPressed, + this.isTitleTouchable = false, + this.onHeaderTitlePressed}) + : assert(onHeaderTitlePressed != null, headerTitle != null); - final String headerTitle; - final EdgeInsetsGeometry headerMargin; - final bool showHeader; - final TextStyle headerTextStyle; - final bool showHeaderButtons; - final Color headerIconColor; - final VoidCallback onLeftButtonPressed; - final VoidCallback onRightButtonPressed; - final bool isTitleTouchable; - final VoidCallback onHeaderTitlePressed; + final String headerTitle; + final EdgeInsetsGeometry headerMargin; + final bool showHeader; + final TextStyle headerTextStyle; + final bool showHeaderButtons; + final Color headerIconColor; + final VoidCallback onLeftButtonPressed; + final VoidCallback onRightButtonPressed; + final bool isTitleTouchable; + final VoidCallback onHeaderTitlePressed; - Widget _leftButton() => IconButton( - onPressed: onLeftButtonPressed, - icon: Icon(Icons.chevron_left, - color: headerIconColor - ), - ); + Widget _leftButton() => IconButton( + onPressed: onLeftButtonPressed, + icon: Icon(Icons.chevron_left, color: headerIconColor), + ); - Widget _rightButton() => IconButton( - onPressed: onRightButtonPressed, - icon: Icon(Icons.chevron_right, - color: headerIconColor - ), - ); + Widget _rightButton() => IconButton( + onPressed: onRightButtonPressed, + icon: Icon(Icons.chevron_right, color: headerIconColor), + ); - Widget _headerTouchable() => FlatButton( - onPressed: onHeaderTitlePressed, - child: Text(headerTitle, style: headerTextStyle), - ); + Widget _headerTouchable() => FlatButton( + onPressed: onHeaderTitlePressed, + child: Text(headerTitle, style: headerTextStyle), + ); - @override - Widget build(BuildContext context) => - showHeader ? - Container( - margin: headerMargin, - child: DefaultTextStyle( - style: headerTextStyle, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - showHeaderButtons - ? _leftButton() - : Container(), - isTitleTouchable - ? _headerTouchable() - : Text(headerTitle, style: headerTextStyle), - showHeaderButtons - ? _rightButton() - : Container(), - ] - ) - ), - ) : Container(); -} \ No newline at end of file + @override + Widget build(BuildContext context) => showHeader + ? Container( + margin: headerMargin, + child: DefaultTextStyle( + style: headerTextStyle, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + showHeaderButtons ? _leftButton() : Container(), + isTitleTouchable + ? _headerTouchable() + : Text(headerTitle, style: headerTextStyle), + showHeaderButtons ? _rightButton() : Container(), + ])), + ) + : Container(); +} From 1df96b83c10883b77b305b99122dff527c075779 Mon Sep 17 00:00:00 2001 From: edgar Date: Tue, 19 Feb 2019 13:30:07 +0700 Subject: [PATCH 08/15] change assertion to required --- lib/src/calendar_header.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index 7917a0a..7d8437e 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -3,17 +3,16 @@ import 'default_styles.dart'; class CalendarHeader extends StatelessWidget { CalendarHeader( - {this.headerTitle, + {@required this.headerTitle, this.headerMargin = const EdgeInsets.symmetric(vertical: 16.0), this.showHeader = true, this.headerTextStyle = defaultHeaderTextStyle, this.showHeaderButtons = true, this.headerIconColor = Colors.blueAccent, - this.onLeftButtonPressed, - this.onRightButtonPressed, + @required this.onLeftButtonPressed, + @required this.onRightButtonPressed, this.isTitleTouchable = false, - this.onHeaderTitlePressed}) - : assert(onHeaderTitlePressed != null, headerTitle != null); + @required this.onHeaderTitlePressed}); final String headerTitle; final EdgeInsetsGeometry headerMargin; From c1358590d22495b23b5436a864bda5eaebb517ef Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 20 Feb 2019 13:26:50 +0700 Subject: [PATCH 09/15] revert defaults in header --- lib/flutter_calendar_carousel.dart | 10 +++++----- lib/src/calendar_header.dart | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/flutter_calendar_carousel.dart b/lib/flutter_calendar_carousel.dart index 6eea677..a7c619b 100644 --- a/lib/flutter_calendar_carousel.dart +++ b/lib/flutter_calendar_carousel.dart @@ -94,7 +94,7 @@ class CalendarCarousel extends StatefulWidget { this.daysHaveCircularBorder, this.onDayPressed, this.weekdayTextStyle, - this.iconColor, + this.iconColor = Colors.blueAccent, this.headerTextStyle, this.headerText, this.weekendTextStyle, @@ -111,13 +111,13 @@ class CalendarCarousel extends StatefulWidget { this.markedDateMoreCustomDecoration, this.markedDateMoreCustomTextStyle, this.markedDateWidget, - this.headerMargin, + this.headerMargin = const EdgeInsets.symmetric(vertical: 16.0), this.childAspectRatio = 1.0, this.weekDayMargin = const EdgeInsets.only(bottom: 4.0), this.showWeekDays = true, this.weekFormat = false, - this.showHeader, - this.showHeaderButton, + this.showHeader = true, + this.showHeaderButton = true, this.customGridViewPhysics, this.onCalendarChanged, this.locale = "en", @@ -125,7 +125,7 @@ class CalendarCarousel extends StatefulWidget { this.maxSelectedDate, this.inactiveDaysTextStyle, this.inactiveWeekendTextStyle, - this.headerTitleTouchable, + this.headerTitleTouchable = false, this.onHeaderTitlePressed, this.weekDayFormat = WeekdayFormat.short, this.staticSixWeekFormat = false, diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index 7d8437e..be36696 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -4,14 +4,14 @@ import 'default_styles.dart'; class CalendarHeader extends StatelessWidget { CalendarHeader( {@required this.headerTitle, - this.headerMargin = const EdgeInsets.symmetric(vertical: 16.0), - this.showHeader = true, - this.headerTextStyle = defaultHeaderTextStyle, - this.showHeaderButtons = true, - this.headerIconColor = Colors.blueAccent, + this.headerMargin, + this.showHeader, + this.headerTextStyle, + this.showHeaderButtons, + this.headerIconColor, @required this.onLeftButtonPressed, @required this.onRightButtonPressed, - this.isTitleTouchable = false, + this.isTitleTouchable, @required this.onHeaderTitlePressed}); final String headerTitle; @@ -25,6 +25,8 @@ class CalendarHeader extends StatelessWidget { final bool isTitleTouchable; final VoidCallback onHeaderTitlePressed; + TextStyle get getTextStyle => headerTextStyle != null ? headerTextStyle : defaultHeaderTextStyle; + Widget _leftButton() => IconButton( onPressed: onLeftButtonPressed, icon: Icon(Icons.chevron_left, color: headerIconColor), @@ -37,7 +39,7 @@ class CalendarHeader extends StatelessWidget { Widget _headerTouchable() => FlatButton( onPressed: onHeaderTitlePressed, - child: Text(headerTitle, style: headerTextStyle), + child: Text(headerTitle, style: getTextStyle), ); @override @@ -45,14 +47,14 @@ class CalendarHeader extends StatelessWidget { ? Container( margin: headerMargin, child: DefaultTextStyle( - style: headerTextStyle, + style: getTextStyle, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ showHeaderButtons ? _leftButton() : Container(), isTitleTouchable ? _headerTouchable() - : Text(headerTitle, style: headerTextStyle), + : Text(headerTitle, style: getTextStyle), showHeaderButtons ? _rightButton() : Container(), ])), ) From 1f25220f628b20a77dfb2bdab011ad82d7277738 Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 20 Feb 2019 14:26:39 +0700 Subject: [PATCH 10/15] header tests --- test/src/header_test.dart | 112 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 4 deletions(-) diff --git a/test/src/header_test.dart b/test/src/header_test.dart index 7f6163c..b520bce 100644 --- a/test/src/header_test.dart +++ b/test/src/header_test.dart @@ -1,12 +1,116 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_calendar_carousel/src/calendar_header.dart'; +import 'package:flutter/material.dart'; + void main() { - testWidgets('Test Header', (WidgetTester tester) async { + final title = "Test title"; + final margin = const EdgeInsets.symmetric(vertical: 16.0); + final iconColor = Colors.blueAccent; + + testWidgets('Verify Header Defaults', (WidgetTester tester) async { + + var headerTapped = false; + var leftPressed = false; + var rightPressed = false; + + await tester.pumpWidget(wrapped( + CalendarHeader( + headerTitle: title, + headerMargin: margin, + showHeader: true, + showHeaderButtons: true, + headerIconColor: iconColor, + onHeaderTitlePressed: () => headerTapped = true, + onRightButtonPressed: () => rightPressed = true, + onLeftButtonPressed: () => leftPressed = true, + isTitleTouchable: true, + ) + )); + + expect(find.text(title), findsOneWidget); + + await tester.tap(find.byType(FlatButton)); + + await tester.pump(); + + expect(headerTapped, equals(true)); - await tester.pumpWidget(CalendarHeader( - )); + await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_right)); + + await tester.pump(); + + expect(rightPressed, equals(true)); + + await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_left)); + + await tester.pump(); + + expect(leftPressed, equals(true)); }); -} \ No newline at end of file + + testWidgets('Verify No header Renders', (WidgetTester tester) async { + + final noHeaderEmpty = CalendarHeader(showHeader: false); + + await tester.pumpWidget(Container(child: noHeaderEmpty)); + + expect(find.byWidget(noHeaderEmpty), findsOneWidget); + + }); + + testWidgets('Verify Header Is Not Touchable', (WidgetTester tester) async { + + await tester.pumpWidget(wrapped( + CalendarHeader( + headerTitle: title, + headerMargin: margin, + showHeader: true, + showHeaderButtons: true, + headerIconColor: iconColor, + onHeaderTitlePressed: () {}, + onRightButtonPressed: () {}, + onLeftButtonPressed: () {}, + isTitleTouchable: false, + ) + )); + + // the header FlatButton Should not render + final touchableHeader = find.byType(FlatButton); + + expect(touchableHeader, findsNothing); + + }); + + testWidgets('Verify No Header Buttons', (WidgetTester tester) async { + + await tester.pumpWidget(wrapped( + CalendarHeader( + headerTitle: title, + headerMargin: margin, + showHeader: true, + showHeaderButtons: false, + headerIconColor: iconColor, + onHeaderTitlePressed: () {}, + onRightButtonPressed: () {}, + onLeftButtonPressed: () {}, + isTitleTouchable: true, + ) + )); + + // the header IconButtons Should not render + final headerButton = find.byType(IconButton); + + expect(headerButton, findsNothing); + + }); +} + +// header uses Row which requires MaterialApp as an ancestor +Widget wrapped(Widget widget) => MaterialApp( + home: Container( + child: Material(child: widget), + ), +); \ No newline at end of file From 6263cfdfc3e6ae522a5f4a24515ecd5a9801fd0e Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 20 Feb 2019 14:31:53 +0700 Subject: [PATCH 11/15] format code --- lib/src/calendar_header.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index be36696..5c5a9c2 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -25,7 +25,8 @@ class CalendarHeader extends StatelessWidget { final bool isTitleTouchable; final VoidCallback onHeaderTitlePressed; - TextStyle get getTextStyle => headerTextStyle != null ? headerTextStyle : defaultHeaderTextStyle; + TextStyle get getTextStyle => + headerTextStyle != null ? headerTextStyle : defaultHeaderTextStyle; Widget _leftButton() => IconButton( onPressed: onLeftButtonPressed, From ee6020c30c5e4e0cd17e923c858c839b097fcbbb Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 20 Feb 2019 14:34:37 +0700 Subject: [PATCH 12/15] format test code --- test/src/header_test.dart | 153 +++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 84 deletions(-) diff --git a/test/src/header_test.dart b/test/src/header_test.dart index b520bce..03256e1 100644 --- a/test/src/header_test.dart +++ b/test/src/header_test.dart @@ -4,30 +4,26 @@ import 'package:flutter_calendar_carousel/src/calendar_header.dart'; import 'package:flutter/material.dart'; void main() { - - final title = "Test title"; - final margin = const EdgeInsets.symmetric(vertical: 16.0); - final iconColor = Colors.blueAccent; + final title = "Test title"; + final margin = const EdgeInsets.symmetric(vertical: 16.0); + final iconColor = Colors.blueAccent; testWidgets('Verify Header Defaults', (WidgetTester tester) async { - - var headerTapped = false; - var leftPressed = false; - var rightPressed = false; - - await tester.pumpWidget(wrapped( - CalendarHeader( - headerTitle: title, - headerMargin: margin, - showHeader: true, - showHeaderButtons: true, - headerIconColor: iconColor, - onHeaderTitlePressed: () => headerTapped = true, - onRightButtonPressed: () => rightPressed = true, - onLeftButtonPressed: () => leftPressed = true, - isTitleTouchable: true, - ) - )); + var headerTapped = false; + var leftPressed = false; + var rightPressed = false; + + await tester.pumpWidget(wrapped(CalendarHeader( + headerTitle: title, + headerMargin: margin, + showHeader: true, + showHeaderButtons: true, + headerIconColor: iconColor, + onHeaderTitlePressed: () => headerTapped = true, + onRightButtonPressed: () => rightPressed = true, + onLeftButtonPressed: () => leftPressed = true, + isTitleTouchable: true, + ))); expect(find.text(title), findsOneWidget); @@ -37,80 +33,69 @@ void main() { expect(headerTapped, equals(true)); - await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_right)); - - await tester.pump(); + await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_right)); - expect(rightPressed, equals(true)); + await tester.pump(); - await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_left)); + expect(rightPressed, equals(true)); - await tester.pump(); + await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_left)); - expect(leftPressed, equals(true)); + await tester.pump(); + expect(leftPressed, equals(true)); }); - testWidgets('Verify No header Renders', (WidgetTester tester) async { - - final noHeaderEmpty = CalendarHeader(showHeader: false); - - await tester.pumpWidget(Container(child: noHeaderEmpty)); - - expect(find.byWidget(noHeaderEmpty), findsOneWidget); - - }); + testWidgets('Verify No header Renders', (WidgetTester tester) async { + final noHeaderEmpty = CalendarHeader(showHeader: false); - testWidgets('Verify Header Is Not Touchable', (WidgetTester tester) async { + await tester.pumpWidget(Container(child: noHeaderEmpty)); - await tester.pumpWidget(wrapped( - CalendarHeader( - headerTitle: title, - headerMargin: margin, - showHeader: true, - showHeaderButtons: true, - headerIconColor: iconColor, - onHeaderTitlePressed: () {}, - onRightButtonPressed: () {}, - onLeftButtonPressed: () {}, - isTitleTouchable: false, - ) - )); - - // the header FlatButton Should not render - final touchableHeader = find.byType(FlatButton); - - expect(touchableHeader, findsNothing); - - }); - - testWidgets('Verify No Header Buttons', (WidgetTester tester) async { - - await tester.pumpWidget(wrapped( - CalendarHeader( - headerTitle: title, - headerMargin: margin, - showHeader: true, - showHeaderButtons: false, - headerIconColor: iconColor, - onHeaderTitlePressed: () {}, - onRightButtonPressed: () {}, - onLeftButtonPressed: () {}, - isTitleTouchable: true, - ) - )); - - // the header IconButtons Should not render - final headerButton = find.byType(IconButton); + expect(find.byWidget(noHeaderEmpty), findsOneWidget); + }); - expect(headerButton, findsNothing); + testWidgets('Verify Header Is Not Touchable', (WidgetTester tester) async { + await tester.pumpWidget(wrapped(CalendarHeader( + headerTitle: title, + headerMargin: margin, + showHeader: true, + showHeaderButtons: true, + headerIconColor: iconColor, + onHeaderTitlePressed: () {}, + onRightButtonPressed: () {}, + onLeftButtonPressed: () {}, + isTitleTouchable: false, + ))); + + // the header FlatButton Should not render + final touchableHeader = find.byType(FlatButton); + + expect(touchableHeader, findsNothing); + }); - }); + testWidgets('Verify No Header Buttons', (WidgetTester tester) async { + await tester.pumpWidget(wrapped(CalendarHeader( + headerTitle: title, + headerMargin: margin, + showHeader: true, + showHeaderButtons: false, + headerIconColor: iconColor, + onHeaderTitlePressed: () {}, + onRightButtonPressed: () {}, + onLeftButtonPressed: () {}, + isTitleTouchable: true, + ))); + + // the header IconButtons Should not render + final headerButton = find.byType(IconButton); + + expect(headerButton, findsNothing); + }); } // header uses Row which requires MaterialApp as an ancestor Widget wrapped(Widget widget) => MaterialApp( - home: Container( - child: Material(child: widget), - ), -); \ No newline at end of file + home: Container( + child: Material(child: widget), + ), + ); From 7ee2645a3c7a31fbfff81366cfad96977d4c6a6a Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 20 Feb 2019 14:40:39 +0700 Subject: [PATCH 13/15] remove space on main file --- lib/flutter_calendar_carousel.dart | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/flutter_calendar_carousel.dart b/lib/flutter_calendar_carousel.dart index a7c619b..2d54571 100644 --- a/lib/flutter_calendar_carousel.dart +++ b/lib/flutter_calendar_carousel.dart @@ -204,17 +204,14 @@ class _CalendarState extends State> { CalendarHeader( showHeader: widget.showHeader, headerMargin: widget.headerMargin, - headerTitle: widget.weekFormat - ? '${_localeDate.format(_weeks[1].first)}' - : '${_localeDate.format(this._dates[1])}', + headerTitle: widget.weekFormat ? '${_localeDate.format(_weeks[1].first)}' : '${_localeDate.format(this._dates[1])}', headerTextStyle: widget.headerTextStyle, showHeaderButtons: widget.showHeaderButton, headerIconColor: widget.iconColor, onLeftButtonPressed: () => _setDate(0), onRightButtonPressed: () => _setDate(2), isTitleTouchable: widget.headerTitleTouchable, - onHeaderTitlePressed: widget.onHeaderTitlePressed != null - ? widget.onHeaderTitlePressed : () => _selectDateFromPicker(), + onHeaderTitlePressed: widget.onHeaderTitlePressed != null ? widget.onHeaderTitlePressed : () => _selectDateFromPicker(), ), Container( child: !widget.showWeekDays From 6cf74a2d381a9f5cd26341311a324fa0ca2abac8 Mon Sep 17 00:00:00 2001 From: Edgar Date: Wed, 20 Feb 2019 15:02:28 +0700 Subject: [PATCH 14/15] run flutter format --- lib/flutter_calendar_carousel.dart | 40 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/flutter_calendar_carousel.dart b/lib/flutter_calendar_carousel.dart index 2d54571..7b6b396 100644 --- a/lib/flutter_calendar_carousel.dart +++ b/lib/flutter_calendar_carousel.dart @@ -13,7 +13,6 @@ import 'package:intl/intl.dart' show DateFormat; typedef MarkedDateIconBuilder = Widget Function(T event); class CalendarCarousel extends StatefulWidget { - final double viewportFraction; final TextStyle prevDaysTextStyle; final TextStyle daysTextStyle; @@ -201,18 +200,22 @@ class _CalendarState extends State> { height: widget.height, child: Column( children: [ - CalendarHeader( - showHeader: widget.showHeader, - headerMargin: widget.headerMargin, - headerTitle: widget.weekFormat ? '${_localeDate.format(_weeks[1].first)}' : '${_localeDate.format(this._dates[1])}', - headerTextStyle: widget.headerTextStyle, - showHeaderButtons: widget.showHeaderButton, - headerIconColor: widget.iconColor, - onLeftButtonPressed: () => _setDate(0), - onRightButtonPressed: () => _setDate(2), - isTitleTouchable: widget.headerTitleTouchable, - onHeaderTitlePressed: widget.onHeaderTitlePressed != null ? widget.onHeaderTitlePressed : () => _selectDateFromPicker(), - ), + CalendarHeader( + showHeader: widget.showHeader, + headerMargin: widget.headerMargin, + headerTitle: widget.weekFormat + ? '${_localeDate.format(_weeks[1].first)}' + : '${_localeDate.format(this._dates[1])}', + headerTextStyle: widget.headerTextStyle, + showHeaderButtons: widget.showHeaderButton, + headerIconColor: widget.iconColor, + onLeftButtonPressed: () => _setDate(0), + onRightButtonPressed: () => _setDate(2), + isTitleTouchable: widget.headerTitleTouchable, + onHeaderTitlePressed: widget.onHeaderTitlePressed != null + ? widget.onHeaderTitlePressed + : () => _selectDateFromPicker(), + ), Container( child: !widget.showWeekDays ? Container() @@ -932,14 +935,11 @@ class _CalendarState extends State> { ); } } else { - - //max 5 dots - if(event_index < 5) { + if (event_index < 5) { if (widget.markedDateIconBuilder != null) { tmp.add(widget.markedDateIconBuilder(event)); - } - else { + } else { if (widget.markedDateWidget != null) { tmp.add(widget.markedDateWidget); } else { @@ -947,13 +947,9 @@ class _CalendarState extends State> { } } } - - - } event_index++; - }); return tmp; } From 4bb6c4d5ee292041b4d38e7a219865dc6f7549af Mon Sep 17 00:00:00 2001 From: edgar Date: Fri, 22 Feb 2019 16:29:22 +0700 Subject: [PATCH 15/15] import only defaultHeaderTextStyle in header --- lib/src/calendar_header.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/calendar_header.dart b/lib/src/calendar_header.dart index 5c5a9c2..6587e93 100644 --- a/lib/src/calendar_header.dart +++ b/lib/src/calendar_header.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'default_styles.dart'; +import 'default_styles.dart' show defaultHeaderTextStyle; class CalendarHeader extends StatelessWidget { CalendarHeader(