-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initialisation error handler to example app
Minor improvements to example app
- Loading branch information
1 parent
b31b096
commit 767581f
Showing
7 changed files
with
187 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
example/lib/screens/initialisation_error/initialisation_error.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:path_provider/path_provider.dart'; | ||
|
||
import '../../main.dart'; | ||
|
||
class InitialisationError extends StatelessWidget { | ||
const InitialisationError({super.key, required this.err}); | ||
|
||
final Object? err; | ||
|
||
@override | ||
Widget build(BuildContext context) => Scaffold( | ||
body: SingleChildScrollView( | ||
padding: const EdgeInsets.all(32), | ||
child: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
const Icon(Icons.error, size: 64), | ||
const SizedBox(height: 12), | ||
Text( | ||
'Whoops, look like FMTC ran into an error initialising', | ||
style: Theme.of(context) | ||
.textTheme | ||
.displaySmall! | ||
.copyWith(color: Colors.white), | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 32), | ||
SelectableText( | ||
'Type: ${err.runtimeType}', | ||
style: Theme.of(context).textTheme.headlineSmall, | ||
textAlign: TextAlign.center, | ||
), | ||
SelectableText( | ||
'Error: $err', | ||
style: Theme.of(context).textTheme.bodyLarge, | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 32), | ||
Text( | ||
'We recommend trying to delete the existing root, as it may ' | ||
'have become corrupt.\nPlease be aware that this will delete ' | ||
'any cached data, and will cause the app to restart.', | ||
style: Theme.of(context) | ||
.textTheme | ||
.bodyLarge! | ||
.copyWith(color: Colors.white), | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 16), | ||
OutlinedButton( | ||
onPressed: () async { | ||
void showFailure() { | ||
if (context.mounted) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text( | ||
"Unfortuately, that didn't work. Try clearing " | ||
"the app's storage and cache manually.", | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
final dir = Directory( | ||
path.join( | ||
(await getApplicationDocumentsDirectory()) | ||
.absolute | ||
.path, | ||
'fmtc', | ||
), | ||
); | ||
|
||
if (!await dir.exists()) { | ||
showFailure(); | ||
return; | ||
} | ||
|
||
try { | ||
await dir.delete(recursive: true); | ||
} on FileSystemException { | ||
showFailure(); | ||
rethrow; | ||
} | ||
|
||
runApp(const SizedBox.shrink()); | ||
|
||
main(); | ||
}, | ||
child: const Text( | ||
'Reset FMTC & attempt re-initialisation', | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters