Skip to content

Commit

Permalink
[timetable] fade in wallpaper when the app was resumed after long tim…
Browse files Browse the repository at this point in the history
…e on the background
  • Loading branch information
liplum committed Sep 23, 2024
1 parent 7a451dc commit db56afe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ class _PostServiceRunnerState extends ConsumerState<_PostServiceRunner> {
super.dispose();
}

@override
void didChangeDependencies() {
precacheTimetableBackground();
super.didChangeDependencies();
}

Future<void> onResume() async {
await precacheTimetableBackground();
}
Expand Down
36 changes: 31 additions & 5 deletions lib/timetable/widget/timetable/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,49 @@ class _TimetableBackgroundImpl extends StatefulWidget {

class _TimetableBackgroundImplState extends State<_TimetableBackgroundImpl> with SingleTickerProviderStateMixin {
late final AnimationController $opacity;
late final AppLifecycleListener _listener;

DateTime? lastHiddenTime;

@override
void initState() {
super.initState();
$opacity = AnimationController(vsync: this, value: widget.fade ? 0.0 : widget.background.opacity);
_listener = AppLifecycleListener(
onHide: () {
lastHiddenTime = DateTime.now();
},
onShow: () {
final now = DateTime.now();
if (now.difference(lastHiddenTime ?? now).inSeconds > 15) {
if (widget.fade) {
$opacity.value = 0;
}
}
},
onResume: () {
if (widget.fade) {
animateOpacity();
}
},
);
if (widget.fade) {
$opacity.animateTo(
widget.background.opacity,
duration: widget.fadeDuration,
curve: Curves.easeInOut,
);
animateOpacity();
}
}

void animateOpacity() {
$opacity.animateTo(
widget.background.opacity,
duration: widget.fadeDuration,
curve: Curves.easeInOut,
);
}

@override
void dispose() {
$opacity.dispose();
_listener.dispose();
super.dispose();
}

Expand Down

0 comments on commit db56afe

Please sign in to comment.