Catch exceptions and show them in logs
This commit is contained in:
parent
7f0200885c
commit
b0021f82ac
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:dartssh2/dartssh2.dart';
|
import 'package:dartssh2/dartssh2.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -21,6 +22,21 @@ import 'authentik_api.dart' as authentik;
|
|||||||
import 'package:app_links/app_links.dart';
|
import 'package:app_links/app_links.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
final errorNotifier = ValueNotifier<String?>(null);
|
||||||
|
|
||||||
|
// Fehler-Handler registrieren
|
||||||
|
PlatformDispatcher.instance.onError = (error, stack) {
|
||||||
|
final timeStr = DateTime.now().toIso8601String();
|
||||||
|
final errorMessage = 'Time: $timeStr\nError: $error\nStack: $stack';
|
||||||
|
|
||||||
|
if (errorNotifier.value == null) {
|
||||||
|
errorNotifier.value = errorMessage;
|
||||||
|
} else {
|
||||||
|
errorNotifier.value = errorNotifier.value! + '\n\n' + errorMessage;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
@ -28,7 +44,7 @@ void main() {
|
|||||||
create: (context) => AuthentikUserSettingsChangeDialogState(),
|
create: (context) => AuthentikUserSettingsChangeDialogState(),
|
||||||
), // Do something (navigation, ...)
|
), // Do something (navigation, ...)
|
||||||
],
|
],
|
||||||
child: const MyApp(),
|
child: MyApp(errorNotifier: errorNotifier),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -57,7 +73,9 @@ String encodePublicKey(OpenSSHEd25519KeyPair keyPair, {String comment = ''}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
final ValueNotifier<String?> errorNotifier;
|
||||||
|
|
||||||
|
const MyApp({super.key, required this.errorNotifier});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -66,15 +84,23 @@ class MyApp extends StatelessWidget {
|
|||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.yellow),
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.yellow),
|
||||||
),
|
),
|
||||||
home: const MyHomePage(title: 'LeineLab e.V. Key App'),
|
home: MyHomePage(
|
||||||
|
title: 'LeineLab e.V. Key App',
|
||||||
|
errorNotifier: errorNotifier,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatefulWidget {
|
||||||
const MyHomePage({super.key, required this.title});
|
const MyHomePage({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.errorNotifier,
|
||||||
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
|
final ValueNotifier<String?> errorNotifier;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
State<MyHomePage> createState() => _MyHomePageState();
|
||||||
@ -402,6 +428,31 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final bodyComponentLogs = Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.all(20),
|
||||||
|
child: Card(
|
||||||
|
child: ValueListenableBuilder<String?>(
|
||||||
|
valueListenable: widget.errorNotifier,
|
||||||
|
builder: (context, error, child) {
|
||||||
|
if (error != null) {
|
||||||
|
return Text(
|
||||||
|
"Error: $error",
|
||||||
|
style: TextStyle(color: Colors.red, fontSize: 15),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Text("No exceptions captured yet.");
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
final actionButtonInfo = FloatingActionButton(
|
final actionButtonInfo = FloatingActionButton(
|
||||||
onPressed: () => obtainKeyPair(regenerate: true),
|
onPressed: () => obtainKeyPair(regenerate: true),
|
||||||
tooltip: 'Regenerate Key',
|
tooltip: 'Regenerate Key',
|
||||||
@ -419,6 +470,10 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
// Info page
|
// Info page
|
||||||
bodyComponent = bodyComponentInfo;
|
bodyComponent = bodyComponentInfo;
|
||||||
actionButton = actionButtonInfo;
|
actionButton = actionButtonInfo;
|
||||||
|
} else if (navIndex == 2) {
|
||||||
|
// Logs page
|
||||||
|
bodyComponent = bodyComponentLogs;
|
||||||
|
actionButton = null;
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Unknown navIndex: $navIndex');
|
throw Exception('Unknown navIndex: $navIndex');
|
||||||
}
|
}
|
||||||
@ -456,6 +511,15 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
ListTile(
|
||||||
|
title: const Text('Logs'),
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
navIndex = 2;
|
||||||
|
});
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user