Skip to content

Commit

Permalink
Add clearSharedPrefs()
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitaprasad committed Sep 8, 2024
1 parent 3fa51a3 commit 8820d26
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions integration_test/test_helper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:apidash/models/settings_model.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/services/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -132,6 +133,7 @@ void apidashWidgetTest(
size: width != null ? Size(width, kMinWindowSize.height) : null);
await ApidashTestHelper.loadApp(widgetTester);
await test(widgetTester, ApidashTestHelper(widgetTester));
await clearSharedPrefs();
},
semanticsEnabled: false,
);
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/settings_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/providers.dart';
import '../services/services.dart';
import '../widgets/widgets.dart';
import '../common/utils.dart';
import '../consts.dart';
Expand Down Expand Up @@ -206,6 +207,7 @@ class SettingsPage extends ConsumerWidget {
TextButton(
onPressed: () async {
Navigator.pop(context, 'Yes');
await clearSharedPrefs();
await ref
.read(collectionStateNotifierProvider
.notifier)
Expand Down
5 changes: 5 additions & 0 deletions lib/services/shared_preferences_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ Future<void> setSettingsToSharedPrefs(SettingsModel settingsModel) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(kSharedPrefSettingsKey, settingsModel.toString());
}

Future<void> clearSharedPrefs() async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(kSharedPrefSettingsKey);
}

0 comments on commit 8820d26

Please sign in to comment.