diff --git a/README.md b/README.md index 157c9c0..2d430a8 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,10 @@ In the flutter date range picker, you can select the entire week when selecting a single day using the `onSelectionChanged` callback and `enableSwipeSelection` property. ## Step 1: -In initState(), initialize the controller for date range picker. +Inside the state, initialize the controller for date range picker. ```xml -DateRangePickerController _controller; -@override -void initState() { - // TODO: implement initState - _controller = DateRangePickerController(); - super.initState(); -} +final DateRangePickerController _controller = DateRangePickerController(); ``` ## Step 2: Place the date range picker inside the body of the Scaffold widget, set the `selectionMode` as range selection and trigger the `onSelectionChanged` callback of the flutter date picker. @@ -45,8 +39,8 @@ void selectionChanged(DateRangePickerSelectionChangedArgs args) { int endDayOfWeek = (firstDayOfWeek - 1) % 7; endDayOfWeek = endDayOfWeek < 0? 7 + endDayOfWeek : endDayOfWeek; PickerDateRange ranges = args.value; - DateTime date1 = ranges.startDate; - DateTime date2 = ranges.endDate?? ranges.startDate; + DateTime date1 = ranges.startDate!; + DateTime date2 = (ranges.endDate?? ranges.startDate)!; if(date1.isAfter(date2)) { var date=date1; diff --git a/lib/main.dart b/lib/main.dart index cf580bf..533b279 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,7 +8,7 @@ class WeekSelection extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - debugShowCheckedModeBanner: false , + debugShowCheckedModeBanner: false, home: WeekSelectionInPicker(), ); } @@ -20,14 +20,7 @@ class WeekSelectionInPicker extends StatefulWidget { } class _WeekSelectionInPickerState extends State { - DateRangePickerController _controller; - - @override - void initState() { - // TODO: implement initState - _controller = DateRangePickerController(); - super.initState(); - } + final DateRangePickerController _controller = DateRangePickerController(); @override Widget build(BuildContext context) { @@ -41,7 +34,8 @@ class _WeekSelectionInPickerState extends State { view: DateRangePickerView.month, selectionMode: DateRangePickerSelectionMode.range, onSelectionChanged: selectionChanged, - monthViewSettings: DateRangePickerMonthViewSettings(enableSwipeSelection: false), + monthViewSettings: + DateRangePickerMonthViewSettings(enableSwipeSelection: false), ), ) ], @@ -51,33 +45,31 @@ class _WeekSelectionInPickerState extends State { ); } - void selectionChanged(DateRangePickerSelectionChangedArgs args) { int firstDayOfWeek = DateTime.sunday % 7; int endDayOfWeek = (firstDayOfWeek - 1) % 7; - endDayOfWeek = endDayOfWeek < 0? 7 + endDayOfWeek : endDayOfWeek; + endDayOfWeek = endDayOfWeek < 0 ? 7 + endDayOfWeek : endDayOfWeek; PickerDateRange ranges = args.value; - DateTime date1 = ranges.startDate; - DateTime date2 = ranges.endDate?? ranges.startDate; - if(date1.isAfter(date2)) - { - var date=date1; - date1=date2; - date2=date; - } + DateTime date1 = ranges.startDate!; + DateTime date2 = (ranges.endDate ?? ranges.startDate)!; + if (date1.isAfter(date2)) { + var date = date1; + date1 = date2; + date2 = date; + } int day1 = date1.weekday % 7; int day2 = date2.weekday % 7; DateTime dat1 = date1.add(Duration(days: (firstDayOfWeek - day1))); DateTime dat2 = date2.add(Duration(days: (endDayOfWeek - day2))); - if( !isSameDate(dat1, ranges.startDate)|| !isSameDate(dat2,ranges.endDate)) - { + if (!isSameDate(dat1, ranges.startDate) || + !isSameDate(dat2, ranges.endDate)) { _controller.selectedRange = PickerDateRange(dat1, dat2); } } - bool isSameDate(DateTime date1, DateTime date2) { + bool isSameDate(DateTime? date1, DateTime? date2) { if (date2 == date1) { return true; } @@ -88,4 +80,4 @@ class _WeekSelectionInPickerState extends State { date1.year == date2.year && date1.day == date2.day; } -} \ No newline at end of file +} diff --git a/pubspec.lock b/pubspec.lock index a0f585f..275280b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,69 +1,62 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: + version: "2.1.0" + characters: dependency: transitive description: - name: charcode + name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.1.0" + charcode: dependency: transitive description: - name: collection + name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.2.0" + clock: dependency: transitive description: - name: convert + name: clock url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.1.0" + collection: dependency: transitive description: - name: crypto + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.2" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -74,74 +67,34 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_web_plugins: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" intl: dependency: transitive description: name: intl url: "https://pub.dartlang.org" source: hosted - version: "0.16.1" + version: "0.17.0" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -153,112 +106,69 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" syncfusion_flutter_core: dependency: transitive description: name: syncfusion_flutter_core url: "https://pub.dartlang.org" source: hosted - version: "18.1.36" + version: "19.1.54+1" syncfusion_flutter_datepicker: dependency: "direct dev" description: name: syncfusion_flutter_datepicker url: "https://pub.dartlang.org" source: hosted - version: "18.1.36-beta" + version: "19.1.54-beta.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" - url_launcher: - dependency: transitive - description: - name: url_launcher - url: "https://pub.dartlang.org" - source: hosted - version: "5.4.2" - url_launcher_macos: - dependency: transitive - description: - name: url_launcher_macos - url: "https://pub.dartlang.org" - source: hosted - version: "0.0.1+4" - url_launcher_platform_interface: - dependency: transitive - description: - name: url_launcher_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.6" - url_launcher_web: - dependency: transitive - description: - name: url_launcher_web - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.1+1" - utf: - dependency: transitive - description: - name: utf - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.0+5" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.5.0 <3.0.0" - flutter: ">=1.12.8 <2.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index f4f8d7c..d0d094f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ description: A new Flutter application. version: 1.0.0+1 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: @@ -22,12 +22,12 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: sdk: flutter - syncfusion_flutter_datepicker: ^18.1.36-beta + syncfusion_flutter_datepicker: ^19.1.54-beta.1 # For information on the generic Dart part of this file, see the