Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/pages/my_reports_pages/detail/shared_report_widgets.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:geocoding/geocoding.dart';
import 'package:mosquito_alert_app/utils/UserManager.dart';

/// Shared widgets for report detail pages
class ReportDetailWidgets {
Expand Down Expand Up @@ -141,10 +140,6 @@ class ReportUtils {
// 3. Fallback: Reverse geocoding from coordinates
final point = report.location.point;
try {
var locale = await UserManager.getUserLocale();
if (locale != null) {
await setLocaleIdentifier(locale);
}
final placemarks =
await placemarkFromCoordinates(point.latitude, point.longitude);
if (placemarks.isNotEmpty) {
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/settings_pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ class _SettingsPageState extends State<SettingsPage> {
final locale = Locale(languageCode, countryCode);

Utils.language = locale;
UserManager.setLanguage(languageCode);
UserManager.setLanguageCountry(countryCode);
UserManager.setLocale(locale);
application.onLocaleChanged(locale);

final userProvider = Provider.of<UserProvider>(context, listen: false);
Expand Down
23 changes: 15 additions & 8 deletions lib/utils/UserManager.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:geocoding/geocoding.dart';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:mosquito_alert_app/pages/settings_pages/consent_form.dart';
Expand All @@ -23,8 +24,7 @@ class UserManager {

await prefs.setBool('firstTime', true);

await setLanguage(Utils.language.languageCode);
await setLanguageCountry(Utils.language.countryCode);
await setLocale(Utils.language);

await Navigator.of(context).push(
MaterialPageRoute(
Expand All @@ -47,15 +47,26 @@ class UserManager {
}

//set
static Future<void> setLanguage(language) async {
static Future<void> setLocale(Locale locale) async {
final String languageCode = locale.languageCode;
final String? countryCode = locale.countryCode;

final String localeIdentifier =
countryCode != null ? '${languageCode}_$countryCode' : languageCode;
await setLocaleIdentifier(localeIdentifier); // From geolocator.
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected comment from 'geolocator' to 'geocoding' - the import at line 3 is package:geocoding/geocoding.dart, not geolocator.

Suggested change
await setLocaleIdentifier(localeIdentifier); // From geolocator.
await setLocaleIdentifier(localeIdentifier); // Set locale identifier.

Copilot uses AI. Check for mistakes.
await _setLanguage(languageCode);
await _setLanguageCountry(countryCode ?? '');
}

static Future<void> _setLanguage(String language) async {
var prefs = await SharedPreferences.getInstance();
// NOTE: this is important for DateFormat to work correctly
Intl.defaultLocale = Intl.verifiedLocale(language, DateFormat.localeExists,
onFailure: (newLocale) => 'en');
await prefs.setString('language', language);
}

static Future<void> setLanguageCountry(lngCountry) async {
static Future<void> _setLanguageCountry(String lngCountry) async {
var prefs = await SharedPreferences.getInstance();
await prefs.setString('languageCountry', lngCountry);
}
Expand Down Expand Up @@ -89,10 +100,6 @@ class UserManager {
return prefs.getString('languageCountry');
}

static Future<String?> getUserLocale() async {
return '${await UserManager.getLanguage()}_${await UserManager.getLanguageCountry()}';
}

static Future<void> migrateHashtagToHashtags() async {
final prefs = await SharedPreferences.getInstance();

Expand Down
Loading