From 8249cf198a2d365835f0060ab2f6d9f990dfa17f Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 24 Sep 2024 04:29:06 +0800 Subject: [PATCH] [timetable] extract wallpaper widget --- .../widget/wallpaper.dart} | 30 +++++++++---------- lib/index.dart | 4 +-- lib/timetable/page/screenshot.dart | 4 +-- lib/timetable/widget/timetable/board.dart | 4 +-- 4 files changed, 21 insertions(+), 21 deletions(-) rename lib/{timetable/widget/timetable/background.dart => design/widget/wallpaper.dart} (80%) diff --git a/lib/timetable/widget/timetable/background.dart b/lib/design/widget/wallpaper.dart similarity index 80% rename from lib/timetable/widget/timetable/background.dart rename to lib/design/widget/wallpaper.dart index f6ca4c59..e79b1d07 100644 --- a/lib/timetable/widget/timetable/background.dart +++ b/lib/design/widget/wallpaper.dart @@ -4,14 +4,14 @@ import 'package:flutter/material.dart'; import 'package:mimir/files.dart'; import 'package:rettulf/rettulf.dart'; -import '../../p13n/entity/background.dart'; +import '../../timetable/p13n/entity/background.dart'; -class TimetableBackground extends StatelessWidget { +class WallpaperWidget extends StatelessWidget { final BackgroundImage background; final bool fade; final Duration fadeDuration; - const TimetableBackground({ + const WallpaperWidget({ super.key, required this.background, this.fade = true, @@ -21,11 +21,11 @@ class TimetableBackground extends StatelessWidget { @override Widget build(BuildContext context) { if (kIsWeb) { - return _TimetableBackgroundWebImpl( + return _WallpaperWebImpl( background: background, ); } else { - return _TimetableBackgroundImpl( + return _WallpaperImpl( background: background, fade: fade, fadeDuration: kDebugMode ? const Duration(milliseconds: 1000) : Durations.long1, @@ -34,11 +34,11 @@ class TimetableBackground extends StatelessWidget { } } -class WithTimetableBackground extends StatelessWidget { +class WithWallpaper extends StatelessWidget { final BackgroundImage background; final Widget child; - const WithTimetableBackground({ + const WithWallpaper({ super.key, required this.child, required this.background, @@ -48,7 +48,7 @@ class WithTimetableBackground extends StatelessWidget { Widget build(BuildContext context) { return [ Positioned.fill( - child: TimetableBackground( + child: WallpaperWidget( background: background, ), ), @@ -57,22 +57,22 @@ class WithTimetableBackground extends StatelessWidget { } } -class _TimetableBackgroundImpl extends StatefulWidget { +class _WallpaperImpl extends StatefulWidget { final BackgroundImage background; final bool fade; final Duration fadeDuration; - const _TimetableBackgroundImpl({ + const _WallpaperImpl({ required this.background, this.fade = true, this.fadeDuration = Durations.long2, }); @override - State<_TimetableBackgroundImpl> createState() => _TimetableBackgroundImplState(); + State<_WallpaperImpl> createState() => _WallpaperImplState(); } -class _TimetableBackgroundImplState extends State<_TimetableBackgroundImpl> with SingleTickerProviderStateMixin { +class _WallpaperImplState extends State<_WallpaperImpl> with SingleTickerProviderStateMixin { late final AnimationController $opacity; late final AppLifecycleListener _listener; @@ -121,7 +121,7 @@ class _TimetableBackgroundImplState extends State<_TimetableBackgroundImpl> with } @override - void didUpdateWidget(covariant _TimetableBackgroundImpl oldWidget) { + void didUpdateWidget(covariant _WallpaperImpl oldWidget) { super.didUpdateWidget(oldWidget); if (widget.fade && oldWidget.fade) { if (oldWidget.background != widget.background) { @@ -151,10 +151,10 @@ class _TimetableBackgroundImplState extends State<_TimetableBackgroundImpl> with } } -class _TimetableBackgroundWebImpl extends StatelessWidget { +class _WallpaperWebImpl extends StatelessWidget { final BackgroundImage background; - const _TimetableBackgroundWebImpl({ + const _WallpaperWebImpl({ required this.background, }); diff --git a/lib/index.dart b/lib/index.dart index aed36fb8..2845f96d 100644 --- a/lib/index.dart +++ b/lib/index.dart @@ -14,7 +14,7 @@ import 'package:mimir/life/i18n.dart' as $life; import 'package:mimir/game/i18n.dart' as $game; import 'package:mimir/me/i18n.dart' as $me; import 'package:mimir/timetable/p13n/entity/background.dart'; -import 'package:mimir/timetable/widget/timetable/background.dart'; +import 'package:mimir/design/widget/wallpaper.dart'; // import 'package:mimir/backend/forum/i18n.dart' as $forum; import 'package:rettulf/rettulf.dart'; @@ -118,7 +118,7 @@ class _MainStagePageState extends ConsumerState { child: ColoredBox(color: context.colorScheme.surface), ), Positioned.fill( - child: TimetableBackground( + child: WallpaperWidget( background: Settings.timetable.backgroundImage ?? BackgroundImage.disabled(), ), ), diff --git a/lib/timetable/page/screenshot.dart b/lib/timetable/page/screenshot.dart index 1e96dc6f..df9ef47c 100644 --- a/lib/timetable/page/screenshot.dart +++ b/lib/timetable/page/screenshot.dart @@ -8,7 +8,7 @@ import 'package:mimir/utils/screenshot.dart'; import "../i18n.dart"; import '../p13n/widget/style.dart'; -import '../widget/timetable/background.dart'; +import '../../design/widget/wallpaper.dart'; import '../widget/timetable/weekly.dart'; import '../entity/timetable_entity.dart'; @@ -146,7 +146,7 @@ class TimetableWeeklyScreenshotFilm extends StatelessWidget { if (config.enableBackground && background.enabled) { return [ Positioned.fill( - child: TimetableBackground( + child: WallpaperWidget( background: background, fade: false, ), diff --git a/lib/timetable/widget/timetable/board.dart b/lib/timetable/widget/timetable/board.dart index e0972cd4..95b73874 100644 --- a/lib/timetable/widget/timetable/board.dart +++ b/lib/timetable/widget/timetable/board.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:mimir/design/widget/wallpaper.dart'; import 'package:rettulf/rettulf.dart'; import 'package:mimir/timetable/p13n/widget/style.dart'; import '../../entity/display.dart'; import '../../entity/pos.dart'; import '../../entity/timetable_entity.dart'; -import 'background.dart'; import 'daily.dart'; import 'weekly.dart'; @@ -28,7 +28,7 @@ class TimetableBoard extends StatelessWidget { final style = TimetableStyle.of(context); final background = style.background; if (background.enabled) { - return WithTimetableBackground( + return WithWallpaper( background: background, child: buildBoard(), );