Skip to content

Commit

Permalink
refactor: Add UpdateLocaleToSettings.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Oct 11, 2023
1 parent 3d581fc commit 6c0b076
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
42 changes: 42 additions & 0 deletions lib/app_wrappers/UpdateLocaleToSettings.dart
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();
}
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:locus/app_wrappers/LocationHistoryUpdater.dart';
import 'package:locus/app_wrappers/RegisterBackgroundListeners.dart';
import 'package:locus/app_wrappers/UniLinksHandler.dart';
import 'package:locus/app_wrappers/UpdateLastLocationToSettings.dart';
import 'package:locus/app_wrappers/UpdateLocaleToSettings.dart';
import 'package:locus/screens/locations_overview_screen_widgets/LocationFetchers.dart';
import 'package:locus/services/app_update_service.dart';
import 'package:locus/services/current_location_service.dart';
Expand Down Expand Up @@ -104,6 +105,7 @@ void main() async {
UniLinksHandler(),
UpdateLastLocationToSettings(),
RegisterBackgroundListeners(),
UpdateLocaleToSettings(),
App(),
],
),
Expand Down
8 changes: 0 additions & 8 deletions lib/screens/LocationsOverviewScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class _LocationsOverviewScreenState extends State<LocationsOverviewScreen>
..addPostFrameCallback((_) {
_setLocationFromSettings();
initQuickActions(context);
_updateLocaleToSettings();
_showUpdateDialogIfRequired();
_initLiveLocationUpdate();
locationFetchers.fetchPreviewLocations();
Expand Down Expand Up @@ -438,13 +437,6 @@ class _LocationsOverviewScreenState extends State<LocationsOverviewScreen>
});
}

void _updateLocaleToSettings() {
final settingsService = context.read<SettingsService>();

settingsService.localeName = AppLocalizations.of(context).localeName;
settingsService.save();
}

void _showUpdateDialogIfRequired() async {
final l10n = AppLocalizations.of(context);
final appUpdateService = context.read<AppUpdateService>();
Expand Down

0 comments on commit 6c0b076

Please sign in to comment.