chore: Follow up better error dialog
This commit is contained in:
parent
43f304b1a8
commit
1d44e8b5d0
2 changed files with 43 additions and 7 deletions
|
|
@ -6,6 +6,8 @@ import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
import 'package:fluffychat/pages/homeserver_picker/public_homeserver.dart';
|
import 'package:fluffychat/pages/homeserver_picker/public_homeserver.dart';
|
||||||
|
import 'package:fluffychat/utils/error_reporter.dart';
|
||||||
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
import 'homeserver_bottom_sheet.dart';
|
import 'homeserver_bottom_sheet.dart';
|
||||||
import 'homeserver_picker.dart';
|
import 'homeserver_picker.dart';
|
||||||
|
|
||||||
|
|
@ -31,6 +33,19 @@ class HomeserverAppBar extends StatelessWidget {
|
||||||
leading: const CircularProgressIndicator.adaptive(strokeWidth: 2),
|
leading: const CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||||
title: Text(L10n.of(context)!.loadingPleaseWait),
|
title: Text(L10n.of(context)!.loadingPleaseWait),
|
||||||
),
|
),
|
||||||
|
errorBuilder: (context, error) {
|
||||||
|
ErrorReporter(context, 'Unable to load homeservers').onErrorCallback(
|
||||||
|
error ?? Object(),
|
||||||
|
StackTrace.current,
|
||||||
|
);
|
||||||
|
return ListTile(
|
||||||
|
leading: const Icon(Icons.error_outlined),
|
||||||
|
title: Text(
|
||||||
|
error?.toLocalizedString(context) ??
|
||||||
|
L10n.of(context)!.oopsSomethingWentWrong,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
itemBuilder: (context, homeserver) => ListTile(
|
itemBuilder: (context, homeserver) => ListTile(
|
||||||
title: Text(homeserver.name),
|
title: Text(homeserver.name),
|
||||||
subtitle: homeserver.description == null
|
subtitle: homeserver.description == null
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ import 'dart:io';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:flutter_highlighter/flutter_highlighter.dart';
|
||||||
|
import 'package:flutter_highlighter/themes/shades-of-purple.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
|
|
@ -19,14 +20,34 @@ class ErrorReporter {
|
||||||
|
|
||||||
void onErrorCallback(Object error, [StackTrace? stackTrace]) async {
|
void onErrorCallback(Object error, [StackTrace? stackTrace]) async {
|
||||||
Logs().e(message ?? 'Error caught', error, stackTrace);
|
Logs().e(message ?? 'Error caught', error, stackTrace);
|
||||||
final consent = await showOkCancelAlertDialog(
|
final consent = await showAdaptiveDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
title: L10n.of(context)!.reportErrorDescription,
|
builder: (context) => AlertDialog.adaptive(
|
||||||
message: '$error\n${stackTrace ?? ''}',
|
title: Text(L10n.of(context)!.reportErrorDescription),
|
||||||
okLabel: L10n.of(context)!.report,
|
content: SizedBox(
|
||||||
cancelLabel: L10n.of(context)!.close,
|
height: 256,
|
||||||
|
width: 256,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: HighlightView(
|
||||||
|
'$error\n${stackTrace ?? ''}',
|
||||||
|
language: 'sh',
|
||||||
|
theme: shadesOfPurpleTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop<bool>(false),
|
||||||
|
child: Text(L10n.of(context)!.close),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop<bool>(true),
|
||||||
|
child: Text(L10n.of(context)!.report),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
if (consent != OkCancelResult.ok) return;
|
if (consent != true) return;
|
||||||
final os = kIsWeb ? 'web' : Platform.operatingSystem;
|
final os = kIsWeb ? 'web' : Platform.operatingSystem;
|
||||||
final version = await PlatformInfos.getVersion();
|
final version = await PlatformInfos.getVersion();
|
||||||
final description = '''
|
final description = '''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue