From c1b8f96c06294e9ca5aeec691a4c3a6dc82eaa96 Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Mon, 21 Sep 2020 23:46:48 +0530 Subject: [PATCH 1/8] changes to ui --- .idea/.gitignore | 2 + .idea/calendarro.iml | 19 ++ .idea/codeStyles/Project.xml | 116 +++++++++++ .idea/libraries/Dart_Packages.xml | 188 ++++++++++++++++++ .idea/libraries/Dart_SDK.xml | 29 +++ .idea/libraries/Flutter_Plugins.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + example/ios/Flutter/.last_build_id | 1 + example/ios/Flutter/Flutter.podspec | 18 ++ .../ios/Flutter/flutter_export_environment.sh | 15 ++ example/ios/Runner.xcodeproj/project.pbxproj | 16 +- example/lib/main.dart | 157 ++++++++++++--- example/pubspec.lock | 57 +++--- example/pubspec.yaml | 1 + lib/calendarro.dart | 2 + lib/date_utils.dart | 7 +- lib/default_day_tile.dart | 26 ++- pubspec.lock | 48 ++--- 19 files changed, 616 insertions(+), 107 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/calendarro.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/libraries/Dart_Packages.xml create mode 100644 .idea/libraries/Dart_SDK.xml create mode 100644 .idea/libraries/Flutter_Plugins.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 example/ios/Flutter/.last_build_id create mode 100644 example/ios/Flutter/Flutter.podspec create mode 100755 example/ios/Flutter/flutter_export_environment.sh diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/calendarro.iml b/.idea/calendarro.iml new file mode 100644 index 0000000..ef03246 --- /dev/null +++ b/.idea/calendarro.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml new file mode 100644 index 0000000..965d931 --- /dev/null +++ b/.idea/libraries/Dart_Packages.xml @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml new file mode 100644 index 0000000..e852ff3 --- /dev/null +++ b/.idea/libraries/Dart_SDK.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml new file mode 100644 index 0000000..b0f6971 --- /dev/null +++ b/.idea/libraries/Flutter_Plugins.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..aa84e03 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id new file mode 100644 index 0000000..64c5c41 --- /dev/null +++ b/example/ios/Flutter/.last_build_id @@ -0,0 +1 @@ +00ef326ece8f422830c8ec2e0c41fd4c \ No newline at end of file diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec new file mode 100644 index 0000000..5ca3041 --- /dev/null +++ b/example/ios/Flutter/Flutter.podspec @@ -0,0 +1,18 @@ +# +# NOTE: This podspec is NOT to be published. It is only used as a local source! +# + +Pod::Spec.new do |s| + s.name = 'Flutter' + s.version = '1.0.0' + s.summary = 'High-performance, high-fidelity mobile apps.' + s.description = <<-DESC +Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS. + DESC + s.homepage = 'https://flutter.io' + s.license = { :type => 'MIT' } + s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } + s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } + s.ios.deployment_target = '8.0' + s.vendored_frameworks = 'Flutter.framework' +end diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..87dd5e1 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/ebey/Desktop/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/ebey/Desktop/Github/calendarro/example" +export "FLUTTER_TARGET=/Users/ebey/Desktop/Github/calendarro/example/lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" +export "OTHER_LDFLAGS=$(inherited) -framework Flutter" +export "FLUTTER_FRAMEWORK_DIR=/Users/ebey/Desktop/flutter/bin/cache/artifacts/engine/ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_DEFINES=flutter.inspector.structuredErrors%3Dtrue" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=true" +export "TREE_SHAKE_ICONS=false" diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 896e575..4170033 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,10 +9,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; }; 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; @@ -29,8 +25,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -41,13 +35,11 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -61,8 +53,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -72,9 +62,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -208,7 +196,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -261,7 +249,6 @@ /* Begin XCBuildConfiguration section */ 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -315,7 +302,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; diff --git a/example/lib/main.dart b/example/lib/main.dart index 96ad596..c3f59dd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,59 +1,150 @@ import 'package:calendarro/date_utils.dart'; import 'package:flutter/material.dart'; import 'package:calendarro/calendarro.dart'; +import 'package:intl/intl.dart'; + +List months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; + +var now = new DateTime.now(); void main() => runApp(new MyApp()); -class MyApp extends StatelessWidget { + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { @override Widget build(BuildContext context) { - return new MaterialApp( - title: 'Calendarro Demo', - theme: new ThemeData( - primarySwatch: Colors.orange, + return MaterialApp( + title: "Demo", + home: Scaffold( + appBar: AppBar( + title: Text("Demo"), + ), + body: Container( + height: 3000, + child: Calender(), + ), ), - home: new MyHomePage(title: 'Calendarro Demo'), ); } } -class MyHomePage extends StatelessWidget { - final String title; - Calendarro monthCalendarro; - - MyHomePage({Key key, this.title}) : super(key: key); +class Calender extends StatefulWidget { + @override + _CalenderState createState() => _CalenderState(); +} +class _CalenderState extends State { + var currentMonth = now.month; + var startDate = DateUtils.getFirstDayOfCurrentMonth(); + var endDate = DateTime(2021); + Calendarro monthCalendarro; @override Widget build(BuildContext context) { - var startDate = DateUtils.getFirstDayOfCurrentMonth(); - var endDate = DateUtils.getLastDayOfNextMonth(); + + print("Current month: $currentMonth"); monthCalendarro = Calendarro( - startDate: startDate, - endDate: endDate, - displayMode: DisplayMode.MONTHS, - selectionMode: SelectionMode.MULTI, - weekdayLabelsRow: CustomWeekdayLabelsRow(), - onTap: (date) { - print("onTap: $date"); + startDate: startDate, + endDate: endDate, + displayMode: DisplayMode.MONTHS, + selectionMode: SelectionMode.MULTI, + weekdayLabelsRow: CustomWeekdayLabelsRow(), + onPageSelected: (nextStartDate, nextEndDate){ + print("Selected $nextStartDate - $nextEndDate"); + setState(() { + currentMonth = nextStartDate.month; + //startDate = nextStartDate; + //endDate = nextEndDate; }); - return new Scaffold( - appBar: new AppBar( - title: new Text(title), - ), - body: Column( - children: [ - Container( - color: Colors.orange, - child: Calendarro(), + print(currentMonth); + }, + onTap: (date){ + print("Tapped $date"); + }, + ); + return Column( + children: [ + Container( + color: Colors.red, + child: Text( + months[currentMonth-1], + textAlign: TextAlign.center, ), - Container(height: 32.0), - monthCalendarro - ], - ), + ), + monthCalendarro + ], ); } } + + + +//class MyApp extends StatelessWidget { +// @override +// Widget build(BuildContext context) { +// return new MaterialApp( +// title: 'Calendarro Demo', +// theme: new ThemeData( +// primarySwatch: Colors.orange, +// ), +// home: new MyHomePage(title: 'Calender Demo'), +// ); +// } +//} +// +//class MyHomePage extends StatelessWidget { +// final String title; +// var currentMonth = 0; +// Calendarro monthCalendarro; +// +// MyHomePage({Key key, this.title}) : super(key: key); +// +// @override +// Widget build(BuildContext context) { +// var startDate = DateUtils.getFirstDayOfCurrentMonth(); +// var endDate = DateUtils.getLastDayOfNextMonth(); +// var now = new DateTime.now(); +// currentMonth = now.month; +// monthCalendarro = Calendarro( +// startDate: startDate, +// endDate: endDate, +// displayMode: DisplayMode.MONTHS, +// selectionMode: SelectionMode.MULTI, +// weekdayLabelsRow: CustomWeekdayLabelsRow(), +// onPageSelected: (startDate,endDate){ +// print("Selected $startDate : $endDate"); +// currentMonth =startDate.month; +// print(currentMonth); +// }, +// onTap: (date) { +// print("onTap: $date"); +// }); +// +// return new Scaffold( +// appBar: new AppBar( +// title: new Text(title), +// ), +// body: Column( +// children: [ +// Container( +// color: Colors.red, +// child: Text( +// months[currentMonth+1], +// textAlign: TextAlign.center, +// ), +// height: 32.0), +// monthCalendarro +// ], +// ), +// ); +// } +//} + class CustomWeekdayLabelsRow extends StatelessWidget { @override Widget build(BuildContext context) { diff --git a/example/pubspec.lock b/example/pubspec.lock index e92c641..d9ca0e9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,35 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.4.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.0" calendarro: dependency: "direct dev" description: path: ".." relative: true source: path - version: "1.0.1" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.12" cupertino_icons: dependency: "direct main" description: @@ -43,6 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.2" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -53,41 +67,34 @@ packages: description: flutter source: sdk version: "0.0.0" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" 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" sky_engine: dependency: transitive description: flutter @@ -99,7 +106,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" stack_trace: dependency: transitive description: @@ -120,7 +127,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -134,7 +141,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.16" typed_data: dependency: transitive description: @@ -150,4 +157,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.7.0 <3.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b7de302..2e783ef 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,6 +8,7 @@ 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 + intl: ^0.16.1 dev_dependencies: flutter_test: diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 07eff6d..bd9a2d9 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -201,9 +201,11 @@ class CalendarroState extends State { var maxWeeksNumber = DateUtils.calculateMaxWeeksNumberMonthly( widget.startDate, widget.endDate); + print("Max weeks number: $maxWeeksNumber"); widgetHeight = widget.dayLabelHeight + maxWeeksNumber * widget.dayTileHeight; } + print("Widget height: $widgetHeight"); return Container( height: widgetHeight, diff --git a/lib/date_utils.dart b/lib/date_utils.dart index 78de495..ce86b69 100644 --- a/lib/date_utils.dart +++ b/lib/date_utils.dart @@ -98,11 +98,13 @@ class DateUtils { DateTime endDate) { int monthsNumber = calculateMonthsDifference(startDate, endDate); + print("monthNumber: $monthsNumber"); List weeksNumbersMonthly = List(); - + print("$startDate,$endDate"); if (monthsNumber == 0) { + print("HERE"); return calculateWeeksNumber(startDate, endDate); } else { weeksNumbersMonthly.add( @@ -112,6 +114,7 @@ class DateUtils { DateTime firstDateOfMonth = getFirstDayOfMonth(startDate); for (int i = 1; i <= monthsNumber - 2; i++) { firstDateOfMonth = firstDateOfMonth.add(Duration(days: 31)); + print("firstDateofMonth :$firstDateOfMonth"); weeksNumbersMonthly.add( calculateWeeksNumber( firstDateOfMonth, @@ -123,6 +126,8 @@ class DateUtils { calculateWeeksNumber(getFirstDayOfMonth(endDate), endDate) ); + print(weeksNumbersMonthly); + weeksNumbersMonthly.sort((a, b) => b.compareTo(a)); return weeksNumbersMonthly[0]; } diff --git a/lib/default_day_tile.dart b/lib/default_day_tile.dart index 4f303cc..96f838f 100644 --- a/lib/default_day_tile.dart +++ b/lib/default_day_tile.dart @@ -32,15 +32,23 @@ 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), - ))), + child: Column( + children: [ + Container( + height: 20.0, + decoration: boxDecoration, + child: Center( + child: Text( + "${date.day}", + textAlign: TextAlign.center, + style: TextStyle(color: textColor), + ))), + Container( + //color: Colors.red, + height: 20.0, + ) + ], + ), onTap: handleTap, behavior: HitTestBehavior.translucent, )); diff --git a/pubspec.lock b/pubspec.lock index 7642229..bd50f82 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,28 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.4.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.12" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -45,35 +59,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" 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" sky_engine: dependency: transitive description: flutter @@ -85,7 +85,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" stack_trace: dependency: transitive description: @@ -106,7 +106,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -120,7 +120,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.16" typed_data: dependency: transitive description: @@ -136,4 +136,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.7.0 <3.0.0" From a0a6551541d85a91f3a7eafef4603dab3e744e62 Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Fri, 25 Sep 2020 21:27:10 +0530 Subject: [PATCH 2/8] Fix overflow bug #20 --- lib/date_utils.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/date_utils.dart b/lib/date_utils.dart index 78de495..82fdbba 100644 --- a/lib/date_utils.dart +++ b/lib/date_utils.dart @@ -112,6 +112,7 @@ class DateUtils { DateTime firstDateOfMonth = getFirstDayOfMonth(startDate); for (int i = 1; i <= monthsNumber - 2; i++) { firstDateOfMonth = firstDateOfMonth.add(Duration(days: 31)); + firstDateOfMonth = getFirstDayOfMonth(firstDateOfMonth); weeksNumbersMonthly.add( calculateWeeksNumber( firstDateOfMonth, From 664fcbf176db8b51f7839e9f7c74fba3f35be22f Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Sat, 3 Oct 2020 18:14:08 +0530 Subject: [PATCH 3/8] changes to example --- example/lib/main.dart | 86 ++++++++++++++++++++++++++++++++++++++- lib/calendarro.dart | 3 +- lib/date_utils.dart | 4 +- lib/default_day_tile.dart | 26 ++++-------- 4 files changed, 97 insertions(+), 22 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c3f59dd..93e90c8 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -9,6 +9,78 @@ var now = new DateTime.now(); void main() => runApp(new MyApp()); +class CustomDayTileBuilder extends DayTileBuilder{ + + CustomDayTileBuilder(); + + @override + Widget build(BuildContext context, DateTime date, onTap) { + return CustomCalenderDayItem(date: date, calendarroState: Calendarro.of(context), onTap: onTap,); + } + +} + +class CustomCalenderDayItem extends StatelessWidget { + CustomCalenderDayItem({this.date, this.calendarroState, this.onTap}); + + DateTime date; + CalendarroState calendarroState; + DateTimeCallback onTap; + + @override + Widget build(BuildContext context) { + bool isWeekend = DateUtils.isWeekend(date); + var textColor = isWeekend ? Colors.grey : Colors.black; + bool isToday = DateUtils.isToday(date); + calendarroState = Calendarro.of(context); + + bool daySelected = calendarroState.isDateSelected(date); + + BoxDecoration boxDecoration; + if (daySelected) { + boxDecoration = BoxDecoration(color: Colors.blue, shape: BoxShape.circle); + } else if (isToday) { + boxDecoration = BoxDecoration( + border: Border.all( + color: Colors.white, + width: 1.0, + ), + shape: BoxShape.circle); + } + + return Expanded( + child: GestureDetector( + child: Column( + children: [ + Container( + height: 20.0, + decoration: boxDecoration, + child: Center( + child: Text( + "${date.day}", + textAlign: TextAlign.center, + style: TextStyle(color: textColor), + ))), + Container( + height: 20.0, + child: Image.network("https://www.netclipart.com/pp/m/138-1388728_cloudy-day-outlined-cloudy-weather-icon-png.png"), + ) + ], + ), + onTap: handleTap, + behavior: HitTestBehavior.translucent, + )); + } + void handleTap() { + if (onTap != null) { + onTap(date); + } + + calendarroState.setSelectedDate(date); + calendarroState.setCurrentDate(date); + } +} + class MyApp extends StatefulWidget { @override @@ -42,16 +114,20 @@ class _CalenderState extends State { var currentMonth = now.month; var startDate = DateUtils.getFirstDayOfCurrentMonth(); var endDate = DateTime(2021); + List selectedDates = []; Calendarro monthCalendarro; @override Widget build(BuildContext context) { print("Current month: $currentMonth"); + print("Selected Dates : $selectedDates"); monthCalendarro = Calendarro( + dayTileBuilder: CustomDayTileBuilder(), startDate: startDate, endDate: endDate, displayMode: DisplayMode.MONTHS, - selectionMode: SelectionMode.MULTI, + selectionMode: SelectionMode.RANGE, + selectedDates: selectedDates, weekdayLabelsRow: CustomWeekdayLabelsRow(), onPageSelected: (nextStartDate, nextEndDate){ print("Selected $nextStartDate - $nextEndDate"); @@ -64,6 +140,9 @@ class _CalenderState extends State { }, onTap: (date){ print("Tapped $date"); + setState(() { + //selectedDates = selectedDates; + }); }, ); return Column( @@ -75,7 +154,10 @@ class _CalenderState extends State { textAlign: TextAlign.center, ), ), - monthCalendarro + monthCalendarro, + Container( + child: Text("$selectedDates"), + ) ], ); } diff --git a/lib/calendarro.dart b/lib/calendarro.dart index bd9a2d9..553e383 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -201,11 +201,10 @@ class CalendarroState extends State { var maxWeeksNumber = DateUtils.calculateMaxWeeksNumberMonthly( widget.startDate, widget.endDate); - print("Max weeks number: $maxWeeksNumber"); widgetHeight = widget.dayLabelHeight + maxWeeksNumber * widget.dayTileHeight; } - print("Widget height: $widgetHeight"); + print(widgetHeight); return Container( height: widgetHeight, diff --git a/lib/date_utils.dart b/lib/date_utils.dart index ce86b69..44bfccb 100644 --- a/lib/date_utils.dart +++ b/lib/date_utils.dart @@ -72,7 +72,8 @@ class DateUtils { } static DateTime getFirstDayOfMonth(DateTime month) { - return DateTime(month.year, month.month); + print(month); + return DateTime(month.year, month.month,1); } static DateTime getLastDayOfMonth(DateTime month) { @@ -114,6 +115,7 @@ class DateUtils { DateTime firstDateOfMonth = getFirstDayOfMonth(startDate); for (int i = 1; i <= monthsNumber - 2; i++) { firstDateOfMonth = firstDateOfMonth.add(Duration(days: 31)); + firstDateOfMonth = getFirstDayOfMonth(firstDateOfMonth); print("firstDateofMonth :$firstDateOfMonth"); weeksNumbersMonthly.add( calculateWeeksNumber( diff --git a/lib/default_day_tile.dart b/lib/default_day_tile.dart index 96f838f..4f303cc 100644 --- a/lib/default_day_tile.dart +++ b/lib/default_day_tile.dart @@ -32,23 +32,15 @@ class CalendarroDayItem extends StatelessWidget { return Expanded( child: GestureDetector( - child: Column( - children: [ - Container( - height: 20.0, - decoration: boxDecoration, - child: Center( - child: Text( - "${date.day}", - textAlign: TextAlign.center, - style: TextStyle(color: textColor), - ))), - Container( - //color: Colors.red, - height: 20.0, - ) - ], - ), + 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, )); From 353cca670e779575b6594a71f71bf2f475d2587e Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Sun, 4 Oct 2020 01:38:01 +0530 Subject: [PATCH 4/8] debug --- example/lib/main.dart | 4 +++- lib/calendarro.dart | 1 + lib/date_utils.dart | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 93e90c8..e649dbd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,8 @@ import 'package:calendarro/date_utils.dart'; import 'package:flutter/material.dart'; import 'package:calendarro/calendarro.dart'; + +import 'package:calendarro/date_utils.dart'; import 'package:intl/intl.dart'; List months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; @@ -157,7 +159,7 @@ class _CalenderState extends State { monthCalendarro, Container( child: Text("$selectedDates"), - ) + ), ], ); } diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 553e383..d045ab8 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -150,6 +150,7 @@ class CalendarroState extends State { setState(() { switch (widget.selectionMode) { case SelectionMode.SINGLE: + print("setting single date"); selectedSingleDate = date; break; case SelectionMode.MULTI: diff --git a/lib/date_utils.dart b/lib/date_utils.dart index 44bfccb..405b978 100644 --- a/lib/date_utils.dart +++ b/lib/date_utils.dart @@ -71,6 +71,17 @@ class DateUtils { return firstDayOfCurrentMonth; } + static DateTime subtractMonths(DateTime fromMonth, int months) { + DateTime firstDayOfCurrentMonth = fromMonth; + for (int i = 0; i < months; i++) { + firstDayOfCurrentMonth = + getFirstDayOfMonth(firstDayOfCurrentMonth) + .subtract(Duration(days: 1)); + } + + return firstDayOfCurrentMonth; + } + static DateTime getFirstDayOfMonth(DateTime month) { print(month); return DateTime(month.year, month.month,1); From c25c11157f011bf23b73ce531d1ba630cf0f8c0c Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Mon, 5 Oct 2020 22:22:50 +0530 Subject: [PATCH 5/8] access tile height and width --- example/lib/main.dart | 4 +++- lib/calendarro.dart | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index e649dbd..afa1e4a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -117,6 +117,7 @@ class _CalenderState extends State { var startDate = DateUtils.getFirstDayOfCurrentMonth(); var endDate = DateTime(2021); List selectedDates = []; + DateTime singleSelectedDate; Calendarro monthCalendarro; @override Widget build(BuildContext context) { @@ -128,8 +129,9 @@ class _CalenderState extends State { startDate: startDate, endDate: endDate, displayMode: DisplayMode.MONTHS, - selectionMode: SelectionMode.RANGE, + selectionMode: SelectionMode.SINGLE, selectedDates: selectedDates, + selectedSingleDate: singleSelectedDate, weekdayLabelsRow: CustomWeekdayLabelsRow(), onPageSelected: (nextStartDate, nextEndDate){ print("Selected $nextStartDate - $nextEndDate"); diff --git a/lib/calendarro.dart b/lib/calendarro.dart index d045ab8..98ebd98 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -48,6 +48,8 @@ class Calendarro extends StatefulWidget { this.onTap, this.onPageSelected, this.weekdayLabelsRow, + this.dayTileHeight, + this.dayLabelHeight }) : super(key: key) { if (startDate == null) { startDate = DateUtils.getFirstDayOfCurrentMonth(); From 0641002d9e66552309a4019894340d329f0bdea8 Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Mon, 5 Oct 2020 23:33:24 +0530 Subject: [PATCH 6/8] range date selection odified --- lib/calendarro.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 98ebd98..2cc34d2 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -237,8 +237,8 @@ class CalendarroState extends State { var dateBetweenDatesRange = (date.isAfter(selectedDates[0]) && date.isBefore(selectedDates[1])); return DateUtils.isSameDay(date, selectedDates[0]) - || DateUtils.isSameDay(date, selectedDates[1]) - || dateBetweenDatesRange; + || DateUtils.isSameDay(date, selectedDates[1]); + //|| dateBetweenDatesRange; } break; } From 7a478a1546d844f9487c548860112c095889c813 Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Mon, 5 Oct 2020 23:40:47 +0530 Subject: [PATCH 7/8] range date selection odified-revert --- lib/calendarro.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 2cc34d2..98ebd98 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -237,8 +237,8 @@ class CalendarroState extends State { var dateBetweenDatesRange = (date.isAfter(selectedDates[0]) && date.isBefore(selectedDates[1])); return DateUtils.isSameDay(date, selectedDates[0]) - || DateUtils.isSameDay(date, selectedDates[1]); - //|| dateBetweenDatesRange; + || DateUtils.isSameDay(date, selectedDates[1]) + || dateBetweenDatesRange; } break; } From 4860d3bc98fc918b93059f6251812ea3df983136 Mon Sep 17 00:00:00 2001 From: Ebey Abraham Date: Wed, 7 Oct 2020 10:08:01 +0530 Subject: [PATCH 8/8] remove stray print statements --- lib/calendarro.dart | 2 +- lib/date_utils.dart | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/calendarro.dart b/lib/calendarro.dart index 98ebd98..281652a 100644 --- a/lib/calendarro.dart +++ b/lib/calendarro.dart @@ -207,7 +207,7 @@ class CalendarroState extends State { widgetHeight = widget.dayLabelHeight + maxWeeksNumber * widget.dayTileHeight; } - print(widgetHeight); + //print(widgetHeight); return Container( height: widgetHeight, diff --git a/lib/date_utils.dart b/lib/date_utils.dart index 405b978..3db2239 100644 --- a/lib/date_utils.dart +++ b/lib/date_utils.dart @@ -83,7 +83,7 @@ class DateUtils { } static DateTime getFirstDayOfMonth(DateTime month) { - print(month); + //print(month); return DateTime(month.year, month.month,1); } @@ -110,13 +110,13 @@ class DateUtils { DateTime endDate) { int monthsNumber = calculateMonthsDifference(startDate, endDate); - print("monthNumber: $monthsNumber"); + //print("monthNumber: $monthsNumber"); List weeksNumbersMonthly = List(); - print("$startDate,$endDate"); + //print("$startDate,$endDate"); if (monthsNumber == 0) { - print("HERE"); + //print("HERE"); return calculateWeeksNumber(startDate, endDate); } else { weeksNumbersMonthly.add( @@ -127,7 +127,7 @@ class DateUtils { for (int i = 1; i <= monthsNumber - 2; i++) { firstDateOfMonth = firstDateOfMonth.add(Duration(days: 31)); firstDateOfMonth = getFirstDayOfMonth(firstDateOfMonth); - print("firstDateofMonth :$firstDateOfMonth"); + //print("firstDateofMonth :$firstDateOfMonth"); weeksNumbersMonthly.add( calculateWeeksNumber( firstDateOfMonth, @@ -139,7 +139,7 @@ class DateUtils { calculateWeeksNumber(getFirstDayOfMonth(endDate), endDate) ); - print(weeksNumbersMonthly); + //print(weeksNumbersMonthly); weeksNumbersMonthly.sort((a, b) => b.compareTo(a)); return weeksNumbersMonthly[0];