Browse Source

Add setting for timezone

master
Kenneth Bruen 2 years ago
parent
commit
9d2871405d
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 2
      lib/main.dart
  2. 1
      lib/models.dart
  3. 94
      lib/models/ui_timezone.dart
  4. 1
      lib/pages/settings/setings_page.dart
  5. 20
      lib/pages/settings/settings_page_cupertino.dart
  6. 23
      lib/pages/settings/settings_page_fluent.dart
  7. 23
      lib/pages/settings/settings_page_material.dart
  8. 16
      lib/pages/station_arrdep_page/view_station/view_station_cupertino.dart
  9. 19
      lib/pages/station_arrdep_page/view_station/view_station_fluent.dart
  10. 19
      lib/pages/station_arrdep_page/view_station/view_station_material.dart
  11. 17
      lib/pages/train_info_page/view_train/train_info_cupertino_DisplayTrainStation.dart
  12. 16
      lib/pages/train_info_page/view_train/train_info_fluent_DisplayTrainStation.dart
  13. 16
      lib/pages/train_info_page/view_train/train_info_material_DisplayTrainStation.dart
  14. 34
      lib/providers.dart
  15. 7
      pubspec.lock
  16. 1
      pubspec.yaml

2
lib/main.dart

@ -17,8 +17,10 @@ import 'package:info_tren/pages/train_info_page/view_train/train_info.dart';
import 'package:info_tren/pages/train_info_page/select_train/select_train.dart'; import 'package:info_tren/pages/train_info_page/select_train/select_train.dart';
import 'package:info_tren/providers.dart'; import 'package:info_tren/providers.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:timezone/data/latest.dart';
void main() async { void main() async {
initializeTimeZones();
final sharedPreferences = await SharedPreferences.getInstance(); final sharedPreferences = await SharedPreferences.getInstance();
runApp( runApp(
ProviderScope( ProviderScope(

1
lib/models.dart

@ -7,6 +7,7 @@ export 'package:info_tren/models/stations_result.dart';
export 'package:info_tren/models/train_data.dart' hide State; export 'package:info_tren/models/train_data.dart' hide State;
export 'package:info_tren/models/trains_result.dart'; export 'package:info_tren/models/trains_result.dart';
export 'package:info_tren/models/ui_design.dart'; export 'package:info_tren/models/ui_design.dart';
export 'package:info_tren/models/ui_timezone.dart';
import 'package:info_tren/models/train_data.dart' show State; import 'package:info_tren/models/train_data.dart' show State;

94
lib/models/ui_timezone.dart

@ -0,0 +1,94 @@
import 'package:timezone/timezone.dart' as tz;
enum UiTimeZoneType {
ro,
local,
utc,
iana,
}
extension UITimeZoneTypeName on UiTimeZoneType {
String get userInterfaceName => (const {
UiTimeZoneType.iana: 'Fus orar IANA',
UiTimeZoneType.local: 'Local',
UiTimeZoneType.ro: 'România',
UiTimeZoneType.utc: 'UTC',
})[this]!;
}
const Map<UiTimeZoneType, UiTimeZone Function(String)> fromSerStringConstructors = {
UiTimeZoneType.ro: RoUiTimeZone.fromSerString,
UiTimeZoneType.local: LocalUiTimeZone.fromSerString,
UiTimeZoneType.utc: UtcUiTimeZone.fromSerString,
UiTimeZoneType.iana: IanaUiTimeZone.fromSerString,
};
abstract class UiTimeZone {
final UiTimeZoneType type;
const UiTimeZone({required this.type});
DateTime convertDateTime(DateTime dt);
factory UiTimeZone.fromSerString(String ser) {
final arr = ser.split('\n');
return fromSerStringConstructors.map((key, value) => MapEntry(key.name, value))[arr[0]]!(ser);
}
String toSerString() {
return '${type.name}\n';
}
}
class RoUiTimeZone extends UiTimeZone {
static final roTz = tz.getLocation('Europe/Bucharest');
const RoUiTimeZone() : super(type: UiTimeZoneType.ro);
factory RoUiTimeZone.fromSerString(String ser) => const RoUiTimeZone();
@override
DateTime convertDateTime(DateTime dt) {
return tz.TZDateTime.from(dt, roTz);
}
}
class LocalUiTimeZone extends UiTimeZone {
const LocalUiTimeZone() : super(type: UiTimeZoneType.local);
factory LocalUiTimeZone.fromSerString(String ser) => LocalUiTimeZone();
@override
DateTime convertDateTime(DateTime dt) => dt.toLocal();
}
class UtcUiTimeZone extends UiTimeZone {
const UtcUiTimeZone() : super(type: UiTimeZoneType.utc);
factory UtcUiTimeZone.fromSerString(String ser) => UtcUiTimeZone();
@override
DateTime convertDateTime(DateTime dt) => dt.toUtc();
}
class IanaUiTimeZone extends UiTimeZone {
late final tz.Location location;
IanaUiTimeZone({required String ianaName}): super(type: UiTimeZoneType.iana) {
location = tz.getLocation(ianaName);
}
factory IanaUiTimeZone.fromSerString(String ser) => IanaUiTimeZone(
ianaName: ser.split('\n').skip(1).join('\n'),
);
@override
DateTime convertDateTime(DateTime dt) {
return tz.TZDateTime.from(dt, location);
}
@override
String toSerString() {
return '${type.name}\n${location.name}';
}
}

1
lib/pages/settings/setings_page.dart

@ -31,6 +31,7 @@ class SettingsPage extends ConsumerWidget {
abstract class SettingsPageShared extends StatelessWidget { abstract class SettingsPageShared extends StatelessWidget {
final String pageTitle = 'Setări'; final String pageTitle = 'Setări';
final String appearanceTitle = 'Aspect'; final String appearanceTitle = 'Aspect';
final String timeZoneTitle = 'Fus orar';
const SettingsPageShared({super.key}); const SettingsPageShared({super.key});

20
lib/pages/settings/settings_page_cupertino.dart

@ -67,6 +67,26 @@ class SettingsPageCupertino extends SettingsPageShared {
); );
}, },
), ),
Consumer(
builder: (context, ref, _) {
final currentTZ = ref.watch(uiTimeZoneProvider);
return CupertinoListTile(
title: Text(timeZoneTitle),
trailing: Text(currentTZ.type.userInterfaceName),
onTap: () async {
final choice = await singleChoice(
context: context,
choices: UiTimeZoneType.values.where((tz) => tz != UiTimeZoneType.iana).toList(),
labelBuilder: (UiTimeZoneType utzt) => utzt.userInterfaceName,
title: timeZoneTitle,
);
if (choice != null) {
ref.read(uiTimeZoneProvider.notifier).set(UiTimeZone.fromSerString('${choice.name}\n'));
}
},
);
},
),
], ],
), ),
); );

