diff --git a/lib/main.dart b/lib/main.dart index 1adfa077cb..da84c7f44e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:matrix/matrix.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/client_manager.dart'; import 'package:fluffychat/utils/platform_infos.dart'; +import 'package:fluffychat/widgets/error_widget.dart'; import 'config/setting_keys.dart'; import 'utils/background_push.dart'; import 'widgets/fluffy_chat_app.dart'; @@ -63,6 +64,7 @@ Future startGui(List clients) async { await firstClient?.roomsLoading; await firstClient?.accountDataLoading; + ErrorWidget.builder = (details) => FluffyChatErrorWidget(details); runApp(FluffyChatApp(clients: clients, pincode: pin)); } diff --git a/lib/widgets/error_widget.dart b/lib/widgets/error_widget.dart new file mode 100644 index 0000000000..8606c7608e --- /dev/null +++ b/lib/widgets/error_widget.dart @@ -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 createState() => _FluffyChatErrorWidgetState(); +} + +class _FluffyChatErrorWidgetState extends State { + @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), + ), + ), + ), + ), + ), + ); + } +}