-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Busy progress indicator for pages implemented. (Not yet implemented f…
…or menu actions.)
- Loading branch information
Kern, Thomas
committed
Dec 30, 2023
1 parent
7a61379
commit 2cc85e9
Showing
5 changed files
with
283 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mopicon/utils/globals.dart'; | ||
|
||
/// Shows a modal busy indicator. | ||
/// | ||
/// If [busy] is `true`, interaction with [child] is disabled and | ||
/// a progress indicator is displayed hovering on top of [child]. | ||
/// The progress indicator is slowly fading in. | ||
class BusyWrapper extends StatefulWidget { | ||
final bool busy; | ||
final Widget child; | ||
|
||
const BusyWrapper(this.child, this.busy, {super.key}); | ||
|
||
@override | ||
State<BusyWrapper> createState() => BusyWrapperState(); | ||
} | ||
|
||
class BusyWrapperState extends State<BusyWrapper> | ||
with TickerProviderStateMixin { | ||
late final AnimationController _controller = AnimationController( | ||
duration: const Duration(seconds: 4), | ||
vsync: this, | ||
); | ||
|
||
late final Animation<double> _animation = CurvedAnimation( | ||
parent: _controller, | ||
curve: Curves.easeIn, | ||
); | ||
|
||
bool _busy = false; | ||
|
||
bool get busy => _busy; | ||
|
||
set busy(bool b) { | ||
setState(() { | ||
b ? _controller.forward() : _controller.reset(); | ||
_busy = b; | ||
}); | ||
} | ||
|
||
@override | ||
initState() { | ||
super.initState(); | ||
_busy = widget.busy; | ||
_controller.forward(); | ||
} | ||
|
||
@override | ||
dispose() { | ||
_controller.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void didUpdateWidget(covariant BusyWrapper oldWidget) { | ||
_controller.reset(); | ||
_controller.forward(); | ||
super.didUpdateWidget(oldWidget); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (!widget.busy) { | ||
return widget.child; | ||
} | ||
|
||
return Stack( | ||
children: [ | ||
widget.child, | ||
Opacity( | ||
opacity: 0.4, | ||
child: ModalBarrier( | ||
dismissible: false, | ||
color: Globals.preferences.theme.data.dialogBackgroundColor), | ||
), | ||
Center( | ||
child: FadeTransition( | ||
opacity: _animation, | ||
child: const CircularProgressIndicator(), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.