创建configuration类,将配置的信息放到这里

引入provider状态管理,避免深层嵌套传递信息
周视图和月视图,联动
增加日志输出类LogUtil,方便查看调试
增加example例子
性能优化
develop
xiaodong 5 years ago
parent 6d9d752d16
commit d0da3b9e90

@ -315,3 +315,4 @@ bool operator ==(Object other)|重写==方法可以判断两个dateModel是
* 优化代码实现
* 继续写几个不同风格的Demo
* 支持手势操作
* 实现高度自适应

@ -10,6 +10,7 @@ import 'progress_style_page.dart';
void main() {
// debugProfileBuildsEnabled=true;
// debugProfilePaintsEnabled=true;
// debugPrintRebuildDirtyWidgets=true;
runApp(MyApp());
}

@ -13,12 +13,23 @@ import 'package:flutter_custom_calendar/widget/month_view.dart';
* rebuild
*/
class CalendarProvider extends ChangeNotifier {
double _totalHeight; //
Set<DateModel> selectedDateList = new Set(); //,
DateModel _selectDateModel; //
ItemContainerState lastClickItemState;
DateModel _lastClickDateModel;
double get totalHeight => _totalHeight;
set totalHeight(double value) {
_totalHeight = value;
}
changeTotalHeight(double value) {
_totalHeight = value;
notifyListeners();
}
DateModel get lastClickDateModel =>
_lastClickDateModel; //

@ -158,8 +158,8 @@ class CalendarController {
dateTime = dateTime.add(Duration(days: 7))) {
DateModel dateModel = DateModel.fromDateTime(dateTime);
weekList.add(dateModel);
print("nowTime.isBefore(dateTime)");
print("$nowTime,,,,$dateTime");
// print("nowTime.isBefore(dateTime)");
// print("$nowTime,,,,$dateTime");
if (nowTime.isAfter(dateTime)) {
temp++;
@ -230,7 +230,7 @@ class CalendarController {
calendarProvider.calendarConfiguration.monthController
.previousPage(duration: DEFAULT_DURATION, curve: Curves.ease);
calendarProvider.calendarConfiguration.monthChange(
monthList[currentIndex].year, monthList[currentIndex].month);
monthList[currentIndex-1].year, monthList[currentIndex-1].month);
DateModel temp = new DateModel();
temp.year = monthList[currentIndex].year;
temp.month = monthList[currentIndex].month;
@ -268,7 +268,7 @@ class CalendarController {
calendarProvider.calendarConfiguration.monthController
.nextPage(duration: DEFAULT_DURATION, curve: Curves.ease);
calendarProvider.calendarConfiguration.monthChange(
monthList[currentIndex].year, monthList[currentIndex].month);
monthList[currentIndex+1].year, monthList[currentIndex+1].month);
DateModel temp = new DateModel();
temp.year = monthList[currentIndex].year;
temp.month = monthList[currentIndex].month;

@ -124,27 +124,36 @@ class CalendarContainerState extends State<CalendarContainer>
});
}
widget.calendarController.addMonthChangeListener((year, month) {
if (widget.calendarController.calendarProvider.calendarConfiguration
.showMode !=
Constants.MODE_SHOW_ONLY_WEEK) {
//setState使
int lineCount = DateUtil.getMonthViewLineCount(year, month);
double newHeight = itemHeight * lineCount +
calendarProvider.calendarConfiguration.verticalSpacing *
(lineCount - 1);
if (totalHeight.toInt() != newHeight.toInt()) {
LogUtil.log(
TAG: this.runtimeType,
message: "totalHeight:$totalHeight,newHeight:$newHeight");
LogUtil.log(TAG: this.runtimeType, message: "月份视图高度发生变化");
setState(() {
totalHeight = newHeight;
});
}
// widget.calendarController.addMonthChangeListener((year, month) {
// if (widget.calendarController.calendarProvider.calendarConfiguration
// .showMode !=
// Constants.MODE_SHOW_ONLY_WEEK) {
// //setState使
// int lineCount = DateUtil.getMonthViewLineCount(year, month);
// double newHeight = itemHeight * lineCount +
// calendarProvider.calendarConfiguration.verticalSpacing *
// (lineCount - 1);
// if (totalHeight.toInt() != newHeight.toInt()) {
// LogUtil.log(
// TAG: this.runtimeType,
// message: "totalHeight:$totalHeight,newHeight:$newHeight");
//
// LogUtil.log(TAG: this.runtimeType, message: "月份视图高度发生变化");
// setState(() {
// totalHeight = newHeight;
// });
// }
// }
// });
//,,:a horizontal viewport was given an unlimited amount of I/flutter ( 6759): vertical space in which to expand.
itemHeight = calendarProvider.calendarConfiguration.itemSize ??
MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.width /
7;
if (calendarProvider.totalHeight == null) {
calendarProvider.totalHeight = itemHeight * 6 +
calendarProvider.calendarConfiguration.verticalSpacing * (6 - 1);
}
});
}
@override

@ -1,6 +1,7 @@
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';
@ -17,10 +18,6 @@ class MonthViewPager extends StatefulWidget {
class _MonthViewPagerState extends State<MonthViewPager> {
CalendarProvider calendarProvider;
var totalHeight;
// PageController newPageController;
@override
void initState() {
LogUtil.log(TAG: this.runtimeType, message: "MonthViewPager initState");
@ -84,19 +81,22 @@ class _MonthViewPagerState extends State<MonthViewPager> {
}
//使PageView
// double itemHeight = MediaQuery.of(context).size.width / 7;
//
// int lineCount =
// DateUtil.getMonthViewLineCount(dateModel.year, dateModel.month);
// double newHeight = itemHeight * lineCount +
// configuration.verticalSpacing * (lineCount - 1);
// if(totalHeight!=newHeight){
// totalHeight=newHeight;
// setState(() {
//
// });
// }
if (calendarProvider.calendarConfiguration.showMode !=
Constants.MODE_SHOW_ONLY_WEEK) {
//setState使
int lineCount =
DateUtil.getMonthViewLineCount(dateModel.year, dateModel.month);
double newHeight = (calendarProvider.calendarConfiguration.itemSize ??
MediaQuery.of(context).size.width / 7) *
lineCount +
calendarProvider.calendarConfiguration.verticalSpacing *
(lineCount - 1);
if (calendarProvider.totalHeight.toInt() != newHeight.toInt()) {
LogUtil.log(TAG: this.runtimeType, message: "月份视图高度发生变化");
calendarProvider.totalHeight = newHeight;
// calendarProvider.changeTotalHeight(newHeight);
}
}
},
controller: configuration.monthController,
itemBuilder: (context, index) {

Loading…
Cancel
Save