Skip to content

Commit

Permalink
[timetable] extract wallpaper widget
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Sep 23, 2024
1 parent f0da1ac commit 8249cf1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -48,7 +48,7 @@ class WithTimetableBackground extends StatelessWidget {
Widget build(BuildContext context) {
return [
Positioned.fill(
child: TimetableBackground(
child: WallpaperWidget(
background: background,
),
),
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
});

Expand Down
4 changes: 2 additions & 2 deletions lib/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -118,7 +118,7 @@ class _MainStagePageState extends ConsumerState<MainStagePage> {
child: ColoredBox(color: context.colorScheme.surface),
),
Positioned.fill(
child: TimetableBackground(
child: WallpaperWidget(
background: Settings.timetable.backgroundImage ?? BackgroundImage.disabled(),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/timetable/page/screenshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -146,7 +146,7 @@ class TimetableWeeklyScreenshotFilm extends StatelessWidget {
if (config.enableBackground && background.enabled) {
return [
Positioned.fill(
child: TimetableBackground(
child: WallpaperWidget(
background: background,
fade: false,
),
Expand Down
4 changes: 2 additions & 2 deletions lib/timetable/widget/timetable/board.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(),
);
Expand Down

0 comments on commit 8249cf1

Please sign in to comment.