23
lib/pages/settings/settings_page_fluent.dart

@ -34,6 +34,29 @@ class SettingsPageFluent extends SettingsPageShared {
); );
}, },
), ),
Consumer(
builder: (context, ref, _) {
final currentTZ = ref.watch(uiTimeZoneProvider);
return ListTile(
title: Text(timeZoneTitle),
trailing: ComboBox<UiTimeZoneType>(
items: UiTimeZoneType.values.where((tz) => tz != UiTimeZoneType.iana).map((tzt) => ComboBoxItem(
value: tzt,
child: Text(tzt.userInterfaceName),
)).toList(),
value: currentTZ.type,
onChanged: (newTZ) {
if (newTZ != null) {
ref.read(uiTimeZoneProvider.notifier).set(UiTimeZone.fromSerString('${newTZ.name}\n'));
}
else {
ref.read(uiTimeZoneProvider.notifier).set(null);
}
},
),
);
},
),
], ],
), ),
), ),

23
lib/pages/settings/settings_page_material.dart

@ -35,6 +35,29 @@ class SettingsPageMaterial extends SettingsPageShared {
); );
}, },
), ),
Consumer(
builder: (context, ref, _) {
final currentTZ = ref.watch(uiTimeZoneProvider);
return ListTile(
title: Text(timeZoneTitle),
trailing: DropdownButton<UiTimeZoneType>(
items: UiTimeZoneType.values.where((tz) => tz != UiTimeZoneType.iana).map((tzt) => DropdownMenuItem(
value: tzt,
child: Text(tzt.userInterfaceName),
)).toList(),
value: currentTZ.type,
onChanged: (newTZ) {
if (newTZ != null) {
ref.read(uiTimeZoneProvider.notifier).set(UiTimeZone.fromSerString('${newTZ.name}\n'));
}
else {
ref.read(uiTimeZoneProvider.notifier).set(null);
}
},
),
);
},
),
], ],
), ),
), ),

16
lib/pages/station_arrdep_page/view_station/view_station_cupertino.dart

