2024-09-07 10:54:01 +00:00
|
|
|
import 'dart:async';
|
2024-09-02 13:20:30 +00:00
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
class ErrorNotifier extends GetxController {
|
|
|
|
Rx<MaterialBanner?> showing = Rx(null);
|
|
|
|
|
2024-09-07 10:54:01 +00:00
|
|
|
Timer? _autoDismissTimer;
|
|
|
|
|
2024-09-02 13:20:30 +00:00
|
|
|
void logError(String msg, {StackTrace? trace}) {
|
2024-09-04 15:28:59 +00:00
|
|
|
log('$msg${trace != null ? '\nTrace:\n$trace' : ''}');
|
2024-09-02 13:20:30 +00:00
|
|
|
showError(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showError(String msg) {
|
2024-09-07 10:54:01 +00:00
|
|
|
_autoDismissTimer?.cancel();
|
|
|
|
|
2024-09-02 13:20:30 +00:00
|
|
|
showing.value = MaterialBanner(
|
2024-09-02 15:52:38 +00:00
|
|
|
dividerColor: Colors.transparent,
|
2024-09-02 13:20:30 +00:00
|
|
|
leading: const Icon(Icons.error),
|
|
|
|
content: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
const Text(
|
|
|
|
'Something went wrong...',
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
Text(msg),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
showing.value = null;
|
|
|
|
},
|
|
|
|
child: const Text('Dismiss'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2024-09-07 10:54:01 +00:00
|
|
|
|
|
|
|
_autoDismissTimer = Timer(const Duration(seconds: 3), () {
|
|
|
|
showing.value = null;
|
|
|
|
});
|
2024-09-02 13:20:30 +00:00
|
|
|
}
|
|
|
|
}
|