-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add visualization settings provider and improve UI
- Loading branch information
夏一飞
authored and
夏一飞
committed
Oct 30, 2024
1 parent
938b09b
commit fcd68f4
Showing
15 changed files
with
586 additions
and
285 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,36 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
enum TimeRange { threeMonths, sixMonths, oneYear, all } | ||
|
||
class VisualizationSettingsProvider with ChangeNotifier { | ||
TimeRange _selectedTimeRange = TimeRange.all; | ||
static const String _timeRangeKey = 'selected_time_range'; | ||
|
||
TimeRange get selectedTimeRange => _selectedTimeRange; | ||
|
||
VisualizationSettingsProvider() { | ||
_loadSettings(); | ||
} | ||
|
||
Future<void> _loadSettings() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
final savedRange = prefs.getString(_timeRangeKey); | ||
if (savedRange != null) { | ||
_selectedTimeRange = TimeRange.values.firstWhere( | ||
(e) => e.toString() == savedRange, | ||
orElse: () => TimeRange.all, | ||
); | ||
notifyListeners(); | ||
} | ||
} | ||
|
||
Future<void> setTimeRange(TimeRange range) async { | ||
if (_selectedTimeRange != range) { | ||
_selectedTimeRange = range; | ||
final prefs = await SharedPreferences.getInstance(); | ||
await prefs.setString(_timeRangeKey, range.toString()); | ||
notifyListeners(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.