simplified code across the app and consolidated duplicated helpers

This commit is contained in:
2026-09-27 17:29:54 +02:00
parent 3e856d0b1c
commit ee1240f71a
155 changed files with 1772 additions and 2546 deletions
+8 -12
View File
@@ -23,15 +23,13 @@ class _AsyncMixin extends StatefulWidget {
}
class _AsyncMixinState extends State<_AsyncMixin> {
late final AsyncActionController _internal;
AsyncActionController get _controller => widget.controller ?? _internal;
AsyncActionController? _own;
AsyncActionController get _controller =>
widget.controller ?? (_own ??= AsyncActionController());
@override
void initState() {
super.initState();
if (widget.controller == null) {
_internal = AsyncActionController();
}
_controller.addListener(_onControllerChange);
}
@@ -39,7 +37,7 @@ class _AsyncMixinState extends State<_AsyncMixin> {
void didUpdateWidget(covariant _AsyncMixin oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) {
(oldWidget.controller ?? _internal).removeListener(_onControllerChange);
(oldWidget.controller ?? _own)?.removeListener(_onControllerChange);
_controller.addListener(_onControllerChange);
}
}
@@ -47,9 +45,7 @@ class _AsyncMixinState extends State<_AsyncMixin> {
@override
void dispose() {
_controller.removeListener(_onControllerChange);
if (widget.controller == null) {
_internal.dispose();
}
_own?.dispose();
super.dispose();
}
@@ -76,11 +72,11 @@ class _AsyncMixinState extends State<_AsyncMixin> {
@override
Widget build(BuildContext context) {
final handler = widget.onPressed == null ? null : _trigger;
final busy = _controller.busy;
return widget.builder(
context,
_controller.busy,
_controller.busy ? null : handler,
busy,
busy || widget.onPressed == null ? null : _trigger,
);
}
}