Skip to content

Commit

Permalink
[timetable] nullable wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Sep 24, 2024
1 parent 29ea2a5 commit f4dcb08
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions lib/timetable/p13n/widget/wallpaper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,52 @@ import 'package:rettulf/rettulf.dart';
import '../entity/background.dart';

class WallpaperWidget extends StatelessWidget {
final BackgroundImage background;
final BackgroundImage? background;
final double opacity;
final bool fade;
final Duration fadeDuration;

const WallpaperWidget({
super.key,
required this.background,
this.background,
this.opacity = 1.0,
this.fade = true,
this.fadeDuration = Durations.long2,
});

@override
Widget build(BuildContext context) {
if (!background.enabled || background.hidden) {
final background = this.background;
if (background == null || !background.enabled || background.hidden) {
return const SizedBox.shrink();
}
if (kIsWeb) {
return _WallpaperWebImpl(
background: background,
opacity: opacity,
);
} else {
return _WallpaperImpl(
background: background,
fade: fade,
opacity: opacity,
fadeDuration: kDebugMode ? const Duration(milliseconds: 1000) : Durations.medium3,
);
}
}
}

class WithWallpaper extends StatelessWidget {
final BackgroundImage background;
final BackgroundImage? background;
final double opacity;
final Widget child;
final bool fade;

const WithWallpaper({
super.key,
required this.child,
required this.background,
this.opacity = 1.0,
this.background,
this.fade = true,
});

Expand All @@ -57,6 +64,7 @@ class WithWallpaper extends StatelessWidget {
Positioned.fill(
child: WallpaperWidget(
background: background,
opacity: opacity,
fade: fade,
),
),
Expand All @@ -67,12 +75,14 @@ class WithWallpaper extends StatelessWidget {

class _WallpaperImpl extends StatefulWidget {
final BackgroundImage background;
final double opacity;
final bool fade;
final Duration fadeDuration;

const _WallpaperImpl({
required this.background,
this.fade = true,
this.opacity = 1.0,
this.fadeDuration = Durations.long2,
});

Expand Down Expand Up @@ -152,28 +162,38 @@ class _WallpaperImplState extends State<_WallpaperImpl> with SingleTickerProvide
Widget build(BuildContext context) {
final background = widget.background;

return Image.file(
Files.timetable.backgroundFile,
opacity: $opacity,
filterQuality: background.filterQuality,
repeat: background.imageRepeat,
return AnimatedOpacity(
opacity: widget.opacity,
duration: Durations.short3,
child: Image.file(
Files.timetable.backgroundFile,
opacity: $opacity,
filterQuality: background.filterQuality,
repeat: background.imageRepeat,
),
);
}
}

class _WallpaperWebImpl extends StatelessWidget {
final BackgroundImage background;
final double opacity;

const _WallpaperWebImpl({
required this.background,
this.opacity = 1.0,
});

@override
Widget build(BuildContext context) {
return CachedNetworkImage(
imageUrl: background.path,
filterQuality: background.filterQuality,
repeat: background.imageRepeat,
return AnimatedOpacity(
opacity: opacity,
duration: Durations.short3,
child: CachedNetworkImage(
imageUrl: background.path,
filterQuality: background.filterQuality,
repeat: background.imageRepeat,
),
);
}
}

0 comments on commit f4dcb08

Please sign in to comment.