Compare commits
2 commits
2456f7cbda
...
9d2871405d
Author | SHA1 | Date | |
---|---|---|---|
9d2871405d | |||
9637551d7a |
23 changed files with 353 additions and 145 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:info_tren/components/cupertino_divider.dart';
|
||||
import 'package:info_tren/components/select_train_suggestions/select_train_suggestions.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
|
||||
class SelectTrainSuggestionsCupertino extends SelectTrainSuggestionsShared {
|
||||
|
@ -69,8 +70,8 @@ class OperatorAutocompleteTileCupertino extends OperatorAutocompleteTile {
|
|||
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 10, fontWeight: FontWeight.w200),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
Text(
|
||||
"${train.rank} ${train.number}",
|
||||
Text.rich(
|
||||
trainIdSpan(rank: train.rank, number: train.number),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
],
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:info_tren/components/select_train_suggestions/select_train_suggestions.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
|
||||
class SelectTrainSuggestionsFluent extends SelectTrainSuggestionsShared {
|
||||
|
@ -68,8 +69,8 @@ class OperatorAutocompleteTileFluent extends OperatorAutocompleteTile {
|
|||
style: FluentTheme.of(context).typography.body?.copyWith(fontSize: 10, fontWeight: FontWeight.w200),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
Text(
|
||||
"${train.rank} ${train.number}",
|
||||
Text.rich(
|
||||
trainIdSpan(rank: train.rank, number: train.number),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
],
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:info_tren/components/select_train_suggestions/select_train_suggestions.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
|
||||
class SelectTrainSuggestionsMaterial extends SelectTrainSuggestionsShared {
|
||||
|
@ -44,7 +45,7 @@ class OperatorAutocompleteTileMaterial extends OperatorAutocompleteTile {
|
|||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
dense: true,
|
||||
title: Text("${train.rank} ${train.number}"),
|
||||
title: Text.rich(trainIdSpan(rank: train.rank, number: train.number)),
|
||||
subtitle: Text(operatorName),
|
||||
onTap: () {
|
||||
onTrainSelected(train.number);
|
||||
|
|
39
lib/components/train_id_text_span.dart
Normal file
39
lib/components/train_id_text_span.dart
Normal file
|
@ -0,0 +1,39 @@
|
|||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
TextSpan trainIdSpan({
|
||||
required String rank,
|
||||
required String number,
|
||||
Locale? locale,
|
||||
MouseCursor? mouseCursor,
|
||||
void Function(PointerEnterEvent)? onEnter,
|
||||
void Function(PointerExitEvent)? onExit,
|
||||
GestureRecognizer? recognizer,
|
||||
String? semanticsLabel,
|
||||
bool? spellOut,
|
||||
TextStyle? style,
|
||||
}) => TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: rank,
|
||||
style: TextStyle(
|
||||
inherit: true,
|
||||
color: rank.startsWith('IC')
|
||||
? const Color.fromARGB(255, 0, 255, 0)
|
||||
: rank.startsWith('IR')
|
||||
? const Color.fromARGB(255, 255, 0, 0)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(text: number),
|
||||
],
|
||||
locale: locale,
|
||||
mouseCursor: mouseCursor,
|
||||
onEnter: onEnter,
|
||||
onExit: onExit,
|
||||
recognizer: recognizer,
|
||||
semanticsLabel: semanticsLabel,
|
||||
spellOut: spellOut,
|
||||
style: style,
|
||||
);
|
|
@ -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/providers.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:timezone/data/latest.dart';
|
||||
|
||||
void main() async {
|
||||
initializeTimeZones();
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
runApp(
|
||||
ProviderScope(
|
||||
|
|
|
@ -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/trains_result.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;
|
||||
|
||||
|
|
94
lib/models/ui_timezone.dart
Normal file
94
lib/models/ui_timezone.dart
Normal file
|
@ -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}';
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ class SettingsPage extends ConsumerWidget {
|
|||
abstract class SettingsPageShared extends StatelessWidget {
|
||||
final String pageTitle = 'Setări';
|
||||
final String appearanceTitle = 'Aspect';
|
||||
final String timeZoneTitle = 'Fus orar';
|
||||
|
||||
const SettingsPageShared({super.key});
|
||||
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||
import 'package:info_tren/components/loading/loading.dart';
|
||||
import 'package:info_tren/components/refresh_future_builder.dart';
|
||||
import 'package:info_tren/components/sliver_persistent_header_padding.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
import 'package:info_tren/pages/station_arrdep_page/view_station/view_station.dart';
|
||||
import 'package:info_tren/providers.dart';
|
||||
|
@ -66,18 +67,7 @@ class ViewStationPageCupertino extends ViewStationPageShared {
|
|||
onTap: () => onTrainTapped(context, item.train),
|
||||
child: CupertinoFormRow(
|
||||
prefix: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: item.train.rank,
|
||||
style: TextStyle(
|
||||
color: item.train.rank.startsWith('IR') ? const Color.fromARGB(255, 255, 0, 0) : null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(text: item.train.number,),
|
||||
],
|
||||
),
|
||||
trainIdSpan(rank: item.train.rank, number: item.train.number),
|
||||
),
|
||||
helper: Text.rich(
|
||||
TextSpan(
|
||||
|
@ -88,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')}');
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -99,18 +95,7 @@ class ViewStationPageCupertino extends ViewStationPageShared {
|
|||
onTap: () => onTrainTapped(context, item.train),
|
||||
child: CupertinoFormRow(
|
||||
prefix: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: item.train.rank,
|
||||
style: TextStyle(
|
||||
color: item.train.rank.startsWith('IR') ? const Color.fromARGB(255, 255, 0, 0) : null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(text: item.train.number,),
|
||||
],
|
||||
),
|
||||
trainIdSpan(rank: item.train.rank, number: item.train.number),
|
||||
),
|
||||
helper: Text.rich(
|
||||
TextSpan(
|
||||
|
@ -121,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')}');
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||
import 'package:info_tren/components/badge/badge.dart';
|
||||
import 'package:info_tren/components/loading/loading.dart';
|
||||
import 'package:info_tren/components/refresh_future_builder.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
import 'package:info_tren/pages/station_arrdep_page/view_station/view_station.dart';
|
||||
import 'package:info_tren/providers.dart';
|
||||
|
@ -141,24 +142,31 @@ class ViewStationPageFluent extends ViewStationPageShared {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${item.time.toLocal().hour.toString().padLeft(2, '0')}:${item.time.toLocal().minute.toString().padLeft(2, '0')}',
|
||||
style: TextStyle(
|
||||
inherit: true,
|
||||
fontFeatures: const [
|
||||
FontFeature.tabularFigures(),
|
||||
],
|
||||
decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null,
|
||||
fontSize: item.status.delay != 0 ? 12 : null,
|
||||
),
|
||||
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')}',
|
||||
style: TextStyle(
|
||||
inherit: true,
|
||||
fontFeatures: const [
|
||||
FontFeature.tabularFigures(),
|
||||
],
|
||||
decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null,
|
||||
fontSize: item.status.delay != 0 ? 12 : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (item.status.delay != 0) Builder(
|
||||
builder: (context) {
|
||||
final newTime = item.time.add(Duration(minutes: item.status.delay));
|
||||
if (item.status.delay != 0) Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
final newTime = tz.convertDateTime(item.time.add(Duration(minutes: item.status.delay)));
|
||||
final delay = item.status.delay > 0;
|
||||
|
||||
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(
|
||||
inherit: true,
|
||||
fontFeatures: const [
|
||||
|
@ -177,18 +185,7 @@ class ViewStationPageFluent extends ViewStationPageShared {
|
|||
child: ListTile(
|
||||
// isThreeLine: item.status.delay != 0,
|
||||
title: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: item.train.rank,
|
||||
style: TextStyle(
|
||||
color: item.train.rank.startsWith('IR') ? const Color.fromARGB(255, 255, 0, 0) : null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(text: item.train.number,),
|
||||
],
|
||||
),
|
||||
trainIdSpan(rank: item.train.rank, number: item.train.number),
|
||||
),
|
||||
subtitle: Text.rich(
|
||||
TextSpan(
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||
import 'package:info_tren/components/badge/badge.dart';
|
||||
import 'package:info_tren/components/loading/loading.dart';
|
||||
import 'package:info_tren/components/refresh_future_builder.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
import 'package:info_tren/pages/station_arrdep_page/view_station/view_station.dart';
|
||||
import 'package:info_tren/providers.dart';
|
||||
|
@ -106,24 +107,31 @@ class ViewStationPageMaterial extends ViewStationPageShared {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${item.time.toLocal().hour.toString().padLeft(2, '0')}:${item.time.toLocal().minute.toString().padLeft(2, '0')}',
|
||||
style: TextStyle(
|
||||
inherit: true,
|
||||
fontFeatures: const [
|
||||
FontFeature.tabularFigures(),
|
||||
],
|
||||
decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null,
|
||||
fontSize: item.status.delay != 0 ? 12 : null,
|
||||
),
|
||||
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')}',
|
||||
style: TextStyle(
|
||||
inherit: true,
|
||||
fontFeatures: const [
|
||||
FontFeature.tabularFigures(),
|
||||
],
|
||||
decoration: item.status.cancelled || item.status.delay != 0 ? TextDecoration.lineThrough : null,
|
||||
fontSize: item.status.delay != 0 ? 12 : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (item.status.delay != 0) Builder(
|
||||
builder: (context) {
|
||||
final newTime = item.time.add(Duration(minutes: item.status.delay));
|
||||
if (item.status.delay != 0) Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
final newTime = tz.convertDateTime(item.time.add(Duration(minutes: item.status.delay)));
|
||||
final delay = item.status.delay > 0;
|
||||
|
||||
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(
|
||||
inherit: true,
|
||||
fontFeatures: const [
|
||||
|
@ -142,18 +150,7 @@ class ViewStationPageMaterial extends ViewStationPageShared {
|
|||
child: ListTile(
|
||||
isThreeLine: item.status.delay != 0,
|
||||
title: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: item.train.rank,
|
||||
style: TextStyle(
|
||||
color: item.train.rank.startsWith('IR') ? const Color.fromARGB(255, 255, 0, 0) : null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(text: item.train.number,),
|
||||
],
|
||||
),
|
||||
trainIdSpan(rank: item.train.rank, number: item.train.number),
|
||||
),
|
||||
subtitle: Text.rich(
|
||||
TextSpan(
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
|
|||
import 'package:flutter/gestures.dart';
|
||||
import 'package:info_tren/components/cupertino_divider.dart';
|
||||
import 'package:info_tren/components/sliver_persistent_header_padding.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
import 'package:info_tren/pages/train_info_page/train_info_constants.dart';
|
||||
import 'package:info_tren/pages/train_info_page/view_train/train_info.dart';
|
||||
|
@ -562,18 +563,7 @@ class DisplayTrainID extends StatelessWidget {
|
|||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: trainData.rank,
|
||||
style: TextStyle(
|
||||
color: trainData.rank.startsWith('IR') ? const Color.fromARGB(255, 255, 0, 0) : null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(text: trainData.number,),
|
||||
],
|
||||
),
|
||||
trainIdSpan(rank: trainData.rank, number: trainData.number),
|
||||
style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle,
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:info_tren/components/badge/badge.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
import 'package:info_tren/providers.dart';
|
||||
|
||||
class DisplayTrainStation extends StatelessWidget {
|
||||
final Station station;
|
||||
|
@ -156,7 +158,7 @@ class Time extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class ArrivalTime extends StatelessWidget {
|
||||
class ArrivalTime extends ConsumerWidget {
|
||||
final Station station;
|
||||
final bool finalStation;
|
||||
|
||||
|
@ -167,7 +169,9 @@ class ArrivalTime extends StatelessWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
|
||||
if (finalStation) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
|
@ -187,7 +191,7 @@ class ArrivalTime extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
final delay = station.arrival!.status?.delay ?? 0;
|
||||
final time = station.arrival!.scheduleTime.toLocal();
|
||||
final time = tz.convertDateTime(station.arrival!.scheduleTime);
|
||||
|
||||
if (delay == 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 bool firstStation;
|
||||
|
||||
|
@ -302,7 +306,8 @@ class DepartureTime extends StatelessWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
if (firstStation) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
|
@ -322,7 +327,7 @@ class DepartureTime extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
final delay = station.departure!.status?.delay ?? 0;
|
||||
final time = station.departure!.scheduleTime.toLocal();
|
||||
final time = tz.convertDateTime(station.departure!.scheduleTime);
|
||||
|
||||
if (delay == 0) {
|
||||
return Text("${time.hour.toString().padLeft(2, "0")}:${time.minute.toString().padLeft(2, "0")}");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
import 'package:info_tren/pages/station_arrdep_page/view_station/view_station.dart';
|
||||
import 'package:info_tren/pages/train_info_page/view_train/train_info.dart';
|
||||
|
@ -303,22 +304,7 @@ class DisplayTrainID extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: trainData.rank,
|
||||
style: TextStyle(
|
||||
color: trainData.rank.startsWith('IR')
|
||||
? const Color.fromARGB(255, 255, 0, 0)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(
|
||||
text: trainData.number,
|
||||
),
|
||||
],
|
||||
),
|
||||
trainIdSpan(rank: trainData.rank, number: trainData.number),
|
||||
style: FluentTheme.of(context).typography.title?.copyWith(
|
||||
color: FluentTheme.of(context).typography.body?.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
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/models.dart';
|
||||
import 'package:info_tren/providers.dart';
|
||||
|
||||
class DisplayTrainStation extends StatelessWidget {
|
||||
final Station station;
|
||||
|
@ -170,7 +172,7 @@ class Time extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class ArrivalTime extends StatelessWidget {
|
||||
class ArrivalTime extends ConsumerWidget {
|
||||
final Station station;
|
||||
final bool finalStation;
|
||||
|
||||
|
@ -181,7 +183,8 @@ class ArrivalTime extends StatelessWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
if (station.arrival == null) {
|
||||
return Container();
|
||||
}
|
||||
|
@ -204,7 +207,7 @@ class ArrivalTime extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
final delay = station.arrival!.status?.delay ?? 0;
|
||||
final time = station.arrival!.scheduleTime.toLocal();
|
||||
final time = tz.convertDateTime(station.arrival!.scheduleTime);
|
||||
|
||||
if (delay == 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 bool firstStation;
|
||||
|
||||
|
@ -320,7 +323,8 @@ class DepartureTime extends StatelessWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
if (station.departure == null) {
|
||||
return Container();
|
||||
}
|
||||
|
@ -343,7 +347,7 @@ class DepartureTime extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
final delay = station.departure!.status?.delay ?? 0;
|
||||
final time = station.departure!.scheduleTime.toLocal();
|
||||
final time = tz.convertDateTime(station.departure!.scheduleTime);
|
||||
|
||||
if (delay == 0) {
|
||||
return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:info_tren/components/slim_app_bar.dart';
|
||||
import 'package:info_tren/components/train_id_text_span.dart';
|
||||
import 'package:info_tren/models.dart';
|
||||
import 'package:info_tren/pages/station_arrdep_page/view_station/view_station.dart';
|
||||
import 'package:info_tren/pages/train_info_page/view_train/train_info.dart';
|
||||
|
@ -318,22 +319,7 @@ class DisplayTrainID extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: trainData.rank,
|
||||
style: TextStyle(
|
||||
color: trainData.rank.startsWith('IR')
|
||||
? const Color.fromARGB(255, 255, 0, 0)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' '),
|
||||
TextSpan(
|
||||
text: trainData.number,
|
||||
),
|
||||
],
|
||||
),
|
||||
trainIdSpan(rank: trainData.rank, number: trainData.number),
|
||||
style: (isSmallScreen(context)
|
||||
? Theme.of(context).textTheme.headlineMedium
|
||||
: Theme.of(context).textTheme.displaySmall)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:info_tren/models.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/providers.dart';
|
||||
|
||||
class DisplayTrainStation extends StatelessWidget {
|
||||
final Station station;
|
||||
|
@ -168,7 +170,7 @@ class Time extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class ArrivalTime extends StatelessWidget {
|
||||
class ArrivalTime extends ConsumerWidget {
|
||||
final Station station;
|
||||
final bool finalStation;
|
||||
|
||||
|
@ -179,7 +181,8 @@ class ArrivalTime extends StatelessWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
if (station.arrival == null) {
|
||||
return Container();
|
||||
}
|
||||
|
@ -202,7 +205,7 @@ class ArrivalTime extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
final delay = station.arrival!.status?.delay ?? 0;
|
||||
final time = station.arrival!.scheduleTime.toLocal();
|
||||
final time = tz.convertDateTime(station.arrival!.scheduleTime);
|
||||
|
||||
if (delay == 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 bool firstStation;
|
||||
|
||||
|
@ -316,7 +319,8 @@ class DepartureTime extends StatelessWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tz = ref.watch(uiTimeZoneProvider);
|
||||
if (station.departure == null) {
|
||||
return Container();
|
||||
}
|
||||
|
@ -339,7 +343,7 @@ class DepartureTime extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
final delay = station.departure!.status?.delay ?? 0;
|
||||
final time = station.departure!.scheduleTime.toLocal();
|
||||
final time = tz.convertDateTime(station.departure!.scheduleTime);
|
||||
|
||||
if (delay == 0) {
|
||||
return Text("${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:info_tren/api/station_data.dart';
|
||||
|
@ -36,6 +37,39 @@ final uiDesignProvider = StateNotifierProvider<UiDesignNotifier, UiDesign>(
|
|||
(ref) => UiDesignNotifier(
|
||||
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>(
|
||||
|
|
|
@ -616,6 +616,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
timezone:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: timezone
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.0"
|
||||
timing:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -34,6 +34,7 @@ dependencies:
|
|||
json_annotation: ^4.7.0
|
||||
shared_preferences: ^2.0.15
|
||||
fluent_ui: ^4.0.3+1
|
||||
timezone: ^0.9.0
|
||||
|
||||
dev_dependencies:
|
||||
# flutter_test:
|
||||
|
|
Loading…
Add table
Reference in a new issue