Skip to content

Commit b07ff23

Browse files
committed
formatting
1 parent f81bc28 commit b07ff23

File tree

9 files changed

+247
-203
lines changed

9 files changed

+247
-203
lines changed

example/lib/global_example.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class MyApp extends StatelessWidget {
5656
theme: ThemeData(
5757
primarySwatch: Colors.blue,
5858
// Use global settings directly in theme configuration
59-
brightness: GlobalSettings.getString('ui.theme') == 'dark'
60-
? Brightness.dark
59+
brightness: GlobalSettings.getString('ui.theme') == 'dark'
60+
? Brightness.dark
6161
: Brightness.light,
6262
),
6363
home: const HomePage(),
@@ -73,30 +73,29 @@ class HomePage extends StatefulWidget {
7373
}
7474

7575
class HomePageState extends State<HomePage> {
76-
7776
@override
7877
void initState() {
7978
super.initState();
80-
79+
8180
// Listen to changes in settings
8281
GlobalSettings.addChangeCallback((key, oldValue, newValue) {
8382
// Use debugPrint instead of print for better Flutter integration
8483
debugPrint('Setting changed: $key from $oldValue to $newValue');
85-
84+
8685
// Rebuild UI when theme changes
8786
if (key == 'ui.theme') {
8887
setState(() {});
8988
}
9089
});
91-
90+
9291
// Demonstrate adding a group after initialization
9392
_addNewFeatureGroup();
9493
}
9594

9695
Future<void> _addNewFeatureGroup() async {
9796
// Simulate adding a new feature after app startup
9897
await Future.delayed(Duration(seconds: 2));
99-
98+
10099
try {
101100
await GlobalSettings.addGroup('newFeature', [
102101
BoolSetting(key: 'enabled', defaultValue: false),
@@ -113,8 +112,8 @@ class HomePageState extends State<HomePage> {
113112
return Scaffold(
114113
appBar: AppBar(
115114
title: Text('Global Settings Demo'),
116-
backgroundColor: GlobalSettings.getString('ui.theme') == 'dark'
117-
? Colors.grey[800]
115+
backgroundColor: GlobalSettings.getString('ui.theme') == 'dark'
116+
? Colors.grey[800]
118117
: Colors.blue,
119118
),
120119
body: Padding(
@@ -127,7 +126,7 @@ class HomePageState extends State<HomePage> {
127126
style: Theme.of(context).textTheme.headlineSmall,
128127
),
129128
SizedBox(height: 16),
130-
129+
131130
// Sound toggle - access GlobalSettings directly
132131
SwitchListTile(
133132
title: Text('Sound Enabled'),
@@ -137,10 +136,11 @@ class HomePageState extends State<HomePage> {
137136
setState(() {});
138137
},
139138
),
140-
139+
141140
// Volume slider
142141
ListTile(
143-
title: Text('Volume: ${(GlobalSettings.getDouble('game.volume') * 100).round()}%'),
142+
title: Text(
143+
'Volume: ${(GlobalSettings.getDouble('game.volume') * 100).round()}%'),
144144
subtitle: Slider(
145145
value: GlobalSettings.getDouble('game.volume'),
146146
onChanged: (value) async {
@@ -149,7 +149,7 @@ class HomePageState extends State<HomePage> {
149149
},
150150
),
151151
),
152-
152+
153153
// Difficulty selector
154154
ListTile(
155155
title: Text('Difficulty'),
@@ -168,14 +168,14 @@ class HomePageState extends State<HomePage> {
168168
},
169169
),
170170
),
171-
171+
172172
SizedBox(height: 24),
173173
Text(
174174
'UI Settings',
175175
style: Theme.of(context).textTheme.headlineSmall,
176176
),
177177
SizedBox(height: 16),
178-
178+
179179
// Theme selector
180180
ListTile(
181181
title: Text('Theme'),
@@ -194,7 +194,7 @@ class HomePageState extends State<HomePage> {
194194
},
195195
),
196196
),
197-
197+
198198
// Animation toggle
199199
SwitchListTile(
200200
title: Text('Show Animations'),
@@ -204,9 +204,9 @@ class HomePageState extends State<HomePage> {
204204
setState(() {});
205205
},
206206
),
207-
207+
208208
SizedBox(height: 24),
209-
209+
210210
// Action buttons
211211
Row(
212212
children: [
@@ -239,9 +239,9 @@ class HomePageState extends State<HomePage> {
239239
),
240240
],
241241
),
242-
242+
243243
SizedBox(height: 24),
244-
244+
245245
// Show new feature settings if available
246246
if (GlobalSettings.hasGroup('newFeature')) ...[
247247
Text(
@@ -263,11 +263,11 @@ class HomePageState extends State<HomePage> {
263263
),
264264
);
265265
}
266-
266+
267267
@override
268268
void dispose() {
269269
// Clean up when the app closes
270270
GlobalSettings.dispose();
271271
super.dispose();
272272
}
273-
}
273+
}

example/lib/main.dart

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void main() async {
1212
// Initialize store and settings
1313
store = SettingsStore();
1414
settings = Settings(store: store);
15-
15+
1616
// Define your settings groups with both function and class validators
1717
gameSettings = SettingsGroup(
1818
key: 'game',
@@ -88,16 +88,16 @@ class _SettingsDemoState extends State<SettingsDemo> {
8888
void initState() {
8989
super.initState();
9090
_loadSettings();
91-
91+
9292
// Listen to changes
9393
gameSettings['soundEnabled']?.stream.listen((value) {
9494
setState(() => _soundEnabled = value);
9595
});
96-
96+
9797
gameSettings['volume']?.stream.listen((value) {
9898
setState(() => _volume = value);
9999
});
100-
100+
101101
uiSettings['theme']?.stream.listen((value) {
102102
setState(() => _theme = value);
103103
});
@@ -135,7 +135,7 @@ class _SettingsDemoState extends State<SettingsDemo> {
135135
),
136136
),
137137
const SizedBox(height: 16),
138-
138+
139139
// Sound Enabled
140140
Card(
141141
color: _theme == 'dark' ? Colors.grey[800] : Colors.white,
@@ -149,7 +149,8 @@ class _SettingsDemoState extends State<SettingsDemo> {
149149
subtitle: Text(
150150
'Enable or disable game sounds',
151151
style: TextStyle(
152-
color: _theme == 'dark' ? Colors.grey[300] : Colors.grey[600],
152+
color:
153+
_theme == 'dark' ? Colors.grey[300] : Colors.grey[600],
153154
),
154155
),
155156
value: _soundEnabled,
@@ -158,7 +159,7 @@ class _SettingsDemoState extends State<SettingsDemo> {
158159
},
159160
),
160161
),
161-
162+
162163
// Volume
163164
Card(
164165
color: _theme == 'dark' ? Colors.grey[800] : Colors.white,
@@ -175,13 +176,15 @@ class _SettingsDemoState extends State<SettingsDemo> {
175176
max: 1.0,
176177
divisions: 10,
177178
label: '${(_volume * 100).round()}%',
178-
onChanged: _soundEnabled ? (value) async {
179-
await settings.setDouble('game.volume', value);
180-
} : null,
179+
onChanged: _soundEnabled
180+
? (value) async {
181+
await settings.setDouble('game.volume', value);
182+
}
183+
: null,
181184
),
182185
),
183186
),
184-
187+
185188
// Difficulty
186189
Card(
187190
color: _theme == 'dark' ? Colors.grey[800] : Colors.white,
@@ -206,9 +209,9 @@ class _SettingsDemoState extends State<SettingsDemo> {
206209
),
207210
),
208211
),
209-
212+
210213
const SizedBox(height: 32),
211-
214+
212215
Text(
213216
'UI Settings',
214217
style: TextStyle(
@@ -218,7 +221,7 @@ class _SettingsDemoState extends State<SettingsDemo> {
218221
),
219222
),
220223
const SizedBox(height: 16),
221-
224+
222225
// Theme
223226
Card(
224227
color: _theme == 'dark' ? Colors.grey[800] : Colors.white,
@@ -231,12 +234,14 @@ class _SettingsDemoState extends State<SettingsDemo> {
231234
),
232235
subtitle: DropdownButton<String>(
233236
value: _theme,
234-
dropdownColor: _theme == 'dark' ? Colors.grey[800] : Colors.white,
237+
dropdownColor:
238+
_theme == 'dark' ? Colors.grey[800] : Colors.white,
235239
items: ['light', 'dark', 'auto'].map((theme) {
236240
return DropdownMenuItem(
237241
value: theme,
238242
child: Text(
239-
theme.substring(0, 1).toUpperCase() + theme.substring(1),
243+
theme.substring(0, 1).toUpperCase() +
244+
theme.substring(1),
240245
style: TextStyle(
241246
color: _theme == 'dark' ? Colors.white : Colors.black,
242247
),
@@ -251,7 +256,7 @@ class _SettingsDemoState extends State<SettingsDemo> {
251256
),
252257
),
253258
),
254-
259+
255260
// Notifications
256261
Card(
257262
color: _theme == 'dark' ? Colors.grey[800] : Colors.white,
@@ -265,7 +270,8 @@ class _SettingsDemoState extends State<SettingsDemo> {
265270
subtitle: Text(
266271
'Enable push notifications',
267272
style: TextStyle(
268-
color: _theme == 'dark' ? Colors.grey[300] : Colors.grey[600],
273+
color:
274+
_theme == 'dark' ? Colors.grey[300] : Colors.grey[600],
269275
),
270276
),
271277
value: _notifications,
@@ -275,9 +281,9 @@ class _SettingsDemoState extends State<SettingsDemo> {
275281
},
276282
),
277283
),
278-
284+
279285
const SizedBox(height: 32),
280-
286+
281287
// Reset buttons
282288
Row(
283289
children: [

lib/src/exceptions.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@ class SettingsNotReadyException implements Exception {
123123
class SettingRecoveryException implements Exception {
124124
/// The setting key that failed recovery.
125125
final String settingKey;
126-
126+
127127
/// The invalid value that was stored.
128128
final dynamic invalidValue;
129-
129+
130130
/// The original validation error.
131131
final String validationError;
132-
132+
133133
/// The recovery error that occurred.
134134
final dynamic recoveryError;
135-
135+
136136
/// Descriptive error message.
137137
final String message;
138138

@@ -147,4 +147,4 @@ class SettingRecoveryException implements Exception {
147147

148148
@override
149149
String toString() => 'SettingRecoveryException: $message';
150-
}
150+
}

0 commit comments

Comments
 (0)