@ -78,7 +78,13 @@ class ViewStationPageCupertino extends ViewStationPageShared {
], ],
), ),
), ),
child: Text('${item.time.toLocal().hour.toString().padLeft(2, '0')}:${item.time.toLocal().minute.toString().padLeft(2, '0')}'), child: Consumer(
builder: (context, ref, _) {
final tz = ref.watch(uiTimeZoneProvider);
final time = tz.convertDateTime(item.time);
return Text('${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}');
},
),
), ),
); );
} }
@ -100,7 +106,13 @@ class ViewStationPageCupertino extends ViewStationPageShared {
], ],
), ),
), ),
child: Text('${item.time.toLocal().hour.toString().padLeft(2, '0')}:${item.time.toLocal().minute.toString().padLeft(2, '0')}'), child: Consumer(
builder: (context, ref, _) {
final tz = ref.watch(uiTimeZoneProvider);
final time = tz.convertDateTime(item.time);
return Text('${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}');
},
),
), ),
); );
} }

19
lib/pages/station_arrdep_page/view_station/view_station_fluent.dart

@ -142,8 +142,12 @@ class ViewStationPageFluent extends ViewStationPageShared {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Text( Consumer(
'${item.time.toLocal().hour.toString().padLeft(2, '0')}:${item.time.toLocal().minute.toString().padLeft(2, '0')}', builder: (context, ref, _) {
final tz = ref.watch(uiTimeZoneProvider);
final time = tz.convertDateTime(item.time);
return Text(
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}',
style: TextStyle( style: TextStyle(
inherit: true, inherit: true,
fontFeatures: const [ fontFeatures: const [
@ -152,14 +156,17 @@ class ViewStationPageFluent extends ViewStationPageShared {
decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null, decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null,
fontSize: item.status.delay != 0 ? 12 : null, fontSize: item.status.delay != 0 ? 12 : null,
), ),
);
},
), ),
if (item.status.delay != 0) Builder( if (item.status.delay != 0) Consumer(
builder: (context) { builder: (context, ref, _) {
final newTime = item.time.add(Duration(minutes: item.status.delay)); final tz = ref.watch(uiTimeZoneProvider);
final newTime = tz.convertDateTime(item.time.add(Duration(minutes: item.status.delay)));
final delay = item.status.delay > 0; final delay = item.status.delay > 0;
return Text( return Text(
'${newTime.toLocal().hour.toString().padLeft(2, '0')}:${newTime.toLocal().minute.toString().padLeft(2, '0')}', '${newTime.hour.toString().padLeft(2, '0')}:${newTime.minute.toString().padLeft(2, '0')}',
style: TextStyle( style: TextStyle(
inherit: true, inherit: true,
fontFeatures: const [ fontFeatures: const [

19
lib/pages/station_arrdep_page/view_station/view_station_material.dart

@ -107,8 +107,12 @@ class ViewStationPageMaterial extends ViewStationPageShared {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Text( Consumer(
'${item.time.toLocal().hour.toString().padLeft(2, '0')}:${item.time.toLocal().minute.toString().padLeft(2, '0')}', builder: (context, ref, _) {
final tz = ref.watch(uiTimeZoneProvider);
final time = tz.convertDateTime(item.time);
return Text(
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}',
style: TextStyle( style: TextStyle(
inherit: true, inherit: true,
fontFeatures: const [ fontFeatures: const [
@ -117,14 +121,17 @@ class ViewStationPageMaterial extends ViewStationPageShared {
decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null, decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null,
fontSize: item.status.delay != 0 ? 12 : null, fontSize: item.status.delay != 0 ? 12 : null,
), ),
);
},
), ),
if (item.status.delay != 0) Builder( if (item.status.delay != 0) Consumer(
builder: (context) { builder: (context, ref, _) {
final newTime = item.time.add(Duration(minutes: item.status.delay)); final tz = ref.watch(uiTimeZoneProvider);
final newTime = tz.convertDateTime(item.time.add(Duration(minutes: item.status.delay)));
final delay = item.status.delay > 0; final delay = item.status.delay > 0;
return Text( return Text(
'${newTime.toLocal().hour.toString().padLeft(2, '0')}:${newTime.toLocal().minute.toString().padLeft(2, '0')}', '${newTime.hour.toString().padLeft(2, '0')}:${newTime.minute.toString().padLeft(2, '0')}',
style: TextStyle( style: TextStyle(
inherit: true, inherit: true,
fontFeatures: const [ fontFeatures: const [

17
lib/pages/train_info_page/view_train/train_info_cupertino_DisplayTrainStation.dart

@ -1,6 +1,8 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:info_tren/components/badge/badge.dart'; import 'package:info_tren/components/badge/badge.dart';
import 'package:info_tren/models.dart'; import 'package:info_tren/models.dart';
import 'package:info_tren/providers.dart';
class DisplayTrainStation extends StatelessWidget { class DisplayTrainStation extends StatelessWidget {
final Station station; final Station station;
@ -156,7 +158,7 @@ class Time extends StatelessWidget {
} }
} }
class ArrivalTime extends StatelessWidget { class ArrivalTime extends ConsumerWidget {
final Station station; final Station station;
final bool finalStation; final bool finalStation;
@ -167,7 +169,9 @@ class ArrivalTime extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final tz = ref.watch(uiTimeZoneProvider);
if (finalStation) { if (finalStation) {
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
@ -187,7 +191,7 @@ class ArrivalTime extends StatelessWidget {
} }
else { else {
final delay = station.arrival!.status?.delay ?? 0; final delay = station.arrival!.status?.delay ?? 0;
final time = station.arrival!.scheduleTime.toLocal(); final time = tz.convertDateTime(station.arrival!.scheduleTime);
if (delay == 0) { if (delay == 0) {
return Text("${time.hour.toString().padLeft(2, "0")}:${time.minute.toString().padLeft(2, "0")}"); return Text("${time.hour.toString().padLeft(2, "0")}:${time.minute.toString().padLeft(2, "0")}");
@ -291,7 +295,7 @@ class StopTime extends StatelessWidget {
} }
} }
class DepartureTime extends StatelessWidget { class DepartureTime extends ConsumerWidget {
final Station station; final Station station;
final bool firstStation; final bool firstStation;
@ -302,7 +306,8 @@ class DepartureTime extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final tz = ref.watch(uiTimeZoneProvider);
if (firstStation) { if (firstStation) {
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
@ -322,7 +327,7 @@ class DepartureTime extends StatelessWidget {
} }
else { else {
final delay = station.departure!.status?.delay ?? 0; final delay = station.departure!.status?.delay ?? 0;
final time = station.departure!.scheduleTime.toLocal(); final time = tz.convertDateTime(station.departure!.scheduleTime);
if (delay == 0) { if (delay == 0) {
return Text("${time.hour.toString().padLeft(2, "0")}:${time.minute.toString().padLeft(2, "0")}"); return Text("${time.hour.toString().padLeft(2, "0")}:${time.minute.toString().padLeft(2, "0")}");

16
lib/pages/train_info_page/view_train/train_info_fluent_DisplayTrainStation.dart

@ -1,6 +1,8 @@
import 'package:fluent_ui/fluent_ui.dart'; import 'package:fluent_ui/fluent_ui.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:info_tren/components/badge/badge.dart'; import 'package:info_tren/components/badge/badge.dart';
import 'package:info_tren/models.dart'; import 'package:info_tren/models.dart';
import 'package:info_tren/providers.dart';
class DisplayTrainStation extends StatelessWidget { class DisplayTrainStation extends StatelessWidget {
final Station station; final Station station;
@ -170,7 +172,7 @@ class Time extends StatelessWidget {
} }
} }
class ArrivalTime extends StatelessWidget { class ArrivalTime extends ConsumerWidget {
final Station station; final Station station;
final bool finalStation; final bool finalStation;
@ -181,7 +183,8 @@ class ArrivalTime extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final tz = ref.watch(uiTimeZoneProvider);
if (station.arrival == null) { if (station.arrival == null) {
return Container(); return Container();
} }
@ -204,7 +207,7 @@ class ArrivalTime extends StatelessWidget {
} }
else { else {
final delay = station.arrival!.status?.delay ?? 0; final delay = station.arrival!.status?.delay ?? 0;
final time = station.arrival!.scheduleTime.toLocal(); final time = tz.convertDateTime(station.arrival!.scheduleTime);
if (delay == 0) { if (delay == 0) {
return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}"); return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}");
@ -309,7 +312,7 @@ class StopTime extends StatelessWidget {
} }
} }
class DepartureTime extends StatelessWidget { class DepartureTime extends ConsumerWidget {
final Station station; final Station station;
final bool firstStation; final bool firstStation;
@ -320,7 +323,8 @@ class DepartureTime extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final tz = ref.watch(uiTimeZoneProvider);
if (station.departure == null) { if (station.departure == null) {
return Container(); return Container();
} }
@ -343,7 +347,7 @@ class DepartureTime extends StatelessWidget {
} }
else { else {
final delay = station.departure!.status?.delay ?? 0; final delay = station.departure!.status?.delay ?? 0;
final time = station.departure!.scheduleTime.toLocal(); final time = tz.convertDateTime(station.departure!.scheduleTime);
if (delay == 0) { if (delay == 0) {
return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}"); return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}");

16
lib/pages/train_info_page/view_train/train_info_material_DisplayTrainStation.dart

@ -1,7 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:info_tren/models.dart'; import 'package:info_tren/models.dart';
import 'package:info_tren/components/badge/badge.dart'; import 'package:info_tren/components/badge/badge.dart';
import 'package:info_tren/pages/train_info_page/view_train/train_info_material.dart'; import 'package:info_tren/pages/train_info_page/view_train/train_info_material.dart';
import 'package:info_tren/providers.dart';
class DisplayTrainStation extends StatelessWidget { class DisplayTrainStation extends StatelessWidget {
final Station station; final Station station;
@ -168,7 +170,7 @@ class Time extends StatelessWidget {
} }
} }
class ArrivalTime extends StatelessWidget { class ArrivalTime extends ConsumerWidget {
final Station station; final Station station;
final bool finalStation; final bool finalStation;
@ -179,7 +181,8 @@ class ArrivalTime extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final tz = ref.watch(uiTimeZoneProvider);
if (station.arrival == null) { if (station.arrival == null) {
return Container(); return Container();
} }
@ -202,7 +205,7 @@ class ArrivalTime extends StatelessWidget {
} }
else { else {
final delay = station.arrival!.status?.delay ?? 0; final delay = station.arrival!.status?.delay ?? 0;
final time = station.arrival!.scheduleTime.toLocal(); final time = tz.convertDateTime(station.arrival!.scheduleTime);
if (delay == 0) { if (delay == 0) {
return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}"); return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}");
@ -305,7 +308,7 @@ class StopTime extends StatelessWidget {
} }
} }
class DepartureTime extends StatelessWidget { class DepartureTime extends ConsumerWidget {
final Station station; final Station station;
final bool firstStation; final bool firstStation;
@ -316,7 +319,8 @@ class DepartureTime extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final tz = ref.watch(uiTimeZoneProvider);
if (station.departure == null) { if (station.departure == null) {
return Container(); return Container();
} }
@ -339,7 +343,7 @@ class DepartureTime extends StatelessWidget {
} }
else { else {
final delay = station.departure!.status?.delay ?? 0; final delay = station.departure!.status?.delay ?? 0;
final time = station.departure!.scheduleTime.toLocal(); final time = tz.convertDateTime(station.departure!.scheduleTime);
if (delay == 0) { if (delay == 0) {
return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}"); return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}");

34
lib/providers.dart

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:developer';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:info_tren/api/station_data.dart'; import 'package:info_tren/api/station_data.dart';
@ -36,6 +37,39 @@ final uiDesignProvider = StateNotifierProvider<UiDesignNotifier, UiDesign>(
(ref) => UiDesignNotifier( (ref) => UiDesignNotifier(
sharedPreferences: ref.watch(sharedPreferencesProvider), sharedPreferences: ref.watch(sharedPreferencesProvider),
), ),
dependencies: [sharedPreferencesProvider],
);
class UiTimeZoneNotifier extends StateNotifier<UiTimeZone> {
final SharedPreferences sharedPreferences;
UiTimeZoneNotifier({required this.sharedPreferences,}) : super(const RoUiTimeZone()) {
final stored = sharedPreferences.getString('uiTimeZone');
if (stored != null) {
try {
state = UiTimeZone.fromSerString(stored);
}
catch (e) {
log('Invalid UiTimeZone ser: $stored, error: $e', level: 1000);
}
}
}
void set(UiTimeZone? timeZone) async {
if (timeZone != null) {
await sharedPreferences.setString('uiTimeZone', timeZone.toSerString());
}
else {
await sharedPreferences.remove('uiTimeZone');
}
state = timeZone ?? const LocalUiTimeZone();
}
}
final uiTimeZoneProvider = StateNotifierProvider<UiTimeZoneNotifier, UiTimeZone>(
(ref) => UiTimeZoneNotifier(
sharedPreferences: ref.watch(sharedPreferencesProvider),
),
dependencies: [sharedPreferencesProvider],
); );
final trainInfoArgumentsProvider = Provider<TrainInfoArguments>( final trainInfoArgumentsProvider = Provider<TrainInfoArguments>(

7
pubspec.lock

@ -616,6 +616,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.1" version: "1.2.1"
timezone:
dependency: "direct main"
description:
name: timezone
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.0"
timing: timing:
dependency: transitive dependency: transitive
description: description:

1
pubspec.yaml

@ -34,6 +34,7 @@ dependencies:
json_annotation: ^4.7.0 json_annotation: ^4.7.0
shared_preferences: ^2.0.15 shared_preferences: ^2.0.15
fluent_ui: ^4.0.3+1 fluent_ui: ^4.0.3+1
timezone: ^0.9.0
dev_dependencies: dev_dependencies:
# flutter_test: # flutter_test:

Loading…
Cancel
Save