From b31f293a520da3cfadf09d878a15ce543a0aa6a2 Mon Sep 17 00:00:00 2001 From: Javier Claros Date: Tue, 24 Nov 2020 13:11:11 -0400 Subject: [PATCH 1/5] solve naming conflict or ambiguous import --- lib/calendarro.dart | 97 +++++++++++++++++---------------------- lib/calendarro_page.dart | 39 +++++++--------- lib/default_day_tile.dart | 32 ++++++------- pubspec.lock | 67 +++++++++++++++------------ 4 files changed, 112 insertions(+), 123 deletions(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 07eff6d..5d66eb4 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -3,7 +3,7 @@ library calendarro; import 'package:calendarro/calendarro_page.dart'; import 'package:calendarro/date_range.dart'; import 'package:calendarro/default_weekday_labels_row.dart'; -import 'package:calendarro/date_utils.dart'; +import 'package:calendarro/date_utils.dart' as dateUtil; import 'package:calendarro/default_day_tile_builder.dart'; import 'package:flutter/material.dart'; @@ -50,14 +50,14 @@ class Calendarro extends StatefulWidget { this.weekdayLabelsRow, }) : super(key: key) { if (startDate == null) { - startDate = DateUtils.getFirstDayOfCurrentMonth(); + startDate = dateUtil.DateUtils.getFirstDayOfCurrentMonth(); } - startDate = DateUtils.toMidnight(startDate); + startDate = dateUtil.DateUtils.toMidnight(startDate); if (endDate == null) { - endDate = DateUtils.getLastDayOfCurrentMonth(); + endDate = dateUtil.DateUtils.getLastDayOfCurrentMonth(); } - endDate = DateUtils.toMidnight(endDate); + endDate = dateUtil.DateUtils.toMidnight(endDate); if (startDate.isAfter(endDate)) { throw new ArgumentError("Calendarro: startDate is after the endDate"); @@ -83,8 +83,7 @@ class Calendarro extends StatefulWidget { @override CalendarroState createState() { state = CalendarroState( - selectedSingleDate: selectedSingleDate, - selectedDates: selectedDates); + selectedSingleDate: selectedSingleDate, selectedDates: selectedDates); return state; } @@ -102,9 +101,7 @@ class Calendarro extends StatefulWidget { int getPositionOfDate(DateTime date) { int daysDifference = - date - .difference(DateUtils.toMidnight(startDate)) - .inDays; + date.difference(dateUtil.DateUtils.toMidnight(startDate)).inDays; int weekendsDifference = ((daysDifference + startDate.weekday) / 7).toInt(); var position = daysDifference - weekendsDifference * 2; return position; @@ -112,9 +109,7 @@ class Calendarro extends StatefulWidget { int getPageForDate(DateTime date) { if (displayMode == DisplayMode.WEEKS) { - int daysDifferenceFromStartDate = date - .difference(startDate) - .inDays; + int daysDifferenceFromStartDate = date.difference(startDate).inDays; int page = (daysDifferenceFromStartDate + startDayOffset) ~/ 7; return page; } else { @@ -132,10 +127,7 @@ class CalendarroState extends State { int pagesCount; PageView pageView; - CalendarroState({ - this.selectedSingleDate, - this.selectedDates - }); + CalendarroState({this.selectedSingleDate, this.selectedDates}); @override void initState() { @@ -175,17 +167,18 @@ class CalendarroState extends State { int lastPage = widget.getPageForDate(widget.endDate); pagesCount = lastPage + 1; } else { - pagesCount = DateUtils.calculateMonthsDifference( - widget.startDate, - widget.endDate) + 1; + pagesCount = dateUtil.DateUtils.calculateMonthsDifference( + widget.startDate, widget.endDate) + + 1; } pageView = PageView.builder( itemBuilder: (context, position) => _buildCalendarPage(position), itemCount: pagesCount, controller: PageController( - initialPage: - selectedSingleDate != null ? widget.getPageForDate(selectedSingleDate) : 0), + initialPage: selectedSingleDate != null + ? widget.getPageForDate(selectedSingleDate) + : 0), onPageChanged: (page) { if (widget.onPageSelected != null) { DateRange pageDateRange = _calculatePageDateRange(page); @@ -198,16 +191,13 @@ class CalendarroState extends State { if (widget.displayMode == DisplayMode.WEEKS) { widgetHeight = widget.dayLabelHeight + widget.dayTileHeight; } else { - var maxWeeksNumber = DateUtils.calculateMaxWeeksNumberMonthly( - widget.startDate, - widget.endDate); - widgetHeight = widget.dayLabelHeight - + maxWeeksNumber * widget.dayTileHeight; + var maxWeeksNumber = dateUtil.DateUtils.calculateMaxWeeksNumberMonthly( + widget.startDate, widget.endDate); + widgetHeight = + widget.dayLabelHeight + maxWeeksNumber * widget.dayTileHeight; } - return Container( - height: widgetHeight, - child: pageView); + return Container(height: widgetHeight, child: pageView); } bool isDateSelected(DateTime date) { @@ -216,10 +206,9 @@ class CalendarroState extends State { return DateUtils.isSameDay(selectedSingleDate, date); break; case SelectionMode.MULTI: - final matchedSelectedDate = selectedDates.firstWhere((currentDate) => - DateUtils.isSameDay(currentDate, date), - orElse: () => null - ); + final matchedSelectedDate = selectedDates.firstWhere( + (currentDate) => DateUtils.isSameDay(currentDate, date), + orElse: () => null); return matchedSelectedDate != null; break; @@ -230,11 +219,11 @@ class CalendarroState extends State { case 1: return DateUtils.isSameDay(selectedDates[0], date); default: - var dateBetweenDatesRange = (date.isAfter(selectedDates[0]) - && date.isBefore(selectedDates[1])); - return DateUtils.isSameDay(date, selectedDates[0]) - || DateUtils.isSameDay(date, selectedDates[1]) - || dateBetweenDatesRange; + var dateBetweenDatesRange = (date.isAfter(selectedDates[0]) && + date.isBefore(selectedDates[1])); + return DateUtils.isSameDay(date, selectedDates[0]) || + DateUtils.isSameDay(date, selectedDates[1]) || + dateBetweenDatesRange; } break; } @@ -301,18 +290,19 @@ class CalendarroState extends State { if (pagesCount <= 1) { pageEndDate = widget.endDate; } else { - var lastDayOfMonth = DateUtils.getLastDayOfMonth(widget.startDate); + var lastDayOfMonth = + dateUtil.DateUtils.getLastDayOfMonth(widget.startDate); pageEndDate = lastDayOfMonth; } } else if (pagePosition == pagesCount - 1) { - pageStartDate = DateUtils.getFirstDayOfMonth(widget.endDate); + pageStartDate = dateUtil.DateUtils.getFirstDayOfMonth(widget.endDate); pageEndDate = widget.endDate; } else { - DateTime firstDateOfCurrentMonth = DateUtils.addMonths( - widget.startDate, - pagePosition); + DateTime firstDateOfCurrentMonth = + dateUtil.DateUtils.addMonths(widget.startDate, pagePosition); pageStartDate = firstDateOfCurrentMonth; - pageEndDate = DateUtils.getLastDayOfMonth(firstDateOfCurrentMonth); + pageEndDate = + dateUtil.DateUtils.getLastDayOfMonth(firstDateOfCurrentMonth); } return DateRange(pageStartDate, pageEndDate); @@ -324,16 +314,16 @@ class CalendarroState extends State { if (pagePosition == 0) { pageStartDate = widget.startDate; - pageEndDate = - DateUtils.addDaysToDate(widget.startDate, 6 - widget.startDayOffset); + pageEndDate = dateUtil.DateUtils.addDaysToDate( + widget.startDate, 6 - widget.startDayOffset); } else if (pagePosition == pagesCount - 1) { - pageStartDate = DateUtils.addDaysToDate( + pageStartDate = dateUtil.DateUtils.addDaysToDate( widget.startDate, 7 * pagePosition - widget.startDayOffset); pageEndDate = widget.endDate; } else { - pageStartDate = DateUtils.addDaysToDate( + pageStartDate = dateUtil.DateUtils.addDaysToDate( widget.startDate, 7 * pagePosition - widget.startDayOffset); - pageEndDate = DateUtils.addDaysToDate( + pageEndDate = dateUtil.DateUtils.addDaysToDate( widget.startDate, 7 * pagePosition + 6 - widget.startDayOffset); } @@ -363,10 +353,9 @@ class CalendarroState extends State { } void _setMultiSelectedDate(DateTime date) { - final alreadyExistingDate = selectedDates.firstWhere((currentDate) => - DateUtils.isSameDay(currentDate, date), - orElse: () => null - ); + final alreadyExistingDate = selectedDates.firstWhere( + (currentDate) => dateUtil.DateUtils.isSameDay(currentDate, date), + orElse: () => null); if (alreadyExistingDate != null) { selectedDates.remove(alreadyExistingDate); diff --git a/lib/calendarro_page.dart b/lib/calendarro_page.dart index 9dce19e..bcddb5b 100644 --- a/lib/calendarro_page.dart +++ b/lib/calendarro_page.dart @@ -1,10 +1,9 @@ import 'package:calendarro/calendarro.dart'; -import 'package:calendarro/date_utils.dart'; +import 'package:calendarro/date_utils.dart' as dateUtil; import 'package:calendarro/default_weekday_labels_row.dart'; import 'package:flutter/material.dart'; class CalendarroPage extends StatelessWidget { - static final MAX_ROWS_COUNT = 6; DateTime pageStartDate; @@ -13,11 +12,8 @@ class CalendarroPage extends StatelessWidget { int startDayOffset; - CalendarroPage({ - this.pageStartDate, - this.pageEndDate, - this.weekdayLabelsRow - }) { + CalendarroPage( + {this.pageStartDate, this.pageEndDate, this.weekdayLabelsRow}) { startDayOffset = pageStartDate.weekday - DateTime.monday; } @@ -25,32 +21,30 @@ class CalendarroPage extends StatelessWidget { Widget build(BuildContext context) { return Container( child: Column( - children: buildRows(context), - mainAxisSize: MainAxisSize.min - ) - ); + children: buildRows(context), mainAxisSize: MainAxisSize.min)); } List buildRows(BuildContext context) { List rows = []; rows.add(weekdayLabelsRow); - DateTime rowLastDayDate = DateUtils.addDaysToDate(pageStartDate, 6 - startDayOffset); + DateTime rowLastDayDate = + dateUtil.DateUtils.addDaysToDate(pageStartDate, 6 - startDayOffset); if (pageEndDate.isAfter(rowLastDayDate)) { rows.add(Row( - children: buildCalendarRow(context, pageStartDate, rowLastDayDate)) - ); + children: buildCalendarRow(context, pageStartDate, rowLastDayDate))); for (var i = 1; i < MAX_ROWS_COUNT; i++) { - DateTime nextRowFirstDayDate = DateUtils.addDaysToDate(pageStartDate, 7 * i - startDayOffset); + DateTime nextRowFirstDayDate = dateUtil.DateUtils.addDaysToDate( + pageStartDate, 7 * i - startDayOffset); if (nextRowFirstDayDate.isAfter(pageEndDate)) { break; } - DateTime nextRowLastDayDate = DateUtils.addDaysToDate(pageStartDate, 7 * i - startDayOffset + 6); - + DateTime nextRowLastDayDate = dateUtil.DateUtils.addDaysToDate( + pageStartDate, 7 * i - startDayOffset + 6); if (nextRowLastDayDate.isAfter(pageEndDate)) { nextRowLastDayDate = pageEndDate; @@ -61,9 +55,8 @@ class CalendarroPage extends StatelessWidget { context, nextRowFirstDayDate, nextRowLastDayDate))); } } else { - rows.add(Row( - children: buildCalendarRow(context, pageStartDate, pageEndDate)) - ); + rows.add( + Row(children: buildCalendarRow(context, pageStartDate, pageEndDate))); } return rows; @@ -77,9 +70,9 @@ class CalendarroPage extends StatelessWidget { for (int i = 0; i < 7; i++) { if (i + 1 >= rowStartDate.weekday && i + 1 <= rowEndDate.weekday) { CalendarroState calendarroState = Calendarro.of(context); - Widget dayTile = calendarroState.widget.dayTileBuilder - .build(context, currentDate, calendarroState.widget.onTap); - items.add(dayTile); + Widget dayTile = calendarroState.widget.dayTileBuilder + .build(context, currentDate, calendarroState.widget.onTap); + items.add(dayTile); currentDate = currentDate.add(Duration(days: 1)); } else { items.add(Expanded( diff --git a/lib/default_day_tile.dart b/lib/default_day_tile.dart index 4f303cc..7b6a1c2 100644 --- a/lib/default_day_tile.dart +++ b/lib/default_day_tile.dart @@ -1,5 +1,5 @@ import 'package:calendarro/calendarro.dart'; -import 'package:calendarro/date_utils.dart'; +import 'package:calendarro/date_utils.dart' as dateUtil; import 'package:flutter/material.dart'; class CalendarroDayItem extends StatelessWidget { @@ -11,9 +11,9 @@ class CalendarroDayItem extends StatelessWidget { @override Widget build(BuildContext context) { - bool isWeekend = DateUtils.isWeekend(date); + bool isWeekend = dateUtil.DateUtils.isWeekend(date); var textColor = isWeekend ? Colors.grey : Colors.black; - bool isToday = DateUtils.isToday(date); + bool isToday = dateUtil.DateUtils.isToday(date); calendarroState = Calendarro.of(context); bool daySelected = calendarroState.isDateSelected(date); @@ -32,18 +32,18 @@ class CalendarroDayItem extends StatelessWidget { return Expanded( child: GestureDetector( - child: Container( - height: 40.0, - decoration: boxDecoration, - child: Center( - child: Text( - "${date.day}", - textAlign: TextAlign.center, - style: TextStyle(color: textColor), - ))), - onTap: handleTap, - behavior: HitTestBehavior.translucent, - )); + child: Container( + height: 40.0, + decoration: boxDecoration, + child: Center( + child: Text( + "${date.day}", + textAlign: TextAlign.center, + style: TextStyle(color: textColor), + ))), + onTap: handleTap, + behavior: HitTestBehavior.translucent, + )); } void handleTap() { @@ -54,4 +54,4 @@ class CalendarroDayItem extends StatelessWidget { calendarroState.setSelectedDate(date); calendarroState.setCurrentDate(date); } -} \ No newline at end of file +} diff --git a/pubspec.lock b/pubspec.lock index 7642229..8426fcf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,28 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.5.0-nullsafety.3" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.1.0-nullsafety.3" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0-nullsafety.5" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0-nullsafety.3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0-nullsafety.3" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0-nullsafety.5" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0-nullsafety.3" flutter: dependency: "direct main" description: flutter @@ -45,35 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.10-nullsafety.3" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.6" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.7.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" + version: "1.8.0-nullsafety.3" sky_engine: dependency: transitive description: flutter @@ -85,55 +92,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.0-nullsafety.4" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety.6" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.3" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0-nullsafety.3" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.3" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.19-nullsafety.6" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.5" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.5" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.12.0-0.0 <3.0.0" From 5b3b78f4305e30a525ebb73adf5c2a2276bee81f Mon Sep 17 00:00:00 2001 From: Zachary Claret-Scott Date: Thu, 11 Mar 2021 11:40:48 +0000 Subject: [PATCH 2/5] Removed ancestorStateOfType Error: The method 'ancestorStateOfType' isn't defined for the class 'BuildContext'. --- lib/calendarro.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 5d66eb4..0ab4ed8 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -77,8 +77,8 @@ class Calendarro extends StatefulWidget { } } - static CalendarroState of(BuildContext context) => - context.ancestorStateOfType(const TypeMatcher()); +// static CalendarroState of(BuildContext context) => +// context.ancestorStateOfType(const TypeMatcher()); @override CalendarroState createState() { From e818fe424c1af6336a85f5693cdb5a3548bbecd9 Mon Sep 17 00:00:00 2001 From: Zachary Claret-Scott Date: Thu, 11 Mar 2021 11:45:56 +0000 Subject: [PATCH 3/5] Migrated to findAncestorStateOfType --- lib/calendarro.dart | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 0ab4ed8..eaec5d5 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -77,15 +77,10 @@ class Calendarro extends StatefulWidget { } } -// static CalendarroState of(BuildContext context) => -// context.ancestorStateOfType(const TypeMatcher()); + static CalendarroState of(BuildContext context) => context.findAncestorStateOfType(); @override - CalendarroState createState() { - state = CalendarroState( - selectedSingleDate: selectedSingleDate, selectedDates: selectedDates); - return state; - } + CalendarroState createState() => new CalendarroState(selectedSingleDate: selectedSingleDate, selectedDates: selectedDates); void setSelectedDate(DateTime date) { state.setSelectedDate(date); From 1c2848f85113a4c6c0d1c47f20fcbc2d27aa9a6c Mon Sep 17 00:00:00 2001 From: Zachary Claret-Scott Date: Thu, 11 Mar 2021 11:48:28 +0000 Subject: [PATCH 4/5] Added CalendarroState --- lib/calendarro.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index eaec5d5..d9c9252 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -77,7 +77,7 @@ class Calendarro extends StatefulWidget { } } - static CalendarroState of(BuildContext context) => context.findAncestorStateOfType(); + static CalendarroState of(BuildContext context) => context.findAncestorStateOfType(); @override CalendarroState createState() => new CalendarroState(selectedSingleDate: selectedSingleDate, selectedDates: selectedDates); From 9f1172c6cb3bbaf87837791b5730d6b5f72aca45 Mon Sep 17 00:00:00 2001 From: Zachary Claret-Scott Date: Thu, 11 Mar 2021 11:59:34 +0000 Subject: [PATCH 5/5] Fixed local state --- lib/calendarro.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index d9c9252..4c1e77d 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -78,9 +78,12 @@ class Calendarro extends StatefulWidget { } static CalendarroState of(BuildContext context) => context.findAncestorStateOfType(); - + @override - CalendarroState createState() => new CalendarroState(selectedSingleDate: selectedSingleDate, selectedDates: selectedDates); + CalendarroState createState() { + state = CalendarroState(selectedSingleDate: selectedSingleDate, selectedDates: selectedDates); + return state; + } void setSelectedDate(DateTime date) { state.setSelectedDate(date);