Skip to content

Commit

Permalink
chore: Add better error widget
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Nov 1, 2023
1 parent 0156e3f commit 81943f0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -63,6 +64,7 @@ Future<void> startGui(List<Client> clients) async {
await firstClient?.roomsLoading;
await firstClient?.accountDataLoading;

ErrorWidget.builder = (details) => FluffyChatErrorWidget(details);
runApp(FluffyChatApp(clients: clients, pincode: pin));
}

Expand Down
49 changes: 49 additions & 0 deletions lib/widgets/error_widget.dart
Original file line number Diff line number Diff line change
@@ -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),
),
),
),
),
),
);
}
}

0 comments on commit 81943f0

Please sign in to comment.