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

引入provider状态管理,避免深层嵌套传递信息
develop
xiaodong 5 years ago
parent e9f98bcd99
commit d48e3101ce

@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/configuration.dart';
import 'package:flutter_custom_calendar/model/date_model.dart';
/**
* provider
*
* rebuild
*/
class CalendarProvider extends ChangeNotifier {
Set<DateModel> selectedDateList = new Set(); //,
DateModel _selectDateModel; //
DateModel get selectDateModel => _selectDateModel;
set selectDateModel(DateModel value) {
_selectDateModel = value;
print("notifyListeners:$value");
notifyListeners();
}
//
CalendarConfiguration calendarConfiguration;
void initData(
{Set<DateModel> selectedDateList,
DateModel selectDateModel,
CalendarConfiguration calendarConfiguration}) {
print("CalendarProvider init");
if (selectedDateList != null) {
this.selectedDateList.addAll(selectedDateList);
}
this.selectDateModel = selectDateModel;
this.calendarConfiguration = calendarConfiguration;
}
//退
void clearData() {
print("CalendarProvider clearData");
selectedDateList.clear();
selectDateModel = null;
}
}

@ -0,0 +1,88 @@
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/controller.dart';
import 'package:flutter_custom_calendar/model/date_model.dart';
/**
*
*/
class CalendarConfiguration {
//,MODE_SINGLE_SELECTMODE_MULTI_SELECT
int selectMode;
//
bool expandStatus;
//
int minYear;
int maxYear;
//
int minYearMonth;
int maxYearMonth;
//
int nowYear;
int nowMonth;
//,
int minSelectYear;
int minSelectMonth;
int minSelectDay;
int maxSelectYear;
int maxSelectMonth;
int maxSelectDay; //
Set<DateModel> defaultSelectedDateList = new Set(); //
int maxMultiSelectCount; //
Map<DateTime, Object> extraDataMap = new Map(); //
/**
* UI
*/
//
OnMonthChange monthChange; //
OnCalendarSelect calendarSelect; //
OnMultiSelectOutOfRange multiSelectOutOfRange; //
OnMultiSelectOutOfSize multiSelectOutOfSize; //
//
DayWidgetBuilder dayWidgetBuilder; //item
WeekBarItemWidgetBuilder weekBarItemWidgetBuilder; //weekbar
/**
*
*/
List<DateModel> monthList = new List(); //list
List<DateModel> weekList = new List(); //list
PageController pageController; //controller
PageController weekController; //controller
CalendarConfiguration(
{this.selectMode,
this.expandStatus,
this.minYear,
this.maxYear,
this.minYearMonth,
this.maxYearMonth,
this.nowYear,
this.nowMonth,
this.minSelectYear,
this.minSelectMonth,
this.minSelectDay,
this.maxSelectYear,
this.maxSelectMonth,
this.maxSelectDay,
this.defaultSelectedDateList,
this.maxMultiSelectCount,
this.extraDataMap,
this.monthList,
this.weekList,
this.pageController,
this.weekController});
@override
String toString() {
return 'CalendarConfiguration{selectMode: $selectMode, expandStatus: $expandStatus, minYear: $minYear, maxYear: $maxYear, minYearMonth: $minYearMonth, maxYearMonth: $maxYearMonth, nowYear: $nowYear, nowMonth: $nowMonth, minSelectYear: $minSelectYear, minSelectMonth: $minSelectMonth, minSelectDay: $minSelectDay, maxSelectYear: $maxSelectYear, maxSelectMonth: $maxSelectMonth, maxSelectDay: $maxSelectDay, defaultSelectedDateList: $defaultSelectedDateList, maxMultiSelectCount: $maxMultiSelectCount, extraDataMap: $extraDataMap, monthList: $monthList, weekList: $weekList, pageController: $pageController, weekController: $weekController}';
}
}

@ -1,9 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/CalendarProvider.dart';
import 'package:flutter_custom_calendar/configuration.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
@ -13,55 +17,19 @@ class CalendarController {
static const Set<DateTime> EMPTY_SET = {};
static const Map<DateTime, Object> EMPTY_MAP = {};
//,MODE_SINGLE_SELECTMODE_MULTI_SELECT
int selectMode;
CalendarConfiguration calendarConfiguration;
//
bool expandStatus;
ValueNotifier<bool> expandChanged;
//
int minYear;
int maxYear;
//
int minYearMonth;
int maxYearMonth;
//
int nowYear;
int nowMonth;
//,
int minSelectYear;
int minSelectMonth;
int minSelectDay;
int maxSelectYear;
int maxSelectMonth;
int maxSelectDay; //
Set<DateModel> selectedDateList = new Set(); //,
DateModel selectDateModel; //,
int maxMultiSelectCount; //
Map<DateTime, Object> extraDataMap = new Map(); //
//
OnMonthChange monthChange; //
OnCalendarSelect calendarSelect; //
OnMultiSelectOutOfRange multiSelectOutOfRange; //
OnMultiSelectOutOfSize multiSelectOutOfSize; //
//
DayWidgetBuilder dayWidgetBuilder; //item
WeekBarItemWidgetBuilder weekBarItemWidgetBuilder; //weekbar
CalendarProvider calendarProvider = CalendarProvider();
/**
*
*/
List<DateModel> monthList = new List(); //list
List<DateModel> weekList=new List();//list
PageController pageController;
List<DateModel> weekList = new List(); //list
PageController pageController; //controller
PageController weekController; //controller
ValueNotifier<bool> expandChanged; //
CalendarController(
{int selectMode = Constants.MODE_SINGLE_SELECT,
@ -84,32 +52,31 @@ class CalendarController {
DateModel selectDateModel,
int maxMultiSelectCount = 9999,
Map<DateTime, Object> extraDataMap = EMPTY_MAP}) {
this.selectMode = selectMode;
this.minYear = minYear;
this.maxYear = maxYear;
this.minYearMonth = minYearMonth;
this.maxYearMonth = maxYearMonth;
this.nowYear = nowYear;
this.nowMonth = nowMonth;
this.minSelectYear = minSelectYear;
this.minSelectMonth = minSelectMonth;
this.minSelectDay = minSelectDay;
this.maxSelectYear = maxSelectYear;
this.maxSelectMonth = maxSelectMonth;
this.maxSelectDay = maxSelectDay;
this.selectDateModel = selectDateModel;
this.dayWidgetBuilder = dayWidgetBuilder;
this.weekBarItemWidgetBuilder = weekBarItemWidgetBuilder;
this.maxMultiSelectCount = maxMultiSelectCount;
this.extraDataMap = extraDataMap;
this.expandStatus = expandStatus;
this.expandChanged=ValueNotifier(expandStatus);
this.selectedDateList = Set();
this.expandChanged = ValueNotifier(expandStatus);
calendarConfiguration = CalendarConfiguration(
selectMode: selectMode,
minYear: minYear,
maxYear: maxYear,
maxYearMonth: maxYearMonth,
nowYear: nowYear,
nowMonth: nowMonth,
minSelectYear: minSelectYear,
minSelectMonth: minSelectMonth,
minYearMonth: minYearMonth,
minSelectDay: minSelectDay,
maxSelectYear: maxSelectYear,
maxSelectMonth: maxSelectMonth,
maxSelectDay: maxSelectDay);
calendarConfiguration.dayWidgetBuilder = dayWidgetBuilder;
calendarConfiguration.weekBarItemWidgetBuilder = weekBarItemWidgetBuilder;
if (selectedDateTimeList != null && selectedDateTimeList.isNotEmpty) {
this.selectedDateList.addAll(selectedDateTimeList.map((dateTime) {
return DateModel.fromDateTime(dateTime);
}).toSet());
calendarConfiguration.defaultSelectedDateList
.addAll(selectedDateTimeList.map((dateTime) {
return DateModel.fromDateTime(dateTime);
}).toSet());
}
//pageController,initialPage
@ -141,26 +108,56 @@ class CalendarController {
}
}
this.pageController = new PageController(initialPage: initialPage);
//
///72
int initialWeekPage;
int nowWeekIndex = 0;
weekList.clear();
int sumDays = 0; //
DateTime firstDayOfMonth = DateTime(minYear, minYearMonth, 1);
//
DateTime firstWeekDate =
firstDayOfMonth.add(Duration(days: -(firstDayOfMonth.weekday - 1)));
print("第一个星期的第一天的日期firstWeekDate:$firstWeekDate");
DateTime lastDay = DateTime(maxYear, maxYearMonth,
DateUtil.getMonthDaysCount(maxYear, maxYearMonth));
print("最后一天:$lastDay");
for (DateTime dateTime = firstWeekDate;
dateTime.isBefore(lastDay);
dateTime = dateTime.add(Duration(days: 7))) {
DateModel dateModel = DateModel.fromDateTime(dateTime);
weekList.add(dateModel);
}
this.weekController = new PageController();
calendarConfiguration.monthList = monthList;
calendarConfiguration.weekList = weekList;
calendarConfiguration.pageController = pageController;
calendarConfiguration.weekController = weekController;
calendarConfiguration.dayWidgetBuilder = dayWidgetBuilder;
calendarConfiguration.weekBarItemWidgetBuilder = weekBarItemWidgetBuilder;
}
//
void addMonthChangeListener(OnMonthChange listener) {
this.monthChange = listener;
this.calendarConfiguration.monthChange = listener;
}
//
void addOnCalendarSelectListener(OnCalendarSelect listener) {
this.calendarSelect = listener;
this.calendarConfiguration.calendarSelect = listener;
}
//
void addOnMultiSelectOutOfRangeListener(OnMultiSelectOutOfRange listener) {
this.multiSelectOutOfRange = listener;
this.calendarConfiguration.multiSelectOutOfRange = listener;
}
//
void addOnMultiSelectOutOfSizeListener(OnMultiSelectOutOfSize listener) {
this.multiSelectOutOfSize = listener;
this.calendarConfiguration.multiSelectOutOfSize = listener;
}
//
@ -237,30 +234,21 @@ class CalendarController {
//,
Set<DateModel> getMultiSelectCalendar() {
if (selectedDateList.isEmpty) {
return null;
}
return selectedDateList;
return calendarProvider.selectedDateList;
}
//
DateModel getSingleSelectCalendar() {
if (selectDateModel == null) {
return null;
}
return selectDateModel;
return calendarProvider.selectDateModel;
}
//
void toggleExpandStatus(){
expandChanged.value=!expandChanged.value;
void toggleExpandStatus() {
expandChanged.value = !expandChanged.value;
print("toggleExpandStatus${expandChanged.value}");
}
void addExpandChangeListener(){
}
void addExpandChangeListener() {}
}
/**

@ -14,6 +14,16 @@ class DateUtil {
dateTime.weekday == DateTime.sunday;
}
/**
*
*/
static int getYearDaysCount(int year) {
if (isLeapYear(year)) {
return 366;
}
return 365;
}
/**
*
*

@ -1,13 +1,19 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_custom_calendar/CalendarProvider.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/widget/month_view_pager.dart';
import 'package:flutter_custom_calendar/widget/week_view_pager.dart';
import 'package:provider/provider.dart';
/**
*
*/
//StatefulWidgetStatelessWidget
class CalendarViewWidget extends StatefulWidget {
//
BoxDecoration boxDecoration;
@ -15,125 +21,155 @@ class CalendarViewWidget extends StatefulWidget {
//
CalendarController calendarController;
CalendarViewWidget({@required this.calendarController, this.boxDecoration});
CalendarViewWidget(
{Key key, @required this.calendarController, this.boxDecoration})
: super(key: key);
@override
_CalendarViewWidgetState createState() => _CalendarViewWidgetState();
}
class _CalendarViewWidgetState extends State<CalendarViewWidget>
class _CalendarViewWidgetState extends State<CalendarViewWidget> {
@override
void initState() {
widget.calendarController.calendarProvider.initData(
calendarConfiguration: widget.calendarController.calendarConfiguration);
super.initState();
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<CalendarProvider>.value(
value: widget.calendarController.calendarProvider,
child: Container(
//
decoration: widget.boxDecoration,
child: const CalendarContainer()),
);
}
}
class CalendarContainer extends StatefulWidget {
const CalendarContainer();
@override
CalendarContainerState createState() => CalendarContainerState();
}
class CalendarContainerState extends State<CalendarContainer>
with SingleTickerProviderStateMixin {
double itemHeight;
double totalHeight;
bool expand = true;
AnimationController _animationController;
@override
void initState() {
_animationController =
AnimationController(duration: Duration(milliseconds: 200), vsync: this);
// widget.calendarController.expandChanged.addListener(() {
// print("_CalendarViewWidgetState:$expand");
// setState(() {
// expand = !expand;
// });
// });
//
}
widget.calendarController.expandChanged.addListener(() {
print("_CalendarViewWidgetState:$expand");
setState(() {
expand = !expand;
});
});
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
print("CalendarContainerState build");
//,,:a horizontal viewport was given an unlimited amount of I/flutter ( 6759): vertical space in which to expand.
itemHeight = MediaQuery.of(context).size.width / 7;
totalHeight = itemHeight * 6 + 10 * (6 - 1);
return Container(
//
decoration: widget.boxDecoration,
child: new Column(
children: <Widget>[
/**
* constsetStateview
*/
widget.calendarController.weekBarItemWidgetBuilder(),
// widget.calendarController.weekBarItemWidgetBuilder(),
AnimatedContainer(
duration: Duration(milliseconds: 500),
height: expand ? totalHeight : itemHeight,
child: expand
? Container(
height: totalHeight,
child: MonthViewPager(
selectMode: widget.calendarController.selectMode,
monthChange: (int year, int month) {
widget.calendarController.monthChange(year, month);
},
calendarSelect: (dateModel) {
widget.calendarController.selectDateModel = dateModel;
widget.calendarController.calendarSelect(dateModel);
},
monthList: widget.calendarController.monthList,
pageController: widget.calendarController.pageController,
selectedDateList:
widget.calendarController.selectedDateList,
selectDateModel:
widget.calendarController.selectDateModel,
dayWidgetBuilder:
widget.calendarController.dayWidgetBuilder,
minSelectDate: DateModel()
..year = widget.calendarController.minSelectYear
..month = widget.calendarController.minSelectMonth
..day = widget.calendarController.minSelectDay,
maxSelectDate: DateModel()
..year = widget.calendarController.maxSelectYear
..month = widget.calendarController.maxSelectMonth
..day = widget.calendarController.maxSelectDay,
maxMultiSelectCount:
widget.calendarController.maxMultiSelectCount,
multiSelectOutOfRange:
widget.calendarController.multiSelectOutOfRange,
multiSelectOutOfSize:
widget.calendarController.multiSelectOutOfSize,
extraDataMap: widget.calendarController.extraDataMap,
),
)
: Container(
height: itemHeight,
child: WeekViewPager(
selectMode: widget.calendarController.selectMode,
monthChange: (int year, int month) {
widget.calendarController.monthChange(year, month);
},
calendarSelect: (dateModel) {
widget.calendarController.selectDateModel = dateModel;
widget.calendarController.calendarSelect(dateModel);
},
weekList: widget.calendarController.weekList,
pageController: widget.calendarController.pageController,
selectedDateList:
widget.calendarController.selectedDateList,
selectDateModel:
widget.calendarController.selectDateModel,
dayWidgetBuilder:
widget.calendarController.dayWidgetBuilder,
minSelectDate: DateModel()
..year = widget.calendarController.minSelectYear
..month = widget.calendarController.minSelectMonth
..day = widget.calendarController.minSelectDay,
maxSelectDate: DateModel()
..year = widget.calendarController.maxSelectYear
..month = widget.calendarController.maxSelectMonth
..day = widget.calendarController.maxSelectDay,
maxMultiSelectCount:
widget.calendarController.maxMultiSelectCount,
multiSelectOutOfRange:
widget.calendarController.multiSelectOutOfRange,
multiSelectOutOfSize:
widget.calendarController.multiSelectOutOfSize,
extraDataMap: widget.calendarController.extraDataMap,
duration: Duration(milliseconds: 500),
height: expand ? totalHeight : itemHeight,
child:
// expand ?
Container(
height: totalHeight,
child: MonthViewPager(
// selectMode: widget.calendarController.selectMode,
// monthChange: (int year, int month) {
// widget.calendarController.monthChange(year, month);
// },
// calendarSelect: (dateModel) {
// widget.calendarController.selectDateModel = dateModel;
// widget.calendarController.calendarSelect(dateModel);
// },
// monthList: widget.calendarController.monthList,
// pageController: widget.calendarController.pageController,
// selectedDateList:
// widget.calendarController.selectedDateList,
// selectDateModel:
// widget.calendarController.selectDateModel,
// dayWidgetBuilder:
// widget.calendarController.dayWidgetBuilder,
// minSelectDate: DateModel()
// ..year = widget.calendarController.minSelectYear
// ..month = widget.calendarController.minSelectMonth
// ..day = widget.calendarController.minSelectDay,
// maxSelectDate: DateModel()
// ..year = widget.calendarController.maxSelectYear
// ..month = widget.calendarController.maxSelectMonth
// ..day = widget.calendarController.maxSelectDay,
// maxMultiSelectCount:
// widget.calendarController.maxMultiSelectCount,
// multiSelectOutOfRange:
// widget.calendarController.multiSelectOutOfRange,
// multiSelectOutOfSize:
// widget.calendarController.multiSelectOutOfSize,
// extraDataMap: widget.calendarController.extraDataMap,
),
),
),
)
// : Container(
// height: itemHeight,
// child: WeekViewPager(
// selectMode: widget.calendarController.selectMode,
// monthChange: (int year, int month) {
// widget.calendarController.monthChange(year, month);
// },
// calendarSelect: (dateModel) {
// widget.calendarController.selectDateModel = dateModel;
// widget.calendarController.calendarSelect(dateModel);
// },
// weekList: widget.calendarController.weekList,
// pageController: widget.calendarController.pageController,
// selectedDateList:
// widget.calendarController.selectedDateList,
// selectDateModel:
// widget.calendarController.selectDateModel,
// dayWidgetBuilder:
// widget.calendarController.dayWidgetBuilder,
// minSelectDate: DateModel()
// ..year = widget.calendarController.minSelectYear
// ..month = widget.calendarController.minSelectMonth
// ..day = widget.calendarController.minSelectDay,
// maxSelectDate: DateModel()
// ..year = widget.calendarController.maxSelectYear
// ..month = widget.calendarController.maxSelectMonth
// ..day = widget.calendarController.maxSelectDay,
// maxMultiSelectCount:
// widget.calendarController.maxMultiSelectCount,
// multiSelectOutOfRange:
// widget.calendarController.multiSelectOutOfRange,
// multiSelectOutOfSize:
// widget.calendarController.multiSelectOutOfSize,
// extraDataMap: widget.calendarController.extraDataMap,
// ),
// ),
),
],
),
);

@ -1,23 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/CalendarProvider.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:provider/provider.dart';
/**
*
*/
class MonthView extends StatefulWidget {
OnCalendarSelect onCalendarSelectListener;
// OnCalendarSelect onCalendarSelectListener;
Set<DateModel> selectedDateList; //
DateModel selectDateModel; //,
DayWidgetBuilder dayWidgetBuilder;
OnMultiSelectOutOfRange multiSelectOutOfRange; //
OnMultiSelectOutOfSize multiSelectOutOfSize; //
// Set<DateModel> selectedDateList; //
//
// DateModel selectDateModel; //,
//
// DayWidgetBuilder dayWidgetBuilder;
//
// OnMultiSelectOutOfRange multiSelectOutOfRange; //
// OnMultiSelectOutOfSize multiSelectOutOfSize; //
int year;
int month;
@ -26,26 +28,15 @@ class MonthView extends StatefulWidget {
DateModel minSelectDate;
DateModel maxSelectDate;
int selectMode;
int maxMultiSelectCount;
Map<DateTime, Object> extraDataMap; //
MonthView(
{@required this.year,
@required this.month,
this.day,
this.onCalendarSelectListener,
this.dayWidgetBuilder,
this.selectedDateList,
this.selectDateModel,
this.minSelectDate,
this.maxSelectDate,
this.selectMode,
this.multiSelectOutOfSize,
this.multiSelectOutOfRange,
this.maxMultiSelectCount,
this.extraDataMap});
MonthView({
@required this.year,
@required this.month,
this.day,
this.minSelectDate,
this.maxSelectDate,
});
@override
_MonthViewState createState() => _MonthViewState();
@ -60,27 +51,17 @@ class _MonthViewState extends State<MonthView> {
double totalHeight;
double mainSpacing = 10;
int year;
int month;
DateModel selectDateModel; //,
@override
void initState() {
super.initState();
year = widget.year;
month = widget.month;
items = DateUtil.initCalendarForMonthView(
year, month, DateTime.now(), DateTime.sunday,
widget.year, widget.month, DateTime.now(), DateTime.sunday,
minSelectDate: widget.minSelectDate,
maxSelectDate: widget.maxSelectDate,
extraDataMap: widget.extraDataMap);
lineCount = DateUtil.getMonthViewLineCount(year, month);
selectDateModel = widget.selectDateModel;
lineCount = DateUtil.getMonthViewLineCount(widget.year, widget.month);
}
@override
@ -96,67 +77,72 @@ class _MonthViewState extends State<MonthView> {
}
Widget getView() {
return new GridView.builder(
physics: NeverScrollableScrollPhysics(),
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 7, mainAxisSpacing: 10),
itemCount: 7 * lineCount,
itemBuilder: (context, index) {
DateModel dateModel = items[index];
//
if (widget.selectMode == Constants.MODE_MULTI_SELECT) {
if (widget.selectedDateList.contains(dateModel)) {
dateModel.isSelected = true;
} else {
dateModel.isSelected = false;
}
} else {
if (selectDateModel == dateModel) {
dateModel.isSelected = true;
return Consumer<CalendarProvider>(
builder: (context, calendarProvider, child) {
CalendarConfiguration configuration =
calendarProvider.calendarConfiguration;
print(
"Consumer:calendarProvider.selectDateModel:${calendarProvider.selectDateModel}");
return new GridView.builder(
physics: NeverScrollableScrollPhysics(),
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 7, mainAxisSpacing: 10),
itemCount: 7 * lineCount,
itemBuilder: (context, index) {
DateModel dateModel = items[index];
//
if (configuration.selectMode == Constants.MODE_MULTI_SELECT) {
if (calendarProvider.selectedDateList.contains(dateModel)) {
dateModel.isSelected = true;
} else {
dateModel.isSelected = false;
}
} else {
dateModel.isSelected = false;
}
}
return GestureDetector(
onTap: () {
//
if (!dateModel.isInRange) {
//
if (widget.selectMode == Constants.MODE_MULTI_SELECT) {
widget.multiSelectOutOfRange();
}
return;
if (calendarProvider.selectDateModel == dateModel) {
dateModel.isSelected = true;
} else {
dateModel.isSelected = false;
}
}
if (widget.selectMode == Constants.MODE_MULTI_SELECT) {
//
if (widget.selectedDateList.length ==
widget.maxMultiSelectCount) {
widget.multiSelectOutOfSize();
return GestureDetector(
onTap: () {
print("GestureDetector onTap$dateModel");
//
if (!dateModel.isInRange) {
//
if (configuration.selectMode == Constants.MODE_MULTI_SELECT) {
configuration.multiSelectOutOfRange();
}
return;
}
//
selectDateModel = dateModel;
widget.selectDateModel = dateModel;
widget.onCalendarSelectListener(dateModel);
setState(() {
if (widget.selectedDateList.contains(dateModel)) {
widget.selectedDateList.remove(dateModel);
} else {
widget.selectedDateList.add(dateModel);
if (configuration.selectMode == Constants.MODE_MULTI_SELECT) {
//
if (calendarProvider.selectedDateList.length ==
configuration.maxMultiSelectCount) {
configuration.multiSelectOutOfSize();
return;
}
});
} else {
selectDateModel = dateModel;
widget.selectDateModel = dateModel;
widget.onCalendarSelectListener(dateModel);
setState(() {});
}
},
child: widget.dayWidgetBuilder(dateModel),
);
});
//
calendarProvider.selectDateModel = dateModel;
configuration.calendarSelect(dateModel);
setState(() {
if (calendarProvider.selectedDateList.contains(dateModel)) {
calendarProvider.selectedDateList.remove(dateModel);
} else {
calendarProvider.selectedDateList.add(dateModel);
}
});
} else {
calendarProvider.selectDateModel = dateModel;
configuration.calendarSelect(dateModel);
}
},
child: configuration.dayWidgetBuilder(dateModel),
);
});
});
}
}

@ -1,44 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/controller.dart';
import 'package:flutter_custom_calendar/CalendarProvider.dart';
import 'package:flutter_custom_calendar/configuration.dart';
import 'package:flutter_custom_calendar/model/date_model.dart';
import 'package:flutter_custom_calendar/widget/month_view.dart';
import 'package:provider/provider.dart';
class MonthViewPager extends StatefulWidget {
final OnMonthChange monthChange;
final OnCalendarSelect calendarSelect;
final DayWidgetBuilder dayWidgetBuilder;
OnMultiSelectOutOfRange multiSelectOutOfRange; //
OnMultiSelectOutOfSize multiSelectOutOfSize; //
Set<DateModel> selectedDateList; //,
DateModel selectDateModel; //,
final List<DateModel> monthList;
PageController pageController;
DateModel minSelectDate;
DateModel maxSelectDate;
int selectMode;
int maxMultiSelectCount;
Map<DateTime, Object> extraDataMap ; //
MonthViewPager(
{this.monthChange,
this.calendarSelect,
this.monthList,
this.pageController,
this.selectedDateList,
this.selectDateModel,
this.dayWidgetBuilder,
this.minSelectDate,
this.maxSelectDate,
this.selectMode,
this.maxMultiSelectCount,
this.multiSelectOutOfRange,
this.multiSelectOutOfSize,
this.extraDataMap});
MonthViewPager();
@override
_MonthViewPagerState createState() => _MonthViewPagerState();
@ -50,47 +18,46 @@ class _MonthViewPagerState extends State<MonthViewPager> {
@override
Widget build(BuildContext context) {
// CalendarProvider,listenfalse
CalendarProvider calendarProvider =
Provider.of<CalendarProvider>(context, listen: false);
CalendarConfiguration configuration =
calendarProvider.calendarConfiguration;
return Container(
child: PageView.builder(
onPageChanged: (position) {
//
DateModel dateModel = widget.monthList[position];
widget.monthChange(dateModel.year, dateModel.month);
DateModel dateModel = configuration.monthList[position];
configuration.monthChange(dateModel.year, dateModel.month);
},
controller: widget.pageController,
controller: configuration.pageController,
itemBuilder: (context, index) {
DateModel dateModel = widget.monthList[index];
DateModel dateModel = configuration.monthList[index];
return new MonthView(
selectMode: widget.selectMode,
// selectMode: configuration.selectMode,
year: dateModel.year,
month: dateModel.month,
selectDateModel: widget.selectDateModel,
selectedDateList: widget.selectedDateList,
onCalendarSelectListener: widget.calendarSelect,
dayWidgetBuilder: widget.dayWidgetBuilder,
minSelectDate: widget.minSelectDate,
maxSelectDate: widget.maxSelectDate,
maxMultiSelectCount: widget.maxMultiSelectCount,
multiSelectOutOfRange: widget.multiSelectOutOfRange,
multiSelectOutOfSize: widget.multiSelectOutOfSize,
extraDataMap: widget.extraDataMap,
// selectDateModel: calendarProvider.selectDateModel,
// selectedDateList: calendarProvider.selectedDateList,
// onCalendarSelectListener: configuration.calendarSelect,
// dayWidgetBuilder: configuration.dayWidgetBuilder,
minSelectDate: DateModel.fromDateTime(DateTime(
configuration.minSelectYear,
configuration.minSelectMonth,
configuration.minSelectDay)),
maxSelectDate: DateModel.fromDateTime(DateTime(
configuration.maxSelectYear,
configuration.maxSelectMonth,
configuration.maxSelectDay)),
// maxMultiSelectCount: configuration.maxMultiSelectCount,
// multiSelectOutOfRange: configuration.multiSelectOutOfRange,
// multiSelectOutOfSize: configuration.multiSelectOutOfSize,
// extraDataMap: configuration.extraDataMap,
);
},
itemCount: widget.monthList.length,
itemCount: configuration.monthList.length,
),
);
// return SliverFillViewport(
// delegate: SliverChildBuilderDelegate((context, index) {
// DateModel dateModel = widget.monthList[index];
// return new MonthView(
// year: dateModel.year,
// month: dateModel.month,
// selectDateModel: widget.selectDateModel,
// selectedDateList: widget.selectedDateList,
// onCalendarSelectListener: widget.calendarSelect,
// );
// }, childCount: widget.monthList.length),
// );
}
}

Loading…
Cancel
Save