Commit a2a5b44f5a0d16500f443c694d1c8c0e3a7cb0c6

Authored by wdn127929
1 parent a1a94856

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

... ... @@ -409,7 +409,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
}
}
void _updateFocusOnTapJumpYear(DateTime day) {
void _updateFocusOnTapJumpYear(DateTime day) {
if (widget.pageJumpingEnabled) {
_focusedDay.value = day;
return;
... ... @@ -468,10 +468,10 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
_focusedDay.value.month,
_focusedDay.value.day,
);
_updateFocusOnTapJumpYear(focusedDay);
widget.onPageChanged?.call(focusedDay);
_pageController.previousPage(
_pageController.previousPage(
duration: widget.pageAnimationDuration,
curve: widget.pageAnimationCurve,
);
... ... @@ -528,92 +528,97 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
);
},
),
Flexible(
flex: widget.shouldFillViewport ? 1 : 0,
child: TableCalendarBase(
onCalendarCreated: (pageController) {
_pageController = pageController;
widget.onCalendarCreated?.call(pageController);
},
focusedDay: _focusedDay.value,
calendarFormat: widget.calendarFormat,
availableGestures: widget.availableGestures,
firstDay: widget.firstDay,
lastDay: widget.lastDay,
startingDayOfWeek: widget.startingDayOfWeek,
dowDecoration: widget.daysOfWeekStyle.decoration,
rowDecoration: widget.calendarStyle.rowDecoration,
tableBorder: widget.calendarStyle.tableBorder,
tablePadding: widget.calendarStyle.tablePadding,
dowVisible: widget.daysOfWeekVisible,
dowHeight: widget.daysOfWeekHeight,
rowHeight: widget.rowHeight,
formatAnimationDuration: widget.formatAnimationDuration,
formatAnimationCurve: widget.formatAnimationCurve,
pageAnimationEnabled: widget.pageAnimationEnabled,
pageAnimationDuration: widget.pageAnimationDuration,
pageAnimationCurve: widget.pageAnimationCurve,
availableCalendarFormats: widget.availableCalendarFormats,
simpleSwipeConfig: widget.simpleSwipeConfig,
sixWeekMonthsEnforced: widget.sixWeekMonthsEnforced,
onVerticalSwipe: _swipeCalendarFormat,
onPageChanged: (focusedDay) {
_focusedDay.value = focusedDay;
widget.onPageChanged?.call(focusedDay);
},
weekNumbersVisible: widget.weekNumbersVisible,
weekNumberBuilder: (BuildContext context, DateTime day) {
final weekNumber = _calculateWeekNumber(day);
final cell = widget.calendarBuilders.weekNumberBuilder
?.call(context, weekNumber);
return cell ??
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Center(
child: Text(
weekNumber.toString(),
style: widget.calendarStyle.weekNumberTextStyle,
),
),
);
},
dowBuilder: (BuildContext context, DateTime day) {
Widget? dowCell =
widget.calendarBuilders.dowBuilder?.call(context, day);
if (dowCell == null) {
final weekdayString = widget.daysOfWeekStyle.dowTextFormatter
?.call(day, widget.locale) ??
DateFormat.E(widget.locale).format(day);
final isWeekend =
_isWeekend(day, weekendDays: widget.weekendDays);
dowCell = Center(
child: ExcludeSemantics(
child: Text(
weekdayString,
style: isWeekend
? widget.daysOfWeekStyle.weekendStyle
: widget.daysOfWeekStyle.weekdayStyle,
),
),
);
}
return dowCell;
},
dayBuilder: (context, day, focusedMonth) {
return GestureDetector(
behavior: widget.dayHitTestBehavior,
onTap: () => _onDayTapped(day),
onLongPress: () => _onDayLongPressed(day),
child: _buildCell(day, focusedMonth),
ValueListenableBuilder<DateTime>(
valueListenable: _focusedDay,
builder: (context, value, _) {
return Flexible(
flex: widget.shouldFillViewport ? 1 : 0,
child: TableCalendarBase(
onCalendarCreated: (pageController) {
_pageController = pageController;
widget.onCalendarCreated?.call(pageController);
},
focusedDay: _focusedDay.value,
calendarFormat: widget.calendarFormat,
availableGestures: widget.availableGestures,
firstDay: widget.firstDay,
lastDay: widget.lastDay,
startingDayOfWeek: widget.startingDayOfWeek,
dowDecoration: widget.daysOfWeekStyle.decoration,
rowDecoration: widget.calendarStyle.rowDecoration,
tableBorder: widget.calendarStyle.tableBorder,
tablePadding: widget.calendarStyle.tablePadding,
dowVisible: widget.daysOfWeekVisible,
dowHeight: widget.daysOfWeekHeight,
rowHeight: widget.rowHeight,
formatAnimationDuration: widget.formatAnimationDuration,
formatAnimationCurve: widget.formatAnimationCurve,
pageAnimationEnabled: widget.pageAnimationEnabled,
pageAnimationDuration: widget.pageAnimationDuration,
pageAnimationCurve: widget.pageAnimationCurve,
availableCalendarFormats: widget.availableCalendarFormats,
simpleSwipeConfig: widget.simpleSwipeConfig,
sixWeekMonthsEnforced: widget.sixWeekMonthsEnforced,
onVerticalSwipe: _swipeCalendarFormat,
onPageChanged: (focusedDay) {
_focusedDay.value = focusedDay;
widget.onPageChanged?.call(focusedDay);
},
weekNumbersVisible: widget.weekNumbersVisible,
weekNumberBuilder: (BuildContext context, DateTime day) {
final weekNumber = _calculateWeekNumber(day);
final cell = widget.calendarBuilders.weekNumberBuilder
?.call(context, weekNumber);
return cell ??
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Center(
child: Text(
weekNumber.toString(),
style: widget.calendarStyle.weekNumberTextStyle,
),
),
);
},
dowBuilder: (BuildContext context, DateTime day) {
Widget? dowCell =
widget.calendarBuilders.dowBuilder?.call(context, day);
if (dowCell == null) {
final weekdayString = widget
.daysOfWeekStyle.dowTextFormatter
?.call(day, widget.locale) ??
DateFormat.E(widget.locale).format(day);
final isWeekend =
_isWeekend(day, weekendDays: widget.weekendDays);
dowCell = Center(
child: ExcludeSemantics(
child: Text(
weekdayString,
style: isWeekend
? widget.daysOfWeekStyle.weekendStyle
: widget.daysOfWeekStyle.weekdayStyle,
),
),
);
}
return dowCell;
},
dayBuilder: (context, day, focusedMonth) {
return GestureDetector(
behavior: widget.dayHitTestBehavior,
onTap: () => _onDayTapped(day),
onLongPress: () => _onDayLongPressed(day),
child: _buildCell(day, focusedMonth),
);
},
),
);
},
),
),
}),
],
);
}
... ... @@ -819,7 +824,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
}
}
bool _isBeforeYear(DateTime day, DateTime month) {
bool _isBeforeYear(DateTime day, DateTime month) {
if (day.year == month.year) {
return day.month < month.month;
} else {
... ...
... ... @@ -64,16 +64,16 @@ class CalendarHeader extends StatelessWidget {
padding: headerStyle.headerPadding,
child: Row(
children: [
// InkWell(
// onTap: selectPreviousYear,
// child: Container(
// padding: EdgeInsets.only(left: 20),
// // color: Colors.red,
// child: Image.asset(
// 'assets/date_y_l.png',
// width: 16,
// height: 45,
// ))),
InkWell(
onTap: selectPreviousYear,
child: Container(
padding: EdgeInsets.only(left: 20),
// color: Colors.red,
child: Image.asset(
'assets/date_y_l.png',
width: 16,
height: 45,
))),
if (headerStyle.leftChevronVisible)
CustomIconButton(
icon: headerStyle.leftChevronIcon,
... ... @@ -116,16 +116,16 @@ class CalendarHeader extends StatelessWidget {
margin: headerStyle.rightChevronMargin,
padding: headerStyle.rightChevronPadding,
),
// InkWell(
// onTap: selectNextYear,
// child: Container(
// padding: EdgeInsets.only(right: 20),
// // color: Colors.red,
// child: Image.asset(
// 'assets/date_y_r.png',
// width: 12,
// height: 45,
// ))),
InkWell(
onTap: selectNextYear,
child: Container(
padding: EdgeInsets.only(right: 20),
// color: Colors.red,
child: Image.asset(
'assets/date_y_r.png',
width: 12,
height: 45,
))),
],
),
);
... ...