|
|
@ -1,13 +1,19 @@
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
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/constants/constants.dart';
|
|
|
|
import 'package:flutter_custom_calendar/controller.dart';
|
|
|
|
import 'package:flutter_custom_calendar/controller.dart';
|
|
|
|
import 'package:flutter_custom_calendar/model/date_model.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/month_view_pager.dart';
|
|
|
|
import 'package:flutter_custom_calendar/widget/week_view_pager.dart';
|
|
|
|
import 'package:flutter_custom_calendar/widget/week_view_pager.dart';
|
|
|
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 暂时默认是周一开始的
|
|
|
|
* 暂时默认是周一开始的
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//由于旧的代码关系。。所以现在需要抽出一个StatefulWidget放在StatelessWidget里面
|
|
|
|
class CalendarViewWidget extends StatefulWidget {
|
|
|
|
class CalendarViewWidget extends StatefulWidget {
|
|
|
|
//整体的背景设置
|
|
|
|
//整体的背景设置
|
|
|
|
BoxDecoration boxDecoration;
|
|
|
|
BoxDecoration boxDecoration;
|
|
|
@ -15,124 +21,154 @@ class CalendarViewWidget extends StatefulWidget {
|
|
|
|
//控制器
|
|
|
|
//控制器
|
|
|
|
CalendarController calendarController;
|
|
|
|
CalendarController calendarController;
|
|
|
|
|
|
|
|
|
|
|
|
CalendarViewWidget({@required this.calendarController, this.boxDecoration});
|
|
|
|
CalendarViewWidget(
|
|
|
|
|
|
|
|
{Key key, @required this.calendarController, this.boxDecoration})
|
|
|
|
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
_CalendarViewWidgetState createState() => _CalendarViewWidgetState();
|
|
|
|
_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 {
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
double itemHeight;
|
|
|
|
double itemHeight;
|
|
|
|
double totalHeight;
|
|
|
|
double totalHeight;
|
|
|
|
|
|
|
|
|
|
|
|
bool expand = true;
|
|
|
|
bool expand = true;
|
|
|
|
|
|
|
|
|
|
|
|
AnimationController _animationController;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
_animationController =
|
|
|
|
// widget.calendarController.expandChanged.addListener(() {
|
|
|
|
AnimationController(duration: Duration(milliseconds: 200), vsync: this);
|
|
|
|
// print("_CalendarViewWidgetState:$expand");
|
|
|
|
|
|
|
|
// setState(() {
|
|
|
|
|
|
|
|
// expand = !expand;
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
widget.calendarController.expandChanged.addListener(() {
|
|
|
|
@override
|
|
|
|
print("_CalendarViewWidgetState:$expand");
|
|
|
|
void dispose() {
|
|
|
|
setState(() {
|
|
|
|
super.dispose();
|
|
|
|
expand = !expand;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
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.
|
|
|
|
//暂时先这样写死,提前计算布局的高度,不然会出现问题: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;
|
|
|
|
itemHeight = MediaQuery.of(context).size.width / 7;
|
|
|
|
totalHeight = itemHeight * 6 + 10 * (6 - 1);
|
|
|
|
totalHeight = itemHeight * 6 + 10 * (6 - 1);
|
|
|
|
return Container(
|
|
|
|
return Container(
|
|
|
|
//外部可以自定义背景设置
|
|
|
|
|
|
|
|
decoration: widget.boxDecoration,
|
|
|
|
|
|
|
|
child: new Column(
|
|
|
|
child: new Column(
|
|
|
|
children: <Widget>[
|
|
|
|
children: <Widget>[
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 利用const,避免每次setState都会刷新到这顶部的view
|
|
|
|
* 利用const,避免每次setState都会刷新到这顶部的view
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
widget.calendarController.weekBarItemWidgetBuilder(),
|
|
|
|
// widget.calendarController.weekBarItemWidgetBuilder(),
|
|
|
|
AnimatedContainer(
|
|
|
|
AnimatedContainer(
|
|
|
|
duration: Duration(milliseconds: 500),
|
|
|
|
duration: Duration(milliseconds: 500),
|
|
|
|
height: expand ? totalHeight : itemHeight,
|
|
|
|
height: expand ? totalHeight : itemHeight,
|
|
|
|
child: expand
|
|
|
|
child:
|
|
|
|
? Container(
|
|
|
|
// expand ?
|
|
|
|
|
|
|
|
Container(
|
|
|
|
height: totalHeight,
|
|
|
|
height: totalHeight,
|
|
|
|
child: MonthViewPager(
|
|
|
|
child: MonthViewPager(
|
|
|
|
selectMode: widget.calendarController.selectMode,
|
|
|
|
// selectMode: widget.calendarController.selectMode,
|
|
|
|
monthChange: (int year, int month) {
|
|
|
|
// monthChange: (int year, int month) {
|
|
|
|
widget.calendarController.monthChange(year, month);
|
|
|
|
// widget.calendarController.monthChange(year, month);
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
calendarSelect: (dateModel) {
|
|
|
|
// calendarSelect: (dateModel) {
|
|
|
|
widget.calendarController.selectDateModel = dateModel;
|
|
|
|
// widget.calendarController.selectDateModel = dateModel;
|
|
|
|
widget.calendarController.calendarSelect(dateModel);
|
|
|
|
// widget.calendarController.calendarSelect(dateModel);
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
monthList: widget.calendarController.monthList,
|
|
|
|
// monthList: widget.calendarController.monthList,
|
|
|
|
pageController: widget.calendarController.pageController,
|
|
|
|
// pageController: widget.calendarController.pageController,
|
|
|
|
selectedDateList:
|
|
|
|
// selectedDateList:
|
|
|
|
widget.calendarController.selectedDateList,
|
|
|
|
// widget.calendarController.selectedDateList,
|
|
|
|
selectDateModel:
|
|
|
|
// selectDateModel:
|
|
|
|
widget.calendarController.selectDateModel,
|
|
|
|
// widget.calendarController.selectDateModel,
|
|
|
|
dayWidgetBuilder:
|
|
|
|
// dayWidgetBuilder:
|
|
|
|
widget.calendarController.dayWidgetBuilder,
|
|
|
|
// widget.calendarController.dayWidgetBuilder,
|
|
|
|
minSelectDate: DateModel()
|
|
|
|
// minSelectDate: DateModel()
|
|
|
|
..year = widget.calendarController.minSelectYear
|
|
|
|
// ..year = widget.calendarController.minSelectYear
|
|
|
|
..month = widget.calendarController.minSelectMonth
|
|
|
|
// ..month = widget.calendarController.minSelectMonth
|
|
|
|
..day = widget.calendarController.minSelectDay,
|
|
|
|
// ..day = widget.calendarController.minSelectDay,
|
|
|
|
maxSelectDate: DateModel()
|
|
|
|
// maxSelectDate: DateModel()
|
|
|
|
..year = widget.calendarController.maxSelectYear
|
|
|
|
// ..year = widget.calendarController.maxSelectYear
|
|
|
|
..month = widget.calendarController.maxSelectMonth
|
|
|
|
// ..month = widget.calendarController.maxSelectMonth
|
|
|
|
..day = widget.calendarController.maxSelectDay,
|
|
|
|
// ..day = widget.calendarController.maxSelectDay,
|
|
|
|
maxMultiSelectCount:
|
|
|
|
// maxMultiSelectCount:
|
|
|
|
widget.calendarController.maxMultiSelectCount,
|
|
|
|
// widget.calendarController.maxMultiSelectCount,
|
|
|
|
multiSelectOutOfRange:
|
|
|
|
// multiSelectOutOfRange:
|
|
|
|
widget.calendarController.multiSelectOutOfRange,
|
|
|
|
// widget.calendarController.multiSelectOutOfRange,
|
|
|
|
multiSelectOutOfSize:
|
|
|
|
// multiSelectOutOfSize:
|
|
|
|
widget.calendarController.multiSelectOutOfSize,
|
|
|
|
// widget.calendarController.multiSelectOutOfSize,
|
|
|
|
extraDataMap: widget.calendarController.extraDataMap,
|
|
|
|
// extraDataMap: widget.calendarController.extraDataMap,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: Container(
|
|
|
|
// : Container(
|
|
|
|
height: itemHeight,
|
|
|
|
// height: itemHeight,
|
|
|
|
child: WeekViewPager(
|
|
|
|
// child: WeekViewPager(
|
|
|
|
selectMode: widget.calendarController.selectMode,
|
|
|
|
// selectMode: widget.calendarController.selectMode,
|
|
|
|
monthChange: (int year, int month) {
|
|
|
|
// monthChange: (int year, int month) {
|
|
|
|
widget.calendarController.monthChange(year, month);
|
|
|
|
// widget.calendarController.monthChange(year, month);
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
calendarSelect: (dateModel) {
|
|
|
|
// calendarSelect: (dateModel) {
|
|
|
|
widget.calendarController.selectDateModel = dateModel;
|
|
|
|
// widget.calendarController.selectDateModel = dateModel;
|
|
|
|
widget.calendarController.calendarSelect(dateModel);
|
|
|
|
// widget.calendarController.calendarSelect(dateModel);
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
weekList: widget.calendarController.weekList,
|
|
|
|
// weekList: widget.calendarController.weekList,
|
|
|
|
pageController: widget.calendarController.pageController,
|
|
|
|
// pageController: widget.calendarController.pageController,
|
|
|
|
selectedDateList:
|
|
|
|
// selectedDateList:
|
|
|
|
widget.calendarController.selectedDateList,
|
|
|
|
// widget.calendarController.selectedDateList,
|
|
|
|
selectDateModel:
|
|
|
|
// selectDateModel:
|
|
|
|
widget.calendarController.selectDateModel,
|
|
|
|
// widget.calendarController.selectDateModel,
|
|
|
|
dayWidgetBuilder:
|
|
|
|
// dayWidgetBuilder:
|
|
|
|
widget.calendarController.dayWidgetBuilder,
|
|
|
|
// widget.calendarController.dayWidgetBuilder,
|
|
|
|
minSelectDate: DateModel()
|
|
|
|
// minSelectDate: DateModel()
|
|
|
|
..year = widget.calendarController.minSelectYear
|
|
|
|
// ..year = widget.calendarController.minSelectYear
|
|
|
|
..month = widget.calendarController.minSelectMonth
|
|
|
|
// ..month = widget.calendarController.minSelectMonth
|
|
|
|
..day = widget.calendarController.minSelectDay,
|
|
|
|
// ..day = widget.calendarController.minSelectDay,
|
|
|
|
maxSelectDate: DateModel()
|
|
|
|
// maxSelectDate: DateModel()
|
|
|
|
..year = widget.calendarController.maxSelectYear
|
|
|
|
// ..year = widget.calendarController.maxSelectYear
|
|
|
|
..month = widget.calendarController.maxSelectMonth
|
|
|
|
// ..month = widget.calendarController.maxSelectMonth
|
|
|
|
..day = widget.calendarController.maxSelectDay,
|
|
|
|
// ..day = widget.calendarController.maxSelectDay,
|
|
|
|
maxMultiSelectCount:
|
|
|
|
// maxMultiSelectCount:
|
|
|
|
widget.calendarController.maxMultiSelectCount,
|
|
|
|
// widget.calendarController.maxMultiSelectCount,
|
|
|
|
multiSelectOutOfRange:
|
|
|
|
// multiSelectOutOfRange:
|
|
|
|
widget.calendarController.multiSelectOutOfRange,
|
|
|
|
// widget.calendarController.multiSelectOutOfRange,
|
|
|
|
multiSelectOutOfSize:
|
|
|
|
// multiSelectOutOfSize:
|
|
|
|
widget.calendarController.multiSelectOutOfSize,
|
|
|
|
// widget.calendarController.multiSelectOutOfSize,
|
|
|
|
extraDataMap: widget.calendarController.extraDataMap,
|
|
|
|
// extraDataMap: widget.calendarController.extraDataMap,
|
|
|
|
),
|
|
|
|
// ),
|
|
|
|
),
|
|
|
|
// ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|