-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add UpdateLocaleToSettings.dart
- Loading branch information
Showing
3 changed files
with
44 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:locus/services/settings_service/index.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
class UpdateLocaleToSettings extends StatefulWidget { | ||
const UpdateLocaleToSettings({super.key}); | ||
|
||
@override | ||
State<UpdateLocaleToSettings> createState() => _UpdateLocaleToSettingsState(); | ||
} | ||
|
||
class _UpdateLocaleToSettingsState extends State<UpdateLocaleToSettings> { | ||
late final SettingsService _settings; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_settings = context.read<SettingsService>(); | ||
_settings.addListener(_updateLocale); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_settings.removeListener(_updateLocale); | ||
super.dispose(); | ||
} | ||
|
||
void _updateLocale() async { | ||
_settings.localeName = AppLocalizations | ||
.of(context) | ||
.localeName; | ||
|
||
await _settings.save(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const SizedBox.shrink(); | ||
} | ||
} |
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