From 3d23152802352ea45352e9744e1ad13b6aada9ee Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 7 Sep 2024 18:54:01 +0800 Subject: [PATCH] :lipstick: Auto dismiss error --- lib/providers/error_notifier.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/providers/error_notifier.dart b/lib/providers/error_notifier.dart index 83ddc6e..25b3246 100644 --- a/lib/providers/error_notifier.dart +++ b/lib/providers/error_notifier.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:developer'; import 'package:flutter/material.dart'; @@ -6,12 +7,16 @@ import 'package:get/get.dart'; class ErrorNotifier extends GetxController { Rx showing = Rx(null); + Timer? _autoDismissTimer; + void logError(String msg, {StackTrace? trace}) { log('$msg${trace != null ? '\nTrace:\n$trace' : ''}'); showError(msg); } void showError(String msg) { + _autoDismissTimer?.cancel(); + showing.value = MaterialBanner( dividerColor: Colors.transparent, leading: const Icon(Icons.error), @@ -34,5 +39,9 @@ class ErrorNotifier extends GetxController { ), ], ); + + _autoDismissTimer = Timer(const Duration(seconds: 3), () { + showing.value = null; + }); } }