mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
chore: Add better error widget
This commit is contained in:
parent
0156e3ff4f
commit
81943f062c
2 changed files with 51 additions and 0 deletions
|
@ -7,6 +7,7 @@ import 'package:matrix/matrix.dart';
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/utils/client_manager.dart';
|
import 'package:fluffychat/utils/client_manager.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
import 'package:fluffychat/widgets/error_widget.dart';
|
||||||
import 'config/setting_keys.dart';
|
import 'config/setting_keys.dart';
|
||||||
import 'utils/background_push.dart';
|
import 'utils/background_push.dart';
|
||||||
import 'widgets/fluffy_chat_app.dart';
|
import 'widgets/fluffy_chat_app.dart';
|
||||||
|
@ -63,6 +64,7 @@ Future<void> startGui(List<Client> clients) async {
|
||||||
await firstClient?.roomsLoading;
|
await firstClient?.roomsLoading;
|
||||||
await firstClient?.accountDataLoading;
|
await firstClient?.accountDataLoading;
|
||||||
|
|
||||||
|
ErrorWidget.builder = (details) => FluffyChatErrorWidget(details);
|
||||||
runApp(FluffyChatApp(clients: clients, pincode: pin));
|
runApp(FluffyChatApp(clients: clients, pincode: pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
49
lib/widgets/error_widget.dart
Normal file
49
lib/widgets/error_widget.dart
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/error_reporter.dart';
|
||||||
|
|
||||||
|
class FluffyChatErrorWidget extends StatefulWidget {
|
||||||
|
final FlutterErrorDetails details;
|
||||||
|
const FluffyChatErrorWidget(this.details, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FluffyChatErrorWidget> createState() => _FluffyChatErrorWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FluffyChatErrorWidgetState extends State<FluffyChatErrorWidget> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
ErrorReporter(context, 'Error Widget').onErrorCallback(
|
||||||
|
widget.details.exception,
|
||||||
|
widget.details.stack,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Material(
|
||||||
|
color: Colors.orange,
|
||||||
|
child: Placeholder(
|
||||||
|
child: Center(
|
||||||
|
child: Material(
|
||||||
|
color: Colors.white.withOpacity(0.9),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
'😲 Oh no! Something is broken 😲\n${widget.details.exception}',
|
||||||
|
maxLines: 5,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(color: Colors.black),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue