Commit a2a5b44f5a0d16500f443c694d1c8c0e3a7cb0c6

Authored by wdn127929
1 parent a1a94856

日历插件本地化,新增年份切换

@@ -409,7 +409,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> { @@ -409,7 +409,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
409 } 409 }
410 } 410 }
411 411
412 - void _updateFocusOnTapJumpYear(DateTime day) { 412 + void _updateFocusOnTapJumpYear(DateTime day) {
413 if (widget.pageJumpingEnabled) { 413 if (widget.pageJumpingEnabled) {
414 _focusedDay.value = day; 414 _focusedDay.value = day;
415 return; 415 return;
@@ -468,10 +468,10 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> { @@ -468,10 +468,10 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
468 _focusedDay.value.month, 468 _focusedDay.value.month,
469 _focusedDay.value.day, 469 _focusedDay.value.day,
470 ); 470 );
471 - 471 +
472 _updateFocusOnTapJumpYear(focusedDay); 472 _updateFocusOnTapJumpYear(focusedDay);
473 widget.onPageChanged?.call(focusedDay); 473 widget.onPageChanged?.call(focusedDay);
474 - _pageController.previousPage( 474 + _pageController.previousPage(
475 duration: widget.pageAnimationDuration, 475 duration: widget.pageAnimationDuration,
476 curve: widget.pageAnimationCurve, 476 curve: widget.pageAnimationCurve,
477 ); 477 );
@@ -528,92 +528,97 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> { @@ -528,92 +528,97 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
528 ); 528 );
529 }, 529 },
530 ), 530 ),
531 - Flexible(  
532 - flex: widget.shouldFillViewport ? 1 : 0,  
533 - child: TableCalendarBase(  
534 - onCalendarCreated: (pageController) {  
535 - _pageController = pageController;  
536 - widget.onCalendarCreated?.call(pageController);  
537 - },  
538 - focusedDay: _focusedDay.value,  
539 - calendarFormat: widget.calendarFormat,  
540 - availableGestures: widget.availableGestures,  
541 - firstDay: widget.firstDay,  
542 - lastDay: widget.lastDay,  
543 - startingDayOfWeek: widget.startingDayOfWeek,  
544 - dowDecoration: widget.daysOfWeekStyle.decoration,  
545 - rowDecoration: widget.calendarStyle.rowDecoration,  
546 - tableBorder: widget.calendarStyle.tableBorder,  
547 - tablePadding: widget.calendarStyle.tablePadding,  
548 - dowVisible: widget.daysOfWeekVisible,  
549 - dowHeight: widget.daysOfWeekHeight,  
550 - rowHeight: widget.rowHeight,  
551 - formatAnimationDuration: widget.formatAnimationDuration,  
552 - formatAnimationCurve: widget.formatAnimationCurve,  
553 - pageAnimationEnabled: widget.pageAnimationEnabled,  
554 - pageAnimationDuration: widget.pageAnimationDuration,  
555 - pageAnimationCurve: widget.pageAnimationCurve,  
556 - availableCalendarFormats: widget.availableCalendarFormats,  
557 - simpleSwipeConfig: widget.simpleSwipeConfig,  
558 - sixWeekMonthsEnforced: widget.sixWeekMonthsEnforced,  
559 - onVerticalSwipe: _swipeCalendarFormat,  
560 - onPageChanged: (focusedDay) {  
561 - _focusedDay.value = focusedDay;  
562 - widget.onPageChanged?.call(focusedDay);  
563 - },  
564 - weekNumbersVisible: widget.weekNumbersVisible,  
565 - weekNumberBuilder: (BuildContext context, DateTime day) {  
566 - final weekNumber = _calculateWeekNumber(day);  
567 - final cell = widget.calendarBuilders.weekNumberBuilder  
568 - ?.call(context, weekNumber);  
569 -  
570 - return cell ??  
571 - Padding(  
572 - padding: const EdgeInsets.symmetric(horizontal: 4),  
573 - child: Center(  
574 - child: Text(  
575 - weekNumber.toString(),  
576 - style: widget.calendarStyle.weekNumberTextStyle,  
577 - ),  
578 - ),  
579 - );  
580 - },  
581 - dowBuilder: (BuildContext context, DateTime day) {  
582 - Widget? dowCell =  
583 - widget.calendarBuilders.dowBuilder?.call(context, day);  
584 -  
585 - if (dowCell == null) {  
586 - final weekdayString = widget.daysOfWeekStyle.dowTextFormatter  
587 - ?.call(day, widget.locale) ??  
588 - DateFormat.E(widget.locale).format(day);  
589 -  
590 - final isWeekend =  
591 - _isWeekend(day, weekendDays: widget.weekendDays);  
592 -  
593 - dowCell = Center(  
594 - child: ExcludeSemantics(  
595 - child: Text(  
596 - weekdayString,  
597 - style: isWeekend  
598 - ? widget.daysOfWeekStyle.weekendStyle  
599 - : widget.daysOfWeekStyle.weekdayStyle,  
600 - ),  
601 - ),  
602 - );  
603 - }  
604 -  
605 - return dowCell;  
606 - },  
607 - dayBuilder: (context, day, focusedMonth) {  
608 - return GestureDetector(  
609 - behavior: widget.dayHitTestBehavior,  
610 - onTap: () => _onDayTapped(day),  
611 - onLongPress: () => _onDayLongPressed(day),  
612 - child: _buildCell(day, focusedMonth), 531 + ValueListenableBuilder<DateTime>(
  532 + valueListenable: _focusedDay,
  533 + builder: (context, value, _) {
  534 + return Flexible(
  535 + flex: widget.shouldFillViewport ? 1 : 0,
  536 + child: TableCalendarBase(
  537 + onCalendarCreated: (pageController) {
  538 + _pageController = pageController;
  539 + widget.onCalendarCreated?.call(pageController);
  540 + },
  541 + focusedDay: _focusedDay.value,
  542 + calendarFormat: widget.calendarFormat,
  543 + availableGestures: widget.availableGestures,
  544 + firstDay: widget.firstDay,
  545 + lastDay: widget.lastDay,
  546 + startingDayOfWeek: widget.startingDayOfWeek,
  547 + dowDecoration: widget.daysOfWeekStyle.decoration,
  548 + rowDecoration: widget.calendarStyle.rowDecoration,
  549 + tableBorder: widget.calendarStyle.tableBorder,
  550 + tablePadding: widget.calendarStyle.tablePadding,
  551 + dowVisible: widget.daysOfWeekVisible,
  552 + dowHeight: widget.daysOfWeekHeight,
  553 + rowHeight: widget.rowHeight,
  554 + formatAnimationDuration: widget.formatAnimationDuration,
  555 + formatAnimationCurve: widget.formatAnimationCurve,
  556 + pageAnimationEnabled: widget.pageAnimationEnabled,
  557 + pageAnimationDuration: widget.pageAnimationDuration,
  558 + pageAnimationCurve: widget.pageAnimationCurve,
  559 + availableCalendarFormats: widget.availableCalendarFormats,
  560 + simpleSwipeConfig: widget.simpleSwipeConfig,
  561 + sixWeekMonthsEnforced: widget.sixWeekMonthsEnforced,
  562 + onVerticalSwipe: _swipeCalendarFormat,
  563 + onPageChanged: (focusedDay) {
  564 + _focusedDay.value = focusedDay;
  565 + widget.onPageChanged?.call(focusedDay);
  566 + },
  567 + weekNumbersVisible: widget.weekNumbersVisible,
  568 + weekNumberBuilder: (BuildContext context, DateTime day) {
  569 + final weekNumber = _calculateWeekNumber(day);
  570 + final cell = widget.calendarBuilders.weekNumberBuilder
  571 + ?.call(context, weekNumber);
  572 +
  573 + return cell ??
  574 + Padding(
  575 + padding: const EdgeInsets.symmetric(horizontal: 4),
  576 + child: Center(
  577 + child: Text(
  578 + weekNumber.toString(),
  579 + style: widget.calendarStyle.weekNumberTextStyle,
  580 + ),
  581 + ),
  582 + );
  583 + },
  584 + dowBuilder: (BuildContext context, DateTime day) {
  585 + Widget? dowCell =
  586 + widget.calendarBuilders.dowBuilder?.call(context, day);
  587 +
  588 + if (dowCell == null) {
  589 + final weekdayString = widget
  590 + .daysOfWeekStyle.dowTextFormatter
  591 + ?.call(day, widget.locale) ??
  592 + DateFormat.E(widget.locale).format(day);
  593 +
  594 + final isWeekend =
  595 + _isWeekend(day, weekendDays: widget.weekendDays);
  596 +
  597 + dowCell = Center(
  598 + child: ExcludeSemantics(
  599 + child: Text(
  600 + weekdayString,
  601 + style: isWeekend
  602 + ? widget.daysOfWeekStyle.weekendStyle
  603 + : widget.daysOfWeekStyle.weekdayStyle,
  604 + ),
  605 + ),
  606 + );
  607 + }
  608 +
  609 + return dowCell;
  610 + },
  611 + dayBuilder: (context, day, focusedMonth) {
  612 + return GestureDetector(
  613 + behavior: widget.dayHitTestBehavior,
  614 + onTap: () => _onDayTapped(day),
  615 + onLongPress: () => _onDayLongPressed(day),
  616 + child: _buildCell(day, focusedMonth),
  617 + );
  618 + },
  619 + ),
613 ); 620 );
614 - },  
615 - ),  
616 - ), 621 + }),
617 ], 622 ],
618 ); 623 );
619 } 624 }
@@ -819,7 +824,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> { @@ -819,7 +824,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
819 } 824 }
820 } 825 }
821 826
822 - bool _isBeforeYear(DateTime day, DateTime month) { 827 + bool _isBeforeYear(DateTime day, DateTime month) {
823 if (day.year == month.year) { 828 if (day.year == month.year) {
824 return day.month < month.month; 829 return day.month < month.month;
825 } else { 830 } else {
@@ -64,16 +64,16 @@ class CalendarHeader extends StatelessWidget { @@ -64,16 +64,16 @@ class CalendarHeader extends StatelessWidget {
64 padding: headerStyle.headerPadding, 64 padding: headerStyle.headerPadding,
65 child: Row( 65 child: Row(
66 children: [ 66 children: [
67 - // InkWell(  
68 - // onTap: selectPreviousYear,  
69 - // child: Container(  
70 - // padding: EdgeInsets.only(left: 20),  
71 - // // color: Colors.red,  
72 - // child: Image.asset(  
73 - // 'assets/date_y_l.png',  
74 - // width: 16,  
75 - // height: 45,  
76 - // ))), 67 + InkWell(
  68 + onTap: selectPreviousYear,
  69 + child: Container(
  70 + padding: EdgeInsets.only(left: 20),
  71 + // color: Colors.red,
  72 + child: Image.asset(
  73 + 'assets/date_y_l.png',
  74 + width: 16,
  75 + height: 45,
  76 + ))),
77 if (headerStyle.leftChevronVisible) 77 if (headerStyle.leftChevronVisible)
78 CustomIconButton( 78 CustomIconButton(
79 icon: headerStyle.leftChevronIcon, 79 icon: headerStyle.leftChevronIcon,
@@ -116,16 +116,16 @@ class CalendarHeader extends StatelessWidget { @@ -116,16 +116,16 @@ class CalendarHeader extends StatelessWidget {
116 margin: headerStyle.rightChevronMargin, 116 margin: headerStyle.rightChevronMargin,
117 padding: headerStyle.rightChevronPadding, 117 padding: headerStyle.rightChevronPadding,
118 ), 118 ),
119 - // InkWell(  
120 - // onTap: selectNextYear,  
121 - // child: Container(  
122 - // padding: EdgeInsets.only(right: 20),  
123 - // // color: Colors.red,  
124 - // child: Image.asset(  
125 - // 'assets/date_y_r.png',  
126 - // width: 12,  
127 - // height: 45,  
128 - // ))), 119 + InkWell(
  120 + onTap: selectNextYear,
  121 + child: Container(
  122 + padding: EdgeInsets.only(right: 20),
  123 + // color: Colors.red,
  124 + child: Image.asset(
  125 + 'assets/date_y_r.png',
  126 + width: 12,
  127 + height: 45,
  128 + ))),
129 ], 129 ],
130 ), 130 ),
131 ); 131 );