Commit e507622

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-03-15 16:29:12
clean up anti-pattern
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 43d9043
Changed files (2)
lib/components/dialoges/fullscreen_dialoge.dart
@@ -12,6 +12,7 @@ class FullscreenDialoge extends StatelessWidget {
     required this.bottomAppBar,
     this.closeIcon = Icons.close,
     this.actions = const <Widget>[],
+    this.closeCallback,
   });
 
   /// The primary content of the dialoge.
@@ -24,6 +25,10 @@ class FullscreenDialoge extends StatelessWidget {
   /// Setting this icon to null will hide the button entirely.
   final IconData? closeIcon;
 
+  /// Callback that is called after the user pressed the [closeIcon] but before
+  /// popping the scope.
+  final void Function()? closeCallback;
+
   /// Primary content of the text button at the right end of the app bar.
   ///
   /// Usually `localizations.btnSave`
lib/components/dialoges/import_preview_dialoge.dart
@@ -72,18 +72,11 @@ class _ImportPreviewDialogeState extends State<ImportPreviewDialoge> {
     }
   }
 
-  @override
-  void dispose() {
-    if(_showingError) {
-      SchedulerBinding.instance.addPostFrameCallback(
-        // TODO: add on close hook to dialoge and remove anti-pattern
-          (_) => messenger.removeCurrentMaterialBanner(),);
-    }
-    super.dispose();
-  }
-
   @override
   Widget build(BuildContext context) => FullscreenDialoge(
+    closeCallback: () {
+      if(_showingError) messenger.removeCurrentMaterialBanner();
+    },
     bottomAppBar: widget.bottomAppBar,
     actionButtonText: AppLocalizations.of(context)!.import,
     onActionButtonPressed: (_showingError) ? null : () {