-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Devtools extension: Button to clear database
This drops contents and then calls beforeOpen, reinitializing the database with the current migration. Closes #3276
- Loading branch information
Showing
5 changed files
with
96 additions
and
0 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
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,60 @@ | ||
import 'package:devtools_app_shared/ui.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import 'details.dart'; | ||
|
||
class ClearDatabaseButton extends ConsumerStatefulWidget { | ||
const ClearDatabaseButton({super.key}); | ||
|
||
@override | ||
ConsumerState<ClearDatabaseButton> createState() => | ||
_ClearDatabaseButtonState(); | ||
} | ||
|
||
class _ClearDatabaseButtonState extends ConsumerState<ClearDatabaseButton> { | ||
Future<void>? _pendingClear = null; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return DevToolsButton( | ||
onPressed: () { | ||
showDevToolsDialog( | ||
context: context, | ||
title: 'Confirm deletion', | ||
content: const Text( | ||
'This will delete contents of the database and then re-create it. ' | ||
'All current database data will be lost. Continue?', | ||
), | ||
actions: [ | ||
DevToolsButton( | ||
onPressed: _pendingClear != null | ||
? null | ||
: () { | ||
setState(() { | ||
_pendingClear = Future(() async { | ||
final database = ref.read(loadedDatabase); | ||
await database.value!.clear(); | ||
}) | ||
.whenComplete( | ||
() => setState(() => _pendingClear = null)) | ||
.then((_) { | ||
if (mounted) { | ||
// ignore: use_build_context_synchronously | ||
Navigator.pop(context); | ||
} | ||
}); | ||
}); | ||
}, | ||
label: 'Confirm deletion', | ||
color: Colors.redAccent, | ||
), | ||
], | ||
); | ||
}, | ||
label: 'Clear database', | ||
color: Colors.redAccent, | ||
icon: Icons.delete, | ||
); | ||
} | ||
} |
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