支持显示月视图和周视图的情况,优先显示周视图,MODE_SHOW_WEEK_AND_MONTH

develop^2
LXD312569496 5 years ago committed by xiaodong
parent 083abc01ca
commit 389ce46a29

@ -110,7 +110,8 @@ class CalendarProvider extends ChangeNotifier {
? selectDateModel ? selectDateModel
: DateModel.fromDateTime(DateTime.now()) : DateModel.fromDateTime(DateTime.now())
..day = 15; ..day = 15;
if (calendarConfiguration.showMode == Constants.MODE_SHOW_ONLY_WEEK) { if (calendarConfiguration.showMode == Constants.MODE_SHOW_ONLY_WEEK ||
calendarConfiguration.showMode == Constants.MODE_SHOW_WEEK_AND_MONTH) {
expandStatus = ValueNotifier(false); expandStatus = ValueNotifier(false);
} else { } else {
expandStatus = ValueNotifier(true); expandStatus = ValueNotifier(true);

@ -7,7 +7,8 @@ class Constants {
// //
static const int MODE_SHOW_ONLY_MONTH=1;// static const int MODE_SHOW_ONLY_MONTH=1;//
static const int MODE_SHOW_ONLY_WEEK=2;// static const int MODE_SHOW_ONLY_WEEK=2;//
static const int MODE_SHOW_WEEK_AND_MONTH=3;// static const int MODE_SHOW_WEEK_AND_MONTH=3;//
static const int MODE_SHOW_MONTH_AND_WEEK=4;//
/** /**

@ -93,8 +93,7 @@ class CalendarController {
maxYearMonth, maxYearMonth,
))}"); ))}");
if (showMode == Constants.MODE_SHOW_ONLY_MONTH || if (showMode != Constants.MODE_SHOW_ONLY_WEEK) {
showMode == Constants.MODE_SHOW_WEEK_AND_MONTH) {
//pageController,initialPage //pageController,initialPage
int initialPage = 0; int initialPage = 0;
int nowMonthIndex = 0; int nowMonthIndex = 0;
@ -132,8 +131,7 @@ class CalendarController {
"初始化月份视图的信息:一共有${monthList.length}个月initialPage为${nowMonthIndex}"); "初始化月份视图的信息:一共有${monthList.length}个月initialPage为${nowMonthIndex}");
} }
if (showMode == Constants.MODE_SHOW_ONLY_WEEK || if (showMode != Constants.MODE_SHOW_ONLY_MONTH) {
showMode == Constants.MODE_SHOW_WEEK_AND_MONTH) {
// //
///72 ///72
int initialWeekPage = 0; int initialWeekPage = 0;
@ -230,7 +228,8 @@ class CalendarController {
calendarProvider.calendarConfiguration.monthController calendarProvider.calendarConfiguration.monthController
.previousPage(duration: DEFAULT_DURATION, curve: Curves.ease); .previousPage(duration: DEFAULT_DURATION, curve: Curves.ease);
calendarProvider.calendarConfiguration.monthChange( calendarProvider.calendarConfiguration.monthChange(
monthList[currentIndex-1].year, monthList[currentIndex-1].month); monthList[currentIndex - 1].year,
monthList[currentIndex - 1].month);
DateModel temp = new DateModel(); DateModel temp = new DateModel();
temp.year = monthList[currentIndex].year; temp.year = monthList[currentIndex].year;
temp.month = monthList[currentIndex].month; temp.month = monthList[currentIndex].month;
@ -268,7 +267,8 @@ class CalendarController {
calendarProvider.calendarConfiguration.monthController calendarProvider.calendarConfiguration.monthController
.nextPage(duration: DEFAULT_DURATION, curve: Curves.ease); .nextPage(duration: DEFAULT_DURATION, curve: Curves.ease);
calendarProvider.calendarConfiguration.monthChange( calendarProvider.calendarConfiguration.monthChange(
monthList[currentIndex+1].year, monthList[currentIndex+1].month); monthList[currentIndex + 1].year,
monthList[currentIndex + 1].month);
DateModel temp = new DateModel(); DateModel temp = new DateModel();
temp.year = monthList[currentIndex].year; temp.year = monthList[currentIndex].year;
temp.month = monthList[currentIndex].month; temp.month = monthList[currentIndex].month;

@ -73,12 +73,10 @@ class CalendarContainerState extends State<CalendarContainer>
double itemHeight; double itemHeight;
double totalHeight; double totalHeight;
bool expand = true; bool expand;
CalendarProvider calendarProvider; CalendarProvider calendarProvider;
var state = CrossFadeState.showFirst;
List<Widget> widgets = []; List<Widget> widgets = [];
int index = 0; int index = 0;
@ -95,20 +93,28 @@ class CalendarContainerState extends State<CalendarContainer>
Constants.MODE_SHOW_WEEK_AND_MONTH) { Constants.MODE_SHOW_WEEK_AND_MONTH) {
widgets.add(const MonthViewPager()); widgets.add(const MonthViewPager());
widgets.add(const WeekViewPager()); widgets.add(const WeekViewPager());
index = 1;
} else if (calendarProvider.calendarConfiguration.showMode ==
Constants.MODE_SHOW_MONTH_AND_WEEK) {
widgets.add(const MonthViewPager());
widgets.add(const WeekViewPager());
index = 0;
} else { } else {
// //
widgets.add(const MonthViewPager()); widgets.add(const MonthViewPager());
} }
expand = calendarProvider.expandStatus.value;
// //
if (calendarProvider.calendarConfiguration.showMode == if (calendarProvider.calendarConfiguration.showMode ==
Constants.MODE_SHOW_WEEK_AND_MONTH) { Constants.MODE_SHOW_WEEK_AND_MONTH ||
calendarProvider.calendarConfiguration.showMode ==
Constants.MODE_SHOW_MONTH_AND_WEEK) {
calendarProvider.expandStatus.addListener(() { calendarProvider.expandStatus.addListener(() {
setState(() { setState(() {
print(
"calendarProvider.expandStatus.value:${calendarProvider.expandStatus.value}");
expand = calendarProvider.expandStatus.value; expand = calendarProvider.expandStatus.value;
state = (state == CrossFadeState.showSecond
? CrossFadeState.showFirst
: CrossFadeState.showSecond);
if (expand) { if (expand) {
index = 0; index = 0;
// //
@ -122,6 +128,9 @@ class CalendarContainerState extends State<CalendarContainer>
} }
}); });
}); });
}else{
index=0;
} }
// widget.calendarController.addMonthChangeListener((year, month) { // widget.calendarController.addMonthChangeListener((year, month) {
@ -151,7 +160,6 @@ class CalendarContainerState extends State<CalendarContainer>
MediaQueryData mediaQueryData = MediaQueryData mediaQueryData =
MediaQueryData.fromWindow(WidgetsBinding.instance.window); MediaQueryData.fromWindow(WidgetsBinding.instance.window);
print("mediaQueryData.orientation:${mediaQueryData}");
//itemSize/7/7 //itemSize/7/7
itemHeight = calendarProvider.calendarConfiguration.itemSize != null itemHeight = calendarProvider.calendarConfiguration.itemSize != null
? calendarProvider.calendarConfiguration.itemSize ? calendarProvider.calendarConfiguration.itemSize

@ -186,7 +186,7 @@ class ItemContainerState extends State<ItemContainer> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
LogUtil.log(TAG: this.runtimeType, message: "ItemContainerState build"); // LogUtil.log(TAG: this.runtimeType, message: "ItemContainerState build");
calendarProvider = Provider.of<CalendarProvider>(context, listen: false); calendarProvider = Provider.of<CalendarProvider>(context, listen: false);
configuration = calendarProvider.calendarConfiguration; configuration = calendarProvider.calendarConfiguration;
@ -243,21 +243,21 @@ class ItemContainerState extends State<ItemContainer> {
@override @override
void deactivate() { void deactivate() {
LogUtil.log( // LogUtil.log(
TAG: this.runtimeType, message: "ItemContainerState deactivate"); // TAG: this.runtimeType, message: "ItemContainerState deactivate");
super.deactivate(); super.deactivate();
} }
@override @override
void dispose() { void dispose() {
LogUtil.log(TAG: this.runtimeType, message: "ItemContainerState dispose"); // LogUtil.log(TAG: this.runtimeType, message: "ItemContainerState dispose");
super.dispose(); super.dispose();
} }
@override @override
void didUpdateWidget(ItemContainer oldWidget) { void didUpdateWidget(ItemContainer oldWidget) {
LogUtil.log( // LogUtil.log(
TAG: this.runtimeType, message: "ItemContainerState didUpdateWidget"); // TAG: this.runtimeType, message: "ItemContainerState didUpdateWidget");
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
} }
} }

Loading…
Cancel
Save