💄 Auto dismiss error

This commit is contained in:
LittleSheep 2024-09-07 18:54:01 +08:00
parent 90dc3f43a7
commit 3d23152802

View File

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:developer'; import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -6,12 +7,16 @@ import 'package:get/get.dart';
class ErrorNotifier extends GetxController { class ErrorNotifier extends GetxController {
Rx<MaterialBanner?> showing = Rx(null); Rx<MaterialBanner?> showing = Rx(null);
Timer? _autoDismissTimer;
void logError(String msg, {StackTrace? trace}) { void logError(String msg, {StackTrace? trace}) {
log('$msg${trace != null ? '\nTrace:\n$trace' : ''}'); log('$msg${trace != null ? '\nTrace:\n$trace' : ''}');
showError(msg); showError(msg);
} }
void showError(String msg) { void showError(String msg) {
_autoDismissTimer?.cancel();
showing.value = MaterialBanner( showing.value = MaterialBanner(
dividerColor: Colors.transparent, dividerColor: Colors.transparent,
leading: const Icon(Icons.error), leading: const Icon(Icons.error),
@ -34,5 +39,9 @@ class ErrorNotifier extends GetxController {
), ),
], ],
); );
_autoDismissTimer = Timer(const Duration(seconds: 3), () {
showing.value = null;
});
} }
} }