From 201bf9ded9b7d33ed4825f3a2ffd03e556cbbd0a Mon Sep 17 00:00:00 2001 From: AlexVincent525 Date: Tue, 18 Feb 2020 12:16:37 +0800 Subject: [PATCH] :art: Make the hive boxes clearing can use no context. --- lib/constants/hive_boxes.dart | 17 ++++++++++------- lib/pages/home/my_info_page.dart | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/constants/hive_boxes.dart b/lib/constants/hive_boxes.dart index 9c468bdf..77bdb5a3 100644 --- a/lib/constants/hive_boxes.dart +++ b/lib/constants/hive_boxes.dart @@ -49,13 +49,16 @@ class HiveBoxes { changelogBox = await Hive.openBox('openjmu_changelog'); } - static void clearBoxes(context) async { - final confirm = await ConfirmationBottomSheet.show( - context, - title: '清除应用数据', - showConfirm: true, - content: '清除数据会将您的所有应用内容(包括设置、应用消息)清除。\n确定继续吗?', - ); + static void clearBoxes({context}) async { + bool confirm = true; + if (context != null) { + confirm = await ConfirmationBottomSheet.show( + context, + title: '清除应用数据', + showConfirm: true, + content: '清除数据会将您的所有应用内容(包括设置、应用消息)清除。\n确定继续吗?', + ); + } if (confirm) { debugPrint('Clearing Hive Boxes...'); await appMessagesBox?.clear(); diff --git a/lib/pages/home/my_info_page.dart b/lib/pages/home/my_info_page.dart index fcc36ef0..eadf3be4 100755 --- a/lib/pages/home/my_info_page.dart +++ b/lib/pages/home/my_info_page.dart @@ -425,7 +425,7 @@ class MyInfoPageState extends State { color: Theme.of(context).primaryColor, ), child: GestureDetector( - onLongPress: () => HiveBoxes.clearBoxes(context), + onLongPress: () => HiveBoxes.clearBoxes(context: context), child: Text( '(DANGER)\n清除应用数据', style: TextStyle(