Skip to content

Commit

Permalink
[VeggieSeasons] added restore defaults feature (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharojha authored Jan 31, 2021
1 parent f63c465 commit 1fae13e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
6 changes: 6 additions & 0 deletions experimental/veggieseasons/lib/data/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class Preferences extends ChangeNotifier {
notifyListeners();
}

Future<void> restoreDefaults() async {
final prefs = await SharedPreferences.getInstance();
await prefs.clear();
load();
}

void load() {
_loading = _loadFromSharedPrefs();
}
Expand Down
39 changes: 39 additions & 0 deletions experimental/veggieseasons/lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,44 @@ class SettingsScreen extends StatelessWidget {
);
}

SettingsItem _buildRestoreDefaultsItem(
BuildContext context, Preferences prefs) {
return SettingsItem(
label: 'Restore Defaults',
icon: SettingsIcon(
backgroundColor: CupertinoColors.systemRed,
icon: Styles.resetIcon,
),
content: SettingsNavigationIndicator(),
onPress: () {
showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Are you sure?'),
content: Text(
'Are you sure you want to reset the current settings?',
),
actions: <Widget>[
CupertinoDialogAction(
isDestructiveAction: true,
child: Text('Yes'),
onPressed: () async {
await prefs.restoreDefaults();
Navigator.pop(context);
},
),
CupertinoDialogAction(
isDefaultAction: true,
child: Text('No'),
onPressed: () => Navigator.pop(context),
)
],
),
);
},
);
}

@override
Widget build(BuildContext context) {
final prefs = Provider.of<Preferences>(context);
Expand All @@ -238,6 +276,7 @@ class SettingsScreen extends StatelessWidget {
items: [
_buildCaloriesItem(context, prefs),
_buildCategoriesItem(context, prefs),
_buildRestoreDefaultsItem(context, prefs),
],
),
],
Expand Down
10 changes: 8 additions & 2 deletions experimental/veggieseasons/lib/styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ abstract class Styles {
: CupertinoColors.darkBackgroundGray;

static Color settingsLineation(Brightness brightness) =>
brightness == Brightness.light ? Color(0xffbcbbc1) : Color(0xFF4C4B4B);
brightness == Brightness.light ? Color(0xffbcbbc1) : Color(0xff4c4b4b);

static const Color settingsBackground = Color(0xffefeff4);

Expand All @@ -214,6 +214,12 @@ abstract class Styles {
fontPackage: CupertinoIcons.iconFontPackage,
);

static const resetIcon = IconData(
0xf4c4,
fontFamily: CupertinoIcons.iconFont,
fontPackage: CupertinoIcons.iconFontPackage,
);

static const calorieIcon = IconData(
0xf3bb,
fontFamily: CupertinoIcons.iconFont,
Expand All @@ -230,5 +236,5 @@ abstract class Styles {

static const ColorFilter desaturatedColorFilter =
// 222222 is a random color that has low color saturation.
ColorFilter.mode(Color(0xFF222222), BlendMode.saturation);
ColorFilter.mode(Color(0xff222222), BlendMode.saturation);
}

0 comments on commit 1fae13e

Please sign in to comment.