From 025be9826394e9bcefb64e275501b56504201afb Mon Sep 17 00:00:00 2001 From: xiaodong <450468291@qq.com> Date: Fri, 27 Sep 2019 11:24:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAconfiguration=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E5=B0=86=E9=85=8D=E7=BD=AE=E7=9A=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=94=BE=E5=88=B0=E8=BF=99=E9=87=8C=20=E5=BC=95=E5=85=A5provid?= =?UTF-8?q?er=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86,=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=B7=B1=E5=B1=82=E5=B5=8C=E5=A5=97=E4=BC=A0=E9=80=92=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20=E5=91=A8=E8=A7=86=E5=9B=BE=E5=92=8C=E6=9C=88?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=EF=BC=8C=E8=81=94=E5=8A=A8=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E7=B1=BBLogUtil?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E6=9F=A5=E7=9C=8B=E8=B0=83=E8=AF=95?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0example=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/custom_sign_page.dart | 225 +++++++++++++++++++++++ example/lib/main.dart | 10 + example/lib/multi_select_style_page.dart | 4 +- example/lib/progress_style_page.dart | 18 +- example/pubspec.lock | 34 +++- example/pubspec.yaml | 2 +- lib/configuration.dart | 15 +- lib/controller.dart | 14 +- lib/flutter_custom_calendar.dart | 1 + lib/model/date_model.dart | 3 +- lib/style/style.dart | 13 +- lib/utils/date_util.dart | 31 ++-- lib/utils/lunar_util.dart | 10 +- lib/widget/default_custom_day_view.dart | 7 +- lib/widget/month_view.dart | 2 +- lib/widget/week_view.dart | 24 +-- 16 files changed, 339 insertions(+), 74 deletions(-) create mode 100644 example/lib/custom_sign_page.dart diff --git a/example/lib/custom_sign_page.dart b/example/lib/custom_sign_page.dart new file mode 100644 index 0000000..642a87e --- /dev/null +++ b/example/lib/custom_sign_page.dart @@ -0,0 +1,225 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_custom_calendar/flutter_custom_calendar.dart'; +import 'package:flutter_custom_calendar/style/style.dart'; +import 'package:random_pk/random_pk.dart'; + +/** + * 自定义一些额外的数据,实现标记功能 + */ +class CustomSignPage extends StatefulWidget { + CustomSignPage({Key key, this.title}) : super(key: key); + + final String title; + + @override + _CustomSignPageState createState() => _CustomSignPageState(); +} + +class _CustomSignPageState extends State { + String text; + + CalendarController controller; + + Map customExtraData = { + DateModel.fromDateTime(DateTime.now().add(Duration(days: -1))): "假", + DateModel.fromDateTime(DateTime.now().add(Duration(days: -2))): "游", + DateModel.fromDateTime(DateTime.now().add(Duration(days: -3))): "事", + DateModel.fromDateTime(DateTime.now().add(Duration(days: -4))): "班", + DateModel.fromDateTime(DateTime.now().add(Duration(days: -5))): "假", + DateModel.fromDateTime(DateTime.now().add(Duration(days: -6))): "游", + DateModel.fromDateTime(DateTime.now().add(Duration(days: -7))): "事", + DateModel.fromDateTime(DateTime.now().add(Duration(days: -8))): "班", + DateModel.fromDateTime(DateTime.now()): "假", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 1))): "假", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 2))): "游", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 3))): "事", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 4))): "班", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 5))): "假", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 6))): "游", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 7))): "事", + DateModel.fromDateTime(DateTime.now().add(Duration(days: 8))): "班", + }; + + @override + void initState() { + text = "${DateTime.now().year}年${DateTime.now().month}月"; + + controller = new CalendarController( + weekBarItemWidgetBuilder: () { + return CustomStyleWeekBarItem(); + }, + dayWidgetBuilder: (dateModel) { + return CustomStyleDayWidget(dateModel); + }, + extraDataMap: customExtraData); + + controller.addMonthChangeListener( + (year, month) { + setState(() { + text = "$year年$month月"; + }); + }, + ); + + controller.addOnCalendarSelectListener((dateModel) { + //刷新选择的时间 + setState(() {}); + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: new Container( + child: new Column( + children: [ + new Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new IconButton( + icon: Icon(Icons.navigate_before), + onPressed: () { + controller.moveToPreviousMonth(); + }), + new Text(text), + new IconButton( + icon: Icon(Icons.navigate_next), + onPressed: () { + controller.moveToNextMonth(); + }), + ], + ), + CalendarViewWidget( + calendarController: controller, + ), + new Text( + "自定义创建Item\n选中的时间:\n${controller.getSingleSelectCalendar().toString()}"), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + controller.toggleExpandStatus(); + }, + tooltip: 'Increment', + child: Icon(Icons.add), + ), // This trailing comma makes auto-formatting nicer for build methods. + ); + } +} + +class CustomStyleWeekBarItem extends BaseWeekBar { + List weekList = ["一", "二", "三", "四", "五", "六", "日"]; + + @override + Widget getWeekBarItem(int index) { + return new Container( + child: new Center( + child: new Text(weekList[index]), + ), + ); + } +} + +class CustomStyleDayWidget extends BaseCombineDayWidget { + CustomStyleDayWidget(DateModel dateModel) : super(dateModel); + + @override + Widget getNormalWidget(DateModel dateModel) { + return Container( + margin: EdgeInsets.all(8), + child: new Stack( + alignment: Alignment.center, + children: [ + new Column( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + //公历 + new Expanded( + child: Center( + child: new Text( + dateModel.day.toString(), + style: currentMonthTextStyle, + ), + ), + ), + + //农历 + new Expanded( + child: Center( + child: new Text( + "${dateModel.lunarString}", + style: lunarTextStyle, + ), + ), + ), + ], + ), + dateModel.extraData != null + ? Positioned( + child: Text( + "${dateModel.extraData}", + style: TextStyle(fontSize: 10, color: RandomColor.next()), + ), + right: 0, + top: 0, + ) + : Container() + ], + ), + ); + } + + @override + Widget getSelectedWidget(DateModel dateModel) { + return Container( + margin: EdgeInsets.all(8), + foregroundDecoration: + new BoxDecoration(border: Border.all(width: 2, color: Colors.blue)), + child: new Stack( + alignment: Alignment.center, + children: [ + new Column( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + //公历 + new Expanded( + child: Center( + child: new Text( + dateModel.day.toString(), + style: currentMonthTextStyle, + ), + ), + ), + + //农历 + new Expanded( + child: Center( + child: new Text( + "${dateModel.lunarString}", + style: lunarTextStyle, + ), + ), + ), + ], + ), + dateModel.extraData != null + ? Positioned( + child: Text( + "${dateModel.extraData}", + style: TextStyle(fontSize: 10, color: RandomColor.next()), + ), + right: 0, + top: 0, + ) + : Container() + ], + ), + ); + } +} diff --git a/example/lib/main.dart b/example/lib/main.dart index b326919..8b0ebbc 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'custom_sign_page.dart'; import 'custom_style_page.dart'; import 'default_style_page.dart'; import 'multi_select_style_page.dart'; @@ -24,6 +25,9 @@ class MyApp extends StatelessWidget { "/progress": (context) => ProgressStylePage( title: "进度条风格+单选", ), + "/custom_sign": (context) => CustomSignPage( + title: "自定义额外数据,实现标记功能", + ) }, title: 'Flutter Demo', theme: ThemeData( @@ -64,6 +68,12 @@ class HomePage extends StatelessWidget { }, child: new Text("进度条风格+单选"), ), + new RaisedButton( + onPressed: () { + Navigator.pushNamed(context, "/custom_sign"); + }, + child: new Text("自定义额外数据,实现标记功能"), + ), ], ), ), diff --git a/example/lib/multi_select_style_page.dart b/example/lib/multi_select_style_page.dart index 377fa63..8545024 100644 --- a/example/lib/multi_select_style_page.dart +++ b/example/lib/multi_select_style_page.dart @@ -81,8 +81,8 @@ class _MultiSelectStylePageState extends State { CalendarViewWidget( calendarController: controller, ), - new Text( - "多选模式\n选中的时间:\n${controller.getMultiSelectCalendar().toString()}"), +// new Text( +// "多选模式\n选中的时间:\n${controller.getMultiSelectCalendar().toString()}"), ], ), ), diff --git a/example/lib/progress_style_page.dart b/example/lib/progress_style_page.dart index 989b09b..8716d1a 100644 --- a/example/lib/progress_style_page.dart +++ b/example/lib/progress_style_page.dart @@ -23,13 +23,13 @@ class _ProgressStylePageState extends State { DateTime now = DateTime.now(); DateTime temp = DateTime(now.year, now.month, now.day); - Map progressMap = { - temp.add(Duration(days: 1)): 0, - temp.add(Duration(days: 2)): 20, - temp.add(Duration(days: 3)): 40, - temp.add(Duration(days: 4)): 60, - temp.add(Duration(days: 5)): 80, - temp.add(Duration(days: 6)): 100, + Map progressMap = { + DateModel.fromDateTime(temp.add(Duration(days: 1))): 0, + DateModel.fromDateTime(temp.add(Duration(days: 2))): 20, + DateModel.fromDateTime(temp.add(Duration(days: 3))): 40, + DateModel.fromDateTime(temp.add(Duration(days: 4))): 60, + DateModel.fromDateTime(temp.add(Duration(days: 5))): 80, + DateModel.fromDateTime(temp.add(Duration(days: 6))): 100, }; controller = new CalendarController( @@ -90,8 +90,8 @@ class _ProgressStylePageState extends State { CalendarViewWidget( calendarController: controller, ), - new Text( - "单选模式\n选中的时间:\n${controller.getSingleSelectCalendar().toString()}"), +// new Text( +// "单选模式\n选中的时间:\n${controller.getSingleSelectCalendar().toString()}"), ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 2ffd29f..86eee3b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive @@ -7,14 +7,14 @@ packages: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" + version: "2.3.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -66,28 +66,42 @@ packages: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.1.7" path: dependency: transitive description: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.2" + version: "1.6.4" pedantic: dependency: transitive description: name: pedantic url: "https://pub.flutter-io.cn" source: hosted - version: "1.5.0" + version: "1.8.0+1" + provider: + dependency: transitive + description: + name: provider + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.0+1" quiver: dependency: transitive description: name: quiver url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.2" + version: "2.0.5" + random_pk: + dependency: "direct main" + description: + name: random_pk + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.3" sky_engine: dependency: transitive description: flutter @@ -120,7 +134,7 @@ packages: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -134,7 +148,7 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.4" + version: "0.2.5" typed_data: dependency: transitive description: @@ -150,4 +164,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.2.2 <3.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 306fb75..da91d24 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -27,7 +27,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 - + random_pk: any flutter_custom_calendar: path: ../ diff --git a/lib/configuration.dart b/lib/configuration.dart index 7298b0d..be3413a 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -9,8 +9,8 @@ class CalendarConfiguration { //默认是单选,可以配置为MODE_SINGLE_SELECT,MODE_MULTI_SELECT int selectMode; - //展开状态 - bool defaultExpandStatus; + bool defaultExpandStatus; //展开状态,true代表是月视图,false代表是周视图 + bool enableExpand; //是否可以展开 //日历显示的最小年份和最大年份 int minYear; @@ -35,13 +35,13 @@ class CalendarConfiguration { Set defaultSelectedDateList = new Set(); //默认被选中的日期 int maxMultiSelectCount; //多选,最多选多少个 - Map extraDataMap = new Map(); //自定义额外的数据 + Map extraDataMap = new Map(); //自定义额外的数据 /** * UI绘制方面的绘制 */ - double verticalSpacing ;//日历item之间的竖直方向间距,默认10 - + double verticalSpacing; //日历item之间的竖直方向间距,默认10 + BoxDecoration boxDecoration; //整体的背景设置 //支持自定义绘制 DayWidgetBuilder dayWidgetBuilder; //创建日历item @@ -85,8 +85,9 @@ class CalendarConfiguration { this.weekList, this.pageController, this.weekController, - this.verticalSpacing, - bool defaultExpandStatus = true}) { + this.verticalSpacing, + this.enableExpand, + bool defaultExpandStatus}) { this.defaultExpandStatus = defaultExpandStatus; } diff --git a/lib/controller.dart b/lib/controller.dart index de4b83b..0bc6046 100644 --- a/lib/controller.dart +++ b/lib/controller.dart @@ -1,16 +1,13 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; import 'package:flutter_custom_calendar/calendar_provider.dart'; import 'package:flutter_custom_calendar/configuration.dart'; +import 'package:flutter_custom_calendar/constants/constants.dart'; +import 'package:flutter_custom_calendar/model/date_model.dart'; import 'package:flutter_custom_calendar/utils/LogUtil.dart'; import 'package:flutter_custom_calendar/utils/date_util.dart'; import 'package:flutter_custom_calendar/widget/default_combine_day_view.dart'; import 'package:flutter_custom_calendar/widget/default_custom_day_view.dart'; -import 'package:flutter_custom_calendar/model/date_model.dart'; import 'package:flutter_custom_calendar/widget/default_week_bar.dart'; -import 'package:flutter_custom_calendar/constants/constants.dart'; -import 'package:provider/provider.dart'; /** * 利用controller来控制视图 @@ -18,7 +15,7 @@ import 'package:provider/provider.dart'; class CalendarController { static const Set EMPTY_SET = {}; - static const Map EMPTY_MAP = {}; + static const Map EMPTY_MAP = {}; static const Duration DEFAULT_DURATION = const Duration(milliseconds: 500); CalendarConfiguration calendarConfiguration; @@ -54,7 +51,8 @@ class CalendarController { DateModel selectDateModel, int maxMultiSelectCount = 9999, double verticalSpacing = 10, - Map extraDataMap = EMPTY_MAP}) { + bool enableExpand = true, + Map extraDataMap = EMPTY_MAP}) { LogUtil.log(TAG: this.runtimeType, message: "init CalendarConfiguration"); calendarConfiguration = CalendarConfiguration( selectMode: selectMode, @@ -70,7 +68,9 @@ class CalendarController { maxSelectYear: maxSelectYear, maxSelectMonth: maxSelectMonth, defaultExpandStatus: expandStatus, + extraDataMap: extraDataMap, maxSelectDay: maxSelectDay, + enableExpand: enableExpand, verticalSpacing: verticalSpacing); calendarConfiguration.dayWidgetBuilder = dayWidgetBuilder; diff --git a/lib/flutter_custom_calendar.dart b/lib/flutter_custom_calendar.dart index 4a31e33..d9d34c6 100644 --- a/lib/flutter_custom_calendar.dart +++ b/lib/flutter_custom_calendar.dart @@ -9,3 +9,4 @@ export 'package:flutter_custom_calendar/model/date_model.dart'; export 'package:flutter_custom_calendar/widget/default_combine_day_view.dart'; export 'package:flutter_custom_calendar/widget/default_custom_day_view.dart'; export 'package:flutter_custom_calendar/widget/default_week_bar.dart'; +export 'package:flutter_custom_calendar/configuration.dart'; diff --git a/lib/model/date_model.dart b/lib/model/date_model.dart index 9ed80ef..70d0f11 100644 --- a/lib/model/date_model.dart +++ b/lib/model/date_model.dart @@ -17,10 +17,11 @@ class DateModel { String gregorianFestival; //公历节日 String traditionFestival; //传统农历节日 + bool isCurrentMonth;//是否是当前月份 bool isCurrentDay; //是否是今天 bool isLeapYear; //是否是闰年 bool isWeekend; //是否是周末 - int leapMonth; //是否是闰月 +// int leapMonth; //是否是闰月 Object extraData; //自定义的额外数据 diff --git a/lib/style/style.dart b/lib/style/style.dart index 09faae3..5d94265 100644 --- a/lib/style/style.dart +++ b/lib/style/style.dart @@ -1,18 +1,21 @@ - import 'package:flutter/material.dart'; - //顶部7天的文案 -TextStyle topWeekTextStyle=new TextStyle(fontSize: 12); +TextStyle topWeekTextStyle = new TextStyle(fontSize: 12); //当前月份的日期的文字 TextStyle currentMonthTextStyle = -new TextStyle(color: Colors.black, fontSize: 16); + new TextStyle(color: Colors.black, fontSize: 16); //下一个月或者上一个月的日期的文字 TextStyle preOrNextMonthTextStyle = -new TextStyle(color: Colors.grey, fontSize: 18); + new TextStyle(color: Colors.grey, fontSize: 18); //农历的字体 TextStyle lunarTextStyle = new TextStyle(color: Colors.grey, fontSize: 12); +//不是当前月份的日期的文字 +TextStyle notCurrentMonthTextStyle = + new TextStyle(color: Colors.grey, fontSize: 16); + +TextStyle currentDayTextStyle = new TextStyle(color: Colors.red, fontSize: 16); diff --git a/lib/utils/date_util.dart b/lib/utils/date_util.dart index 364f83c..2117eb3 100644 --- a/lib/utils/date_util.dart +++ b/lib/utils/date_util.dart @@ -65,8 +65,8 @@ class DateUtil { * 是否是今天 */ static bool isCurrentDay(int year, int month, int day) { - return new DateTime(year, month, day).difference(DateTime.now()).inDays == - 0; + DateTime now = DateTime.now(); + return now.year == year && now.month == month && now.day == day; } /** @@ -113,7 +113,7 @@ class DateUtil { int year, int month, DateTime currentDate, int weekStart, {DateModel minSelectDate, DateModel maxSelectDate, - Map extraDataMap}) { + Map extraDataMap}) { weekStart = DateTime.monday; //获取月视图其实偏移量 int mPreDiff = getIndexOfFirstDayInMonth(new DateTime(year, month)); @@ -136,19 +136,22 @@ class DateUtil { DateTime temp; DateModel dateModel; if (i < mPreDiff - 1) { + //这个上一月的几天 temp = firstDayOfMonth.subtract(Duration(days: mPreDiff - i - 1)); dateModel = DateModel.fromDateTime(temp); - //这个上一月的几天 + dateModel.isCurrentMonth = false; } else if (i >= monthDayCount + (mPreDiff - 1)) { + //这是下一月的几天 temp = lastDayOfMonth .add(Duration(days: i - mPreDiff - monthDayCount + 2)); dateModel = DateModel.fromDateTime(temp); - //这是下一月的几天 + dateModel.isCurrentMonth = false; } else { //这个月的 temp = new DateTime(year, month, i - mPreDiff + 2); dateModel = DateModel.fromDateTime(temp); + dateModel.isCurrentMonth = true; } //判断是否在范围内 @@ -160,9 +163,8 @@ class DateUtil { } //将自定义额外的数据,存储到相应的model中 if (extraDataMap != null && extraDataMap.isNotEmpty) { - DateTime dateTime = dateModel.getDateTime(); - if (extraDataMap.containsKey(dateTime)) { - dateModel.extraData = extraDataMap[dateTime]; + if (extraDataMap.containsKey(dateModel)) { + dateModel.extraData = extraDataMap[dateModel]; } } @@ -197,7 +199,7 @@ class DateUtil { int year, int month, DateTime currentDate, int weekStart, {DateModel minSelectDate, DateModel maxSelectDate, - Map extraDataMap}) { + Map extraDataMap}) { LogUtil.log(TAG: "DateUtil", message: "initCalendarForWeekView"); List items = List(); @@ -217,11 +219,16 @@ class DateUtil { } else { dateModel.isInRange = false; } + if (month == dateModel.month) { + dateModel.isCurrentMonth = true; + } else { + dateModel.isCurrentMonth = false; + } + //将自定义额外的数据,存储到相应的model中 if (extraDataMap != null && extraDataMap.isNotEmpty) { - DateTime dateTime = dateModel.getDateTime(); - if (extraDataMap.containsKey(dateTime)) { - dateModel.extraData = extraDataMap[dateTime]; + if (extraDataMap.containsKey(dateModel)) { + dateModel.extraData = extraDataMap[dateModel]; } } diff --git a/lib/utils/lunar_util.dart b/lib/utils/lunar_util.dart index 0676cd2..18c9a2c 100644 --- a/lib/utils/lunar_util.dart +++ b/lib/utils/lunar_util.dart @@ -766,16 +766,16 @@ class LunarUtil { dateModel.isLeapYear = DateUtil.isLeapYear(year); dateModel.isCurrentDay = DateUtil.isCurrentDay(year, month, day); - List lunar = LunarUtil.solarToLunar(year, month, day); + List lunar = LunarUtil.solarToLunar(2020, 2, day); dateModel.lunarYear = (lunar[0]); dateModel.lunarMonth = (lunar[1]); dateModel.lunarDay = (lunar[2]); - if (lunar[3] == 1) { - //如果是闰月 - dateModel.leapMonth = lunar[1]; - } +// if (lunar[3] == 1) { +// //如果是闰月 +// dateModel.leapMonth = lunar[1]; +// } //24节气 String solarTerm = getSolarTerm(year, month, day); dateModel.solarTerm=solarTerm; diff --git a/lib/widget/default_custom_day_view.dart b/lib/widget/default_custom_day_view.dart index da62052..3dd1f92 100644 --- a/lib/widget/default_custom_day_view.dart +++ b/lib/widget/default_custom_day_view.dart @@ -72,8 +72,11 @@ class DefaultCustomDayWidget extends BaseCustomDayWidget { void defaultDrawNormal(DateModel dateModel, Canvas canvas, Size size) { //顶部的文字 TextPainter dayTextPainter = new TextPainter() - ..text = - TextSpan(text: dateModel.day.toString(), style: currentMonthTextStyle) + ..text = TextSpan( + text: dateModel.day.toString(), + style: dateModel.isCurrentDay + ? currentDayTextStyle + : currentMonthTextStyle) ..textDirection = TextDirection.ltr ..textAlign = TextAlign.center; diff --git a/lib/widget/month_view.dart b/lib/widget/month_view.dart index e2a1e50..a6b25a7 100644 --- a/lib/widget/month_view.dart +++ b/lib/widget/month_view.dart @@ -18,7 +18,7 @@ class MonthView extends StatefulWidget { final DateModel minSelectDate; final DateModel maxSelectDate; - final Map extraDataMap; //自定义额外的数据 + final Map extraDataMap; //自定义额外的数据 const MonthView({ @required this.year, diff --git a/lib/widget/week_view.dart b/lib/widget/week_view.dart index d14d0f8..59818ae 100644 --- a/lib/widget/week_view.dart +++ b/lib/widget/week_view.dart @@ -11,14 +11,14 @@ import 'package:provider/provider.dart'; * 周视图,只显示本周的日子 */ class WeekView extends StatefulWidget { - final int year; - final int month; - final DateModel firstDayOfWeek; + final int year; + final int month; + final DateModel firstDayOfWeek; - final DateModel minSelectDate; - final DateModel maxSelectDate; + final DateModel minSelectDate; + final DateModel maxSelectDate; - final Map extraDataMap; //自定义额外的数据 + final Map extraDataMap; //自定义额外的数据 const WeekView( {@required this.year, @@ -39,7 +39,7 @@ class _WeekViewState extends State { void initState() { super.initState(); items = DateUtil.initCalendarForWeekView( - 2019, 9, widget.firstDayOfWeek.getDateTime(), 0, + widget.year, widget.month, widget.firstDayOfWeek.getDateTime(), 0, minSelectDate: widget.minSelectDate, maxSelectDate: widget.maxSelectDate, extraDataMap: widget.extraDataMap); @@ -101,11 +101,11 @@ class _WeekViewState extends State { calendarProvider.selectDateModel = dateModel; configuration.calendarSelect(dateModel); // setState(() { - if (calendarProvider.selectedDateList.contains(dateModel)) { - calendarProvider.selectedDateList.remove(dateModel); - } else { - calendarProvider.selectedDateList.add(dateModel); - } + if (calendarProvider.selectedDateList.contains(dateModel)) { + calendarProvider.selectedDateList.remove(dateModel); + } else { + calendarProvider.selectedDateList.add(dateModel); + } // }); } else { calendarProvider.selectDateModel = dateModel;