From fdcb1c2c8508f3327131d22085008fc2c52511ef Mon Sep 17 00:00:00 2001 From: LXD312569496 <450468291@qq.com> Date: Thu, 31 Oct 2019 22:03:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=88=A0=E6=8E=89=E6=B2=A1=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/blue_style_page.dart | 12 ++--- example/lib/custom_sign_page.dart | 3 +- example/lib/custom_style_page.dart | 3 +- example/lib/default_style_page.dart | 9 ++-- example/lib/main.dart | 63 +----------------------- example/lib/multi_select_style_page.dart | 4 +- example/lib/only_week_page.dart | 1 + example/lib/progress_style_page.dart | 3 +- example/lib/red_style_page.dart | 11 +++-- lib/utils/date_util.dart | 3 -- lib/widget/base_day_view.dart | 2 +- lib/widget/calendar_view.dart | 15 +++--- lib/widget/fast_click_widget.dart | 32 ------------ lib/widget/month_view.dart | 2 - lib/widget/month_view_pager.dart | 3 +- lib/widget/week_view.dart | 1 - lib/widget/week_view_pager.dart | 7 +-- 17 files changed, 41 insertions(+), 133 deletions(-) delete mode 100644 lib/widget/fast_click_widget.dart diff --git a/example/lib/blue_style_page.dart b/example/lib/blue_style_page.dart index 297c2f0..121704d 100644 --- a/example/lib/blue_style_page.dart +++ b/example/lib/blue_style_page.dart @@ -1,7 +1,5 @@ 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 BlueStylePage extends StatefulWidget { @@ -23,6 +21,7 @@ class _BlueStylePageState extends State { @override void initState() { + super.initState(); controller = new CalendarController( showMode: CalendarConstants.MODE_SHOW_MONTH_AND_WEEK, @@ -81,8 +80,7 @@ class _BlueStylePageState extends State { height: 20, ), Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - mainAxisSize: MainAxisSize.min, + mainAxisSize: MainAxisSize.max, children: [ Container( height: 100, @@ -146,7 +144,7 @@ class _BlueStylePageState extends State { } class CustomStyleWeekBarItem extends BaseWeekBar { - List weekList = ["mo", "tu", "we", "th", "fr", "sa", "su"]; + final List weekList = ["mo", "tu", "we", "th", "fr", "sa", "su"]; //可以直接重写build方法 @override @@ -183,10 +181,10 @@ class CustomStyleWeekBarItem extends BaseWeekBar { class CustomStyleDayWidget extends BaseCombineDayWidget { CustomStyleDayWidget(DateModel dateModel) : super(dateModel); - TextStyle normalTextStyle = + final TextStyle normalTextStyle = TextStyle(fontWeight: FontWeight.w700, color: Colors.black); - TextStyle noIsCurrentMonthTextStyle = + final TextStyle noIsCurrentMonthTextStyle = TextStyle(fontWeight: FontWeight.w700, color: Colors.grey); @override diff --git a/example/lib/custom_sign_page.dart b/example/lib/custom_sign_page.dart index b4df94c..63466f9 100644 --- a/example/lib/custom_sign_page.dart +++ b/example/lib/custom_sign_page.dart @@ -43,6 +43,7 @@ class _CustomSignPageState extends State { @override void initState() { + super.initState(); controller = new CalendarController( extraDataMap: customExtraData); @@ -124,7 +125,7 @@ class _CustomSignPageState extends State { } class CustomStyleWeekBarItem extends BaseWeekBar { - List weekList = ["一", "二", "三", "四", "五", "六", "日"]; + final List weekList = ["一", "二", "三", "四", "五", "六", "日"]; @override Widget getWeekBarItem(int index) { diff --git a/example/lib/custom_style_page.dart b/example/lib/custom_style_page.dart index 6f587ca..3aec4c9 100644 --- a/example/lib/custom_style_page.dart +++ b/example/lib/custom_style_page.dart @@ -21,6 +21,7 @@ class _CustomStylePageState extends State { @override void initState() { + super.initState(); controller = new CalendarController(); controller.addMonthChangeListener( @@ -96,7 +97,7 @@ class _CustomStylePageState extends State { } class CustomStyleWeekBarItem extends BaseWeekBar { - List weekList = ["一", "二", "三", "四", "五", "六", "日"]; + final List weekList = ["一", "二", "三", "四", "五", "六", "日"]; @override Widget getWeekBarItem(int index) { diff --git a/example/lib/default_style_page.dart b/example/lib/default_style_page.dart index 585be29..bb20ddd 100644 --- a/example/lib/default_style_page.dart +++ b/example/lib/default_style_page.dart @@ -21,12 +21,13 @@ class _DefaultStylePageState extends State { @override void initState() { + super.initState(); DateTime now = DateTime.now(); controller = new CalendarController( - minYear: now.year, - minYearMonth: now.month - 5, - maxYear: now.year, - maxYearMonth: now.month + 5, + minYear: now.year-1, + minYearMonth: 1, + maxYear: now.year+1, + maxYearMonth: 12, showMode: CalendarConstants.MODE_SHOW_MONTH_AND_WEEK); controller.addMonthChangeListener( diff --git a/example/lib/main.dart b/example/lib/main.dart index 7f579b1..3258a09 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,7 @@ import 'package:example/only_week_page.dart'; import 'package:example/red_style_page.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; + import 'blue_style_page.dart'; import 'custom_sign_page.dart'; import 'custom_style_page.dart'; @@ -114,64 +114,3 @@ class HomePage extends StatelessWidget { } } -// -//# Desktop Flutter Example -// -//This is the standard Flutter template application, modified to run on desktop. -// -//The `linux` and `windows` directories serve as early prototypes of -//what will eventually become the `flutter create` templates for desktop, and will -//be evolving over time to better reflect that goal. The `macos` directory has -//now become a `flutter create` template, so is largely identical to what that -//command creates. -// -//## Building and Running -// -//See [the main project README](../README.md). -// -//To build without running, use `flutter build macos`/`windows`/`linux` rather than `flutter run`, as with -//a standard Flutter project. -// -//## Dart Differences from Flutter Template -// -//The `main.dart` and `pubspec.yaml` have minor changes to support desktop: -//* `debugDefaultTargetPlatformOverride` is set to avoid 'Unknown platform' -//exceptions. -//* The font is explicitly set to Roboto, and Roboto is bundled via -//`pubspec.yaml`, to ensure that text displays on all platforms. -// -//See the [Flutter Application Requirements section of the Flutter page on -//desktop support](https://github.com/flutter/flutter/wiki/Desktop-shells#flutter-application-requirements) -//for more information. -// -//## Adapting for Another Project -// -//Since `flutter create` is not yet supported for Windows and Linux, the easiest -//way to try out desktop support with an existing Flutter application on those -//platforms is to copy the platform directories from this example; see below for -//details. For macOS, just run `flutter create --macos .` in your project. -// -//Be sure to read the [Flutter page on desktop -//support](https://github.com/flutter/flutter/wiki/Desktop-shells) before trying to -//run an existing project on desktop, especially the [Flutter Application Requirements -//section](https://github.com/flutter/flutter/wiki/Desktop-shells#flutter-application-requirements). -// -//### Coping the Desktop Runners -// -//The 'linux' and 'windows' directories are self-contained, and can be copied to -//an existing Flutter project, enabling `flutter run` for those platforms. -// -//**Be aware that neither the API surface of the Flutter desktop libraries nor the -//interaction between the `flutter` tool and the platform directories is stable, -//and no attempt will be made to provide supported migration paths as things -//change.** You should expect that every time you update Flutter you may have -//to delete your copies of the platform directories and re-copy them from an -//updated version of flutter-desktop-embedding. -// -//### Customizing the Runners -// -//See [Application Customization](App-Customization.md) for premilinary -//documenation on modifying basic application information like name and icon. -// -//If you are building for macOS, you should also read about [managing macOS -//security configurations](../macOS-Security.md). diff --git a/example/lib/multi_select_style_page.dart b/example/lib/multi_select_style_page.dart index dfabfb1..0fa32ed 100644 --- a/example/lib/multi_select_style_page.dart +++ b/example/lib/multi_select_style_page.dart @@ -21,6 +21,7 @@ class _MultiSelectStylePageState extends State { @override void initState() { + super.initState(); controller = new CalendarController( selectMode: CalendarConstants.MODE_MULTI_SELECT, maxMultiSelectCount: 5, @@ -102,7 +103,7 @@ class _MultiSelectStylePageState extends State { } class CustomStyleWeekBarItem extends BaseWeekBar { - List weekList = ["一", "二", "三", "四", "五", "六", "日"]; + final List weekList = ["一", "二", "三", "四", "五", "六", "日"]; @override Widget getWeekBarItem(int index) { @@ -119,7 +120,6 @@ class CustomStyleDayWidget extends BaseCustomDayWidget { @override void drawNormal(DateModel dateModel, Canvas canvas, Size size) { - bool isWeekend = dateModel.isWeekend; bool isInRange = dateModel.isInRange; //顶部的文字 diff --git a/example/lib/only_week_page.dart b/example/lib/only_week_page.dart index c9af7d3..68ec4ac 100644 --- a/example/lib/only_week_page.dart +++ b/example/lib/only_week_page.dart @@ -21,6 +21,7 @@ class _OnlyWeekPageState extends State { @override void initState() { + super.initState(); DateTime now = DateTime.now(); controller = new CalendarController( minYear: now.year, diff --git a/example/lib/progress_style_page.dart b/example/lib/progress_style_page.dart index a36bd80..f9d597e 100644 --- a/example/lib/progress_style_page.dart +++ b/example/lib/progress_style_page.dart @@ -22,6 +22,7 @@ class _ProgressStylePageState extends State { @override void initState() { + super.initState(); DateTime now = DateTime.now(); DateTime temp = DateTime(now.year, now.month, now.day); @@ -117,7 +118,7 @@ class _ProgressStylePageState extends State { } class CustomStyleWeekBarItem extends BaseWeekBar { - List weekList = ["一", "二", "三", "四", "五", "六", "日"]; + final List weekList = ["一", "二", "三", "四", "五", "六", "日"]; @override Widget getWeekBarItem(int index) { diff --git a/example/lib/red_style_page.dart b/example/lib/red_style_page.dart index a9f4501..491a17e 100644 --- a/example/lib/red_style_page.dart +++ b/example/lib/red_style_page.dart @@ -22,6 +22,8 @@ class _RedStylePageState extends State { @override void initState() { + super.initState(); + controller = new CalendarController( showMode: CalendarConstants.MODE_SHOW_MONTH_AND_WEEK, extraDataMap: customExtraData); @@ -47,6 +49,7 @@ class _RedStylePageState extends State { @override Widget build(BuildContext context) { var calendarWidget = CalendarViewWidget( + itemSize: 40, calendarController: controller, margin: EdgeInsets.only(top: 20), weekBarItemWidgetBuilder: () { @@ -64,7 +67,7 @@ class _RedStylePageState extends State { color: Colors.white, padding: EdgeInsets.symmetric(horizontal: 20), child: new Column( - crossAxisAlignment: CrossAxisAlignment.stretch, + crossAxisAlignment:CrossAxisAlignment.stretch , children: [ SizedBox( height: 20, @@ -131,7 +134,7 @@ class _RedStylePageState extends State { } class CustomStyleWeekBarItem extends BaseWeekBar { - List weekList = ["M", "T", "W", "T", "F", "S", "S"]; + final List weekList = ["M", "T", "W", "T", "F", "S", "S"]; //可以直接重写build方法 @override @@ -168,10 +171,10 @@ class CustomStyleWeekBarItem extends BaseWeekBar { class CustomStyleDayWidget extends BaseCombineDayWidget { CustomStyleDayWidget(DateModel dateModel) : super(dateModel); - TextStyle normalTextStyle = + final TextStyle normalTextStyle = TextStyle(fontWeight: FontWeight.w700, color: Colors.black); - TextStyle noIsCurrentMonthTextStyle = + final TextStyle noIsCurrentMonthTextStyle = TextStyle(fontWeight: FontWeight.w700, color: Colors.grey); @override diff --git a/lib/utils/date_util.dart b/lib/utils/date_util.dart index 6f63d71..898200f 100644 --- a/lib/utils/date_util.dart +++ b/lib/utils/date_util.dart @@ -1,6 +1,3 @@ -import 'dart:developer'; -import 'dart:math'; - import 'package:flutter_custom_calendar/model/date_model.dart'; import 'package:flutter_custom_calendar/utils/LogUtil.dart'; diff --git a/lib/widget/base_day_view.dart b/lib/widget/base_day_view.dart index 17d0808..6ff32ec 100644 --- a/lib/widget/base_day_view.dart +++ b/lib/widget/base_day_view.dart @@ -56,7 +56,7 @@ class CustomDayWidgetPainter extends CustomPainter { * 通过组合widget创建item,只需实现相关的方法就可以 */ abstract class BaseCombineDayWidget extends StatelessWidget { - DateModel dateModel; + final DateModel dateModel; BaseCombineDayWidget(this.dateModel); diff --git a/lib/widget/calendar_view.dart b/lib/widget/calendar_view.dart index d8b1871..cc73ad0 100644 --- a/lib/widget/calendar_view.dart +++ b/lib/widget/calendar_view.dart @@ -16,20 +16,20 @@ import 'package:provider/provider.dart'; //由于旧的代码关系。。所以现在需要抽出一个StatefulWidget放在StatelessWidget里面 class CalendarViewWidget extends StatefulWidget { //整体的背景设置 - BoxDecoration boxDecoration; + final BoxDecoration boxDecoration; //日历的padding和margin - EdgeInsetsGeometry padding; - EdgeInsetsGeometry margin; + final EdgeInsetsGeometry padding; + final EdgeInsetsGeometry margin; //默认是屏幕宽度/7 - double itemSize; + final double itemSize; //日历item之间的竖直方向间距,默认10 - double verticalSpacing; + final double verticalSpacing; - DayWidgetBuilder dayWidgetBuilder; - WeekBarItemWidgetBuilder weekBarItemWidgetBuilder; + final DayWidgetBuilder dayWidgetBuilder; + final WeekBarItemWidgetBuilder weekBarItemWidgetBuilder; //控制器 final CalendarController calendarController; @@ -111,6 +111,7 @@ class CalendarContainerState extends State @override void initState() { + super.initState(); calendarProvider = Provider.of(context, listen: false); expand = calendarProvider.expandStatus.value; diff --git a/lib/widget/fast_click_widget.dart b/lib/widget/fast_click_widget.dart deleted file mode 100644 index afc3f16..0000000 --- a/lib/widget/fast_click_widget.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:flutter/material.dart'; - -/** - * 防止快速点击 - */ -class FastClickWidget extends StatelessWidget { - final int between_time = 500; //默认两次点击间隔500ms内则点击无效 - - Function onTap; - Widget child; - - FastClickWidget({@required this.onTap, @required this.child}); - - int lastClickTime = 0; - - @override - Widget build(BuildContext context) { - return GestureDetector( - onTap: () { - if (lastClickTime == 0 || - DateTime.now().millisecondsSinceEpoch - lastClickTime > - between_time) { - onTap(); - lastClickTime = DateTime.now().millisecondsSinceEpoch; - } else { - //间隔500ms内点击无效 - } - }, - child: child, - ); - } -} diff --git a/lib/widget/month_view.dart b/lib/widget/month_view.dart index 9c02b49..876a029 100644 --- a/lib/widget/month_view.dart +++ b/lib/widget/month_view.dart @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_custom_calendar/cache_data.dart'; diff --git a/lib/widget/month_view_pager.dart b/lib/widget/month_view_pager.dart index 358d442..a35e24f 100644 --- a/lib/widget/month_view_pager.dart +++ b/lib/widget/month_view_pager.dart @@ -1,10 +1,8 @@ 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/month_view.dart'; import 'package:provider/provider.dart'; @@ -21,6 +19,7 @@ class _MonthViewPagerState extends State @override void initState() { + super.initState(); LogUtil.log(TAG: this.runtimeType, message: "MonthViewPager initState"); calendarProvider = Provider.of(context, listen: false); diff --git a/lib/widget/week_view.dart b/lib/widget/week_view.dart index 7542ffc..ddf910c 100644 --- a/lib/widget/week_view.dart +++ b/lib/widget/week_view.dart @@ -2,7 +2,6 @@ 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/controller.dart'; import 'package:flutter_custom_calendar/model/date_model.dart'; import 'package:flutter_custom_calendar/utils/date_util.dart'; import 'package:flutter_custom_calendar/widget/month_view.dart'; diff --git a/lib/widget/week_view_pager.dart b/lib/widget/week_view_pager.dart index ef9f06d..3a468c0 100644 --- a/lib/widget/week_view_pager.dart +++ b/lib/widget/week_view_pager.dart @@ -1,7 +1,6 @@ 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/controller.dart'; import 'package:flutter_custom_calendar/model/date_model.dart'; import 'package:flutter_custom_calendar/utils/LogUtil.dart'; import 'package:flutter_custom_calendar/widget/week_view.dart'; @@ -23,6 +22,7 @@ class _WeekViewPagerState extends State @override void initState() { + super.initState(); LogUtil.log(TAG: this.runtimeType, message: "WeekViewPager initState"); calendarProvider = Provider.of(context, listen: false); @@ -56,7 +56,8 @@ class _WeekViewPagerState extends State } LogUtil.log( TAG: this.runtimeType, - message: "WeekViewPager PageView onPageChanged:${position}"); + message: + "WeekViewPager PageView onPageChanged,position:$position"); // 周视图的变化 DateModel firstDayOfWeek = configuration.weekList[position]; int currentMonth = firstDayOfWeek.month; @@ -64,7 +65,7 @@ class _WeekViewPagerState extends State LogUtil.log( TAG: this.runtimeType, message: - "WeekViewPager PageView monthChange:currentMonth:${currentMonth}"); + "WeekViewPager PageView monthChange:currentMonth:$currentMonth"); configuration.monthChangeListeners.forEach((listener) { listener(firstDayOfWeek.year, firstDayOfWeek.month); });