chore(recovery): small refactoring of recovery mode implementation

[skip ci]
This commit is contained in:
Jagandeep Brar
2022-09-27 22:53:49 -04:00
parent 6eff6c902c
commit 8788f76e5c
4 changed files with 44 additions and 26 deletions

View File

@@ -51,7 +51,7 @@ abstract class RecoveryActionTile extends StatelessWidget {
builder: (context) => const SimpleDialog(
title: Text('Success'),
children: [
Text('Action Completed Successfully'),
Text('Action completed successfully.'),
],
contentPadding: EdgeInsets.only(
left: 24.0,
@@ -87,14 +87,32 @@ abstract class RecoveryActionTile extends StatelessWidget {
context: context,
builder: (context) => AlertDialog(
title: const Text('Are You Sure?'),
content: const Text('Are you sure you want to do this action?'),
content: RichText(
text: TextSpan(
children: [
const TextSpan(text: 'Are you sure you want to '),
TextSpan(text: description.toLowerCase()),
const TextSpan(text: '?'),
],
),
),
actions: [
TextButton(
onPressed: Navigator.of(context).pop,
child: const Text(
'Cancel',
style: TextStyle(color: Colors.white),
),
),
TextButton(
onPressed: () {
result = true;
Navigator.of(context).pop();
},
child: const Text('Confirm'),
child: const Text(
'Confirm',
style: TextStyle(color: Colors.red),
),
)
],
),

View File

@@ -5,10 +5,9 @@ import 'package:lunasea/system/recovery_mode/action_tile.dart';
class BootstrapTile extends RecoveryActionTile {
const BootstrapTile({
super.key,
}) : super(
title: 'Bootstrap LunaSea',
description: 'Run the bootstrap process and show any errors',
);
super.title = 'Bootstrap LunaSea',
super.description = 'Run the bootstrap process and show any errors',
});
@override
Future<void> action(BuildContext context) async {

View File

@@ -5,11 +5,10 @@ import 'package:lunasea/system/recovery_mode/action_tile.dart';
class ClearDatabaseTile extends RecoveryActionTile {
const ClearDatabaseTile({
super.key,
}) : super(
title: 'Clear Database',
description: 'Clear all configured settings and modules',
showConfirmDialog: true,
);
super.title = 'Clear Database',
super.description = 'Clear all configured settings and modules',
super.showConfirmDialog = true,
});
@override
Future<void> action(BuildContext context) async {

View File

@@ -11,7 +11,10 @@ class LunaRecoveryMode extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: _home(),
darkTheme: ThemeData(brightness: Brightness.dark),
darkTheme: ThemeData(
brightness: Brightness.dark,
useMaterial3: true,
),
themeMode: ThemeMode.dark,
);
}
@@ -29,8 +32,8 @@ class LunaRecoveryMode extends StatelessWidget {
);
}
Widget _motd() {
return const Padding(
SliverToBoxAdapter _motd() {
return const SliverToBoxAdapter(
child: Center(
child: Text(
'To exit please fully close and restart the application.',
@@ -40,7 +43,6 @@ class LunaRecoveryMode extends StatelessWidget {
),
),
),
padding: EdgeInsets.all(12.0),
);
}
@@ -50,16 +52,16 @@ class LunaRecoveryMode extends StatelessWidget {
ClearDatabaseTile(),
];
return ListView.separated(
itemCount: actions.length + 1,
itemBuilder: (context, idx) {
if (idx == 0) return _motd();
return actions[idx - 1];
},
separatorBuilder: (context, idx) {
if (idx == 0) return const SizedBox();
return const Divider();
},
return CustomScrollView(
slivers: [
SliverPadding(
sliver: _motd(),
padding: const EdgeInsets.all(12.0),
),
SliverList(
delegate: SliverChildListDelegate(actions),
),
],
);
}
}