Skip to content

Commit

Permalink
[timetable] bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Apr 26, 2024
1 parent 1c99de6 commit 59cd406
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 51 deletions.
38 changes: 19 additions & 19 deletions assets/l10n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,25 @@ timetable:
addColor: Add a color
addFromQrCodeAction: Add palette
addFromQrCodeDesc: Confirm to add a timetable palette from QR code?
builtin:
classic:
name: Classic
americano:
name: Americano
candy:
name: Candy
sprint:
name: Sprint
summary:
name: Summary
fall:
name: Fall
winter:
name: Winter
thicket:
name: Thicket
creeksideBreeze:
name: Creekside Breeze
builtin:
classic:
name: Classic
americano:
name: Americano
candy:
name: Candy
sprint:
name: Sprint
summary:
name: Summary
fall:
name: Fall
winter:
name: Winter
thicket:
name: Thicket
creeksideBreeze:
name: Creekside Breeze
cellStyle:
title: Cell Style
showTeachers:
Expand Down
40 changes: 20 additions & 20 deletions assets/l10n/zh-Hans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ timetable:
removeDay: "删除 {day} 的课"
swapDays: "交换 {a} 和 {b} 的课"
copyDay: "{target} 上与 {source} 相同的课"
moveDay: "把 {source} 的课改到 {target}"
moveDay: "{target} 改为上 {source} 的课"
type:
moveDay: 移动某天
removeDay: 删除某天
Expand Down Expand Up @@ -156,25 +156,25 @@ timetable:
addColor: 添加一种配色
addFromQrCodeAction: 添加配色方案
addFromQrCodeDesc: 确定从读取的二维码中添加配色方案?
builtin:
classic:
name: 经典
americano:
name: 美式复古
candy:
name: 糖果幻境
sprint:
name: 兰时
summary:
name: 时夏
fall:
name: 萧辰
winter:
name: 北陆
thicket:
name: 小森林
creeksideBreeze:
name: 溪畔听风
builtin:
classic:
name: 经典
americano:
name: 美式复古
candy:
name: 糖果幻境
sprint:
name: 兰时
summary:
name: 时夏
fall:
name: 萧辰
winter:
name: 北陆
thicket:
name: 小森林
creeksideBreeze:
name: 溪畔听风
cellStyle:
title: 单元格风格
showTeachers:
Expand Down
16 changes: 11 additions & 5 deletions lib/timetable/widgets/patch/copy_day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ class _TimetableCopyDayPatchSheetState extends State<TimetableCopyDayPatchSheet>

@override
Widget build(BuildContext context) {
final patch = buildPatch();
return PromptSaveBeforeQuitScope(
canSave: anyChanged,
canSave: anyChanged && canSave(),
onSave: onSave,
child: Scaffold(
body: CustomScrollView(
Expand All @@ -100,6 +101,10 @@ class _TimetableCopyDayPatchSheetState extends State<TimetableCopyDayPatchSheet>
TimetableDayLocMode.pos => buildPosTab(),
TimetableDayLocMode.date => buildDateTab(),
},
if (patch != null)
ListTile(
title: patch.l10n().text(),
)
]),
],
),
Expand All @@ -122,7 +127,7 @@ class _TimetableCopyDayPatchSheetState extends State<TimetableCopyDayPatchSheet>
return [
TimetableDayLocPosSelectionTile(
leading: const Icon(Icons.output),
title: "Source position".text(),
title: i18n.patch.copySource.text(),
timetable: widget.timetable,
pos: sourcePos,
onChanged: (newPos) {
Expand All @@ -134,7 +139,7 @@ class _TimetableCopyDayPatchSheetState extends State<TimetableCopyDayPatchSheet>
),
TimetableDayLocPosSelectionTile(
leading: const Icon(Icons.input),
title: "Target position".text(),
title: i18n.patch.copyTarget.text(),
timetable: widget.timetable,
pos: targetPos,
onChanged: (newPos) {
Expand All @@ -144,14 +149,15 @@ class _TimetableCopyDayPatchSheetState extends State<TimetableCopyDayPatchSheet>
markChanged();
},
),

];
}

List<Widget> buildDateTab() {
return [
TimetableDayLocDateSelectionTile(
leading: const Icon(Icons.output),
title: "Source date".text(),
title: i18n.patch.copySource.text(),
timetable: widget.timetable,
date: sourceDate,
onChanged: (newPos) {
Expand All @@ -163,7 +169,7 @@ class _TimetableCopyDayPatchSheetState extends State<TimetableCopyDayPatchSheet>
),
TimetableDayLocDateSelectionTile(
leading: const Icon(Icons.input),
title: "Target date".text(),
title: i18n.patch.copyTarget.text(),
timetable: widget.timetable,
date: targetDate,
onChanged: (newPos) {
Expand Down
7 changes: 6 additions & 1 deletion lib/timetable/widgets/patch/move_day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ class _TimetableMoveDayPatchSheetState extends State<TimetableMoveDayPatchSheet>

@override
Widget build(BuildContext context) {
final patch = buildPatch();
return PromptSaveBeforeQuitScope(
canSave: anyChanged,
canSave: anyChanged && canSave(),
onSave: onSave,
child: Scaffold(
body: CustomScrollView(
Expand All @@ -100,6 +101,10 @@ class _TimetableMoveDayPatchSheetState extends State<TimetableMoveDayPatchSheet>
TimetableDayLocMode.pos => buildPosTab(),
TimetableDayLocMode.date => buildDateTab(),
},
if (patch != null)
ListTile(
title: patch.l10n().text(),
)
]),
],
),
Expand Down
7 changes: 6 additions & 1 deletion lib/timetable/widgets/patch/remove_day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ class _TimetableRemoveDayPatchSheetState extends State<TimetableRemoveDayPatchSh

@override
Widget build(BuildContext context) {
final patch = buildPatch();
return PromptSaveBeforeQuitScope(
canSave: anyChanged,
canSave: anyChanged && canSave(),
onSave: onSave,
child: Scaffold(
body: CustomScrollView(
Expand All @@ -96,6 +97,10 @@ class _TimetableRemoveDayPatchSheetState extends State<TimetableRemoveDayPatchSh
TimetableDayLocMode.pos => buildPosTab(),
TimetableDayLocMode.date => buildDateTab(),
},
if (patch != null)
ListTile(
title: patch.l10n().text(),
)
]),
],
),
Expand Down
12 changes: 8 additions & 4 deletions lib/timetable/widgets/patch/shared.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:rettulf/rettulf.dart';
import 'package:sit/l10n/extension.dart';
import 'package:sit/timetable/entity/pos.dart';
Expand Down Expand Up @@ -35,6 +36,8 @@ class TimetableDayLocModeSwitcher extends StatelessWidget {
}
}

final _lastInitialDate = StateProvider<DateTime>((ref) => DateTime.now());

class TimetableDayLocPosSelectionTile extends StatelessWidget {
final Widget title;
final Widget? leading;
Expand Down Expand Up @@ -75,7 +78,7 @@ class TimetableDayLocPosSelectionTile extends StatelessWidget {
}
}

class TimetableDayLocDateSelectionTile extends StatelessWidget {
class TimetableDayLocDateSelectionTile extends ConsumerWidget {
final Widget title;
final Widget? leading;
final DateTime? date;
Expand All @@ -92,7 +95,7 @@ class TimetableDayLocDateSelectionTile extends StatelessWidget {
});

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final date = this.date;
return ListTile(
leading: leading,
Expand All @@ -104,12 +107,13 @@ class TimetableDayLocDateSelectionTile extends StatelessWidget {
final now = DateTime.now();
final newDate = await showDatePicker(
context: context,
initialDate: date ?? now,
currentDate: now,
initialDate: date ?? ref.read(_lastInitialDate),
currentDate: date ,
firstDate: DateTime(now.year - 4),
lastDate: DateTime(now.year + 2),
);
if (newDate == null) return;
ref.read(_lastInitialDate.notifier).state = newDate;
onChanged(newDate);
},
),
Expand Down
7 changes: 6 additions & 1 deletion lib/timetable/widgets/patch/swap_day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ class _TimetableSwapDaysPatchSheetState extends State<TimetableSwapDaysPatchShee

@override
Widget build(BuildContext context) {
final patch = buildPatch();
return PromptSaveBeforeQuitScope(
canSave: anyChanged,
canSave: anyChanged && canSave(),
onSave: onSave,
child: Scaffold(
body: CustomScrollView(
Expand All @@ -100,6 +101,10 @@ class _TimetableSwapDaysPatchSheetState extends State<TimetableSwapDaysPatchShee
TimetableDayLocMode.pos => buildPosTab(),
TimetableDayLocMode.date => buildDateTab(),
},
if (patch != null)
ListTile(
title: patch.l10n().text(),
)
]),
],
),
Expand Down

0 comments on commit 59cd406

Please sign in to comment.