Skip to content

Commit 1fae13e

Browse files
authored
[VeggieSeasons] added restore defaults feature (#639)
1 parent f63c465 commit 1fae13e

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

experimental/veggieseasons/lib/data/preferences.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ class Preferences extends ChangeNotifier {
5050
notifyListeners();
5151
}
5252

53+
Future<void> restoreDefaults() async {
54+
final prefs = await SharedPreferences.getInstance();
55+
await prefs.clear();
56+
load();
57+
}
58+
5359
void load() {
5460
_loading = _loadFromSharedPrefs();
5561
}

experimental/veggieseasons/lib/screens/settings.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,44 @@ class SettingsScreen extends StatelessWidget {
213213
);
214214
}
215215

216+
SettingsItem _buildRestoreDefaultsItem(
217+
BuildContext context, Preferences prefs) {
218+
return SettingsItem(
219+
label: 'Restore Defaults',
220+
icon: SettingsIcon(
221+
backgroundColor: CupertinoColors.systemRed,
222+
icon: Styles.resetIcon,
223+
),
224+
content: SettingsNavigationIndicator(),
225+
onPress: () {
226+
showCupertinoDialog<void>(
227+
context: context,
228+
builder: (context) => CupertinoAlertDialog(
229+
title: Text('Are you sure?'),
230+
content: Text(
231+
'Are you sure you want to reset the current settings?',
232+
),
233+
actions: <Widget>[
234+
CupertinoDialogAction(
235+
isDestructiveAction: true,
236+
child: Text('Yes'),
237+
onPressed: () async {
238+
await prefs.restoreDefaults();
239+
Navigator.pop(context);
240+
},
241+
),
242+
CupertinoDialogAction(
243+
isDefaultAction: true,
244+
child: Text('No'),
245+
onPressed: () => Navigator.pop(context),
246+
)
247+
],
248+
),
249+
);
250+
},
251+
);
252+
}
253+
216254
@override
217255
Widget build(BuildContext context) {
218256
final prefs = Provider.of<Preferences>(context);
@@ -238,6 +276,7 @@ class SettingsScreen extends StatelessWidget {
238276
items: [
239277
_buildCaloriesItem(context, prefs),
240278
_buildCategoriesItem(context, prefs),
279+
_buildRestoreDefaultsItem(context, prefs),
241280
],
242281
),
243282
],

experimental/veggieseasons/lib/styles.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ abstract class Styles {
198198
: CupertinoColors.darkBackgroundGray;
199199

200200
static Color settingsLineation(Brightness brightness) =>
201-
brightness == Brightness.light ? Color(0xffbcbbc1) : Color(0xFF4C4B4B);
201+
brightness == Brightness.light ? Color(0xffbcbbc1) : Color(0xff4c4b4b);
202202

203203
static const Color settingsBackground = Color(0xffefeff4);
204204

@@ -214,6 +214,12 @@ abstract class Styles {
214214
fontPackage: CupertinoIcons.iconFontPackage,
215215
);
216216

217+
static const resetIcon = IconData(
218+
0xf4c4,
219+
fontFamily: CupertinoIcons.iconFont,
220+
fontPackage: CupertinoIcons.iconFontPackage,
221+
);
222+
217223
static const calorieIcon = IconData(
218224
0xf3bb,
219225
fontFamily: CupertinoIcons.iconFont,
@@ -230,5 +236,5 @@ abstract class Styles {
230236

231237
static const ColorFilter desaturatedColorFilter =
232238
// 222222 is a random color that has low color saturation.
233-
ColorFilter.mode(Color(0xFF222222), BlendMode.saturation);
239+
ColorFilter.mode(Color(0xff222222), BlendMode.saturation);
234240
}

0 commit comments

Comments
 (0)