diff --git a/lib/widget/calendar_view.dart b/lib/widget/calendar_view.dart index b3e7a36..4d22306 100644 --- a/lib/widget/calendar_view.dart +++ b/lib/widget/calendar_view.dart @@ -151,14 +151,17 @@ class CalendarContainerState extends State MediaQueryData mediaQueryData = MediaQueryData.fromWindow(WidgetsBinding.instance.window); - itemHeight = calendarProvider.calendarConfiguration.itemSize ?? - mediaQueryData.orientation == Orientation.landscape - ? mediaQueryData.size.height / 10 - : mediaQueryData.size.width / 7; - if (calendarProvider.totalHeight == null) { - calendarProvider.totalHeight = itemHeight * 6 + - calendarProvider.calendarConfiguration.verticalSpacing * (6 - 1); - } + print("mediaQueryData.orientation:${mediaQueryData}"); + //如果itemSize为空,默认是宽度/7。网页版的话是高度/7 + itemHeight = calendarProvider.calendarConfiguration.itemSize != null + ? calendarProvider.calendarConfiguration.itemSize + : mediaQueryData.orientation == Orientation.landscape + ? mediaQueryData.size.height / 7 + : mediaQueryData.size.width / 7; + + calendarProvider.totalHeight = itemHeight * 6 + + calendarProvider.calendarConfiguration.verticalSpacing * (6 - 1); + totalHeight = calendarProvider.totalHeight; } @override @@ -172,10 +175,6 @@ class CalendarContainerState extends State //暂时先这样写死,提前计算布局的高度,不然会出现问题:a horizontal viewport was given an unlimited amount of I/flutter ( 6759): vertical space in which to expand. // itemHeight = calendarProvider.calendarConfiguration.itemSize ?? // MediaQuery.of(context).size.width / 7; - if (totalHeight == null) { - totalHeight = itemHeight * 6 + - calendarProvider.calendarConfiguration.verticalSpacing * (6 - 1); - } return Container( width: itemHeight * 7, child: new Column( diff --git a/lib/widget/month_view.dart b/lib/widget/month_view.dart index 27d783b..6ee8fee 100644 --- a/lib/widget/month_view.dart +++ b/lib/widget/month_view.dart @@ -108,8 +108,8 @@ class _MonthViewState extends State return new GridView.builder( addAutomaticKeepAlives: true, physics: const NeverScrollableScrollPhysics(), - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 7, mainAxisSpacing: 10), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 7, mainAxisSpacing: configuration.verticalSpacing), itemCount: items.isEmpty ? 0 : 7 * lineCount, itemBuilder: (context, index) { DateModel dateModel = items[index]; diff --git a/lib/widget/month_view_pager.dart b/lib/widget/month_view_pager.dart index 1925717..9fceaab 100644 --- a/lib/widget/month_view_pager.dart +++ b/lib/widget/month_view_pager.dart @@ -86,18 +86,18 @@ class _MonthViewPagerState extends State with AutomaticKeepAlive 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); - } +// 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,