diff --git a/lib/core/router/router.dart b/lib/core/router/router.dart index 6aeeefee1..09e2d5e63 100644 --- a/lib/core/router/router.dart +++ b/lib/core/router/router.dart @@ -1,5 +1,6 @@ import 'package:eqmonitor/app.dart'; import 'package:eqmonitor/core/provider/shared_preferences.dart'; +import 'package:eqmonitor/feature/earthquake_history/model/state/earthquake_history_item.dart'; import 'package:eqmonitor/feature/earthquake_history/page/earthquake_history.dart'; import 'package:eqmonitor/feature/earthquake_history_details/screen/earthquake_history_details.dart'; import 'package:eqmonitor/feature/eew_detailed_history/eew_detailed_history_screen.dart'; @@ -57,29 +58,34 @@ class EarthquakeHistoryRoute extends GoRouteData { } @TypedGoRoute( - path: '/earthquake-history/:eventId', + path: '/earthquake-history-detailed', ) class EarthquakeHistoryDetailsRoute extends GoRouteData { - const EarthquakeHistoryDetailsRoute(this.eventId); - final int eventId; + const EarthquakeHistoryDetailsRoute({ + required this.$extra, + }); + final EarthquakeHistoryItem $extra; @override - Widget build(BuildContext context, GoRouterState state) { - return EarthquakeHistoryDetailsPage( - eventId: eventId, - ); - } + Widget build(BuildContext context, GoRouterState state) => + EarthquakeHistoryDetailsPage( + data: $extra, + ); } -@TypedGoRoute( - path: '/eew-detailed-history/:eventId', +@TypedGoRoute( + path: '/eew-history-detailed', ) -class EewDetailedHistoryRoute extends GoRouteData { - const EewDetailedHistoryRoute(this.eventId); - final int eventId; +class EewHisotryDetailRoute extends GoRouteData { + const EewHisotryDetailRoute({ + required this.$extra, + }); + + final EarthquakeHistoryItem $extra; + @override Widget build(BuildContext context, GoRouterState state) => EewDetailedHistoryScreen( - eventId: eventId, + data: $extra, ); } diff --git a/lib/core/router/router.g.dart b/lib/core/router/router.g.dart index 3ec2e1e0a..78aacdee0 100644 --- a/lib/core/router/router.g.dart +++ b/lib/core/router/router.g.dart @@ -12,7 +12,7 @@ List get $appRoutes => [ $setupRoute, $earthquakeHistoryRoute, $earthquakeHistoryDetailsRoute, - $eewDetailedHistoryRoute, + $eewHisotryDetailRoute, $homeRoute, $talkerRoute, $kmoniRoute, @@ -65,7 +65,7 @@ extension $EarthquakeHistoryRouteExtension on EarthquakeHistoryRoute { } RouteBase get $earthquakeHistoryDetailsRoute => GoRouteData.$route( - path: '/earthquake-history/:eventId', + path: '/earthquake-history-detailed', factory: $EarthquakeHistoryDetailsRouteExtension._fromState, ); @@ -73,46 +73,50 @@ extension $EarthquakeHistoryDetailsRouteExtension on EarthquakeHistoryDetailsRoute { static EarthquakeHistoryDetailsRoute _fromState(GoRouterState state) => EarthquakeHistoryDetailsRoute( - int.parse(state.pathParameters['eventId']!), + $extra: state.extra as EarthquakeHistoryItem, ); String get location => GoRouteData.$location( - '/earthquake-history/${Uri.encodeComponent(eventId.toString())}', + '/earthquake-history-detailed', ); - void go(BuildContext context) => context.go(location); + void go(BuildContext context) => context.go(location, extra: $extra); - Future push(BuildContext context) => context.push(location); + Future push(BuildContext context) => + context.push(location, extra: $extra); void pushReplacement(BuildContext context) => - context.pushReplacement(location); + context.pushReplacement(location, extra: $extra); - void replace(BuildContext context) => context.replace(location); + void replace(BuildContext context) => + context.replace(location, extra: $extra); } -RouteBase get $eewDetailedHistoryRoute => GoRouteData.$route( - path: '/eew-detailed-history/:eventId', - factory: $EewDetailedHistoryRouteExtension._fromState, +RouteBase get $eewHisotryDetailRoute => GoRouteData.$route( + path: '/eew-history-detailed', + factory: $EewHisotryDetailRouteExtension._fromState, ); -extension $EewDetailedHistoryRouteExtension on EewDetailedHistoryRoute { - static EewDetailedHistoryRoute _fromState(GoRouterState state) => - EewDetailedHistoryRoute( - int.parse(state.pathParameters['eventId']!), +extension $EewHisotryDetailRouteExtension on EewHisotryDetailRoute { + static EewHisotryDetailRoute _fromState(GoRouterState state) => + EewHisotryDetailRoute( + $extra: state.extra as EarthquakeHistoryItem, ); String get location => GoRouteData.$location( - '/eew-detailed-history/${Uri.encodeComponent(eventId.toString())}', + '/eew-history-detailed', ); - void go(BuildContext context) => context.go(location); + void go(BuildContext context) => context.go(location, extra: $extra); - Future push(BuildContext context) => context.push(location); + Future push(BuildContext context) => + context.push(location, extra: $extra); void pushReplacement(BuildContext context) => - context.pushReplacement(location); + context.pushReplacement(location, extra: $extra); - void replace(BuildContext context) => context.replace(location); + void replace(BuildContext context) => + context.replace(location, extra: $extra); } RouteBase get $homeRoute => GoRouteData.$route( diff --git a/lib/feature/earthquake_history/page/earthquake_history.dart b/lib/feature/earthquake_history/page/earthquake_history.dart index 017283718..b130d7963 100644 --- a/lib/feature/earthquake_history/page/earthquake_history.dart +++ b/lib/feature/earthquake_history/page/earthquake_history.dart @@ -79,7 +79,6 @@ class EarthquakeHistoryPage extends HookConsumerWidget { .fetch, child: const Text('再読み込み'), ), - ], ), ); @@ -137,9 +136,8 @@ class EarthquakeHistoryListView extends ConsumerWidget { final item = data[index]; return EarthquakeHistoryTileWidget( item: item, - onTap: (p0) => context.push( - EarthquakeHistoryDetailsRoute(p0.eventId).location, - ), + onTap: (p0) => + EarthquakeHistoryDetailsRoute($extra: p0).push(context), showBackgroundColor: shouldShowBackgroundColor, ); }, diff --git a/lib/feature/earthquake_history_details/component/prefecture_intensity.dart b/lib/feature/earthquake_history_details/component/prefecture_intensity.dart index 11a57cdf6..350ff894a 100644 --- a/lib/feature/earthquake_history_details/component/prefecture_intensity.dart +++ b/lib/feature/earthquake_history_details/component/prefecture_intensity.dart @@ -3,7 +3,6 @@ import 'package:eqapi_types/eqapi_types.dart'; import 'package:eqmonitor/core/component/container/bordered_container.dart'; import 'package:eqmonitor/core/component/intenisty/intensity_icon_type.dart'; import 'package:eqmonitor/core/component/intenisty/jma_intensity_icon.dart'; -import 'package:eqmonitor/core/extension/map_to_list.dart'; import 'package:eqmonitor/feature/earthquake_history/model/state/earthquake_history_item.dart'; import 'package:eqmonitor/feature/home/component/sheet/sheet_header.dart'; import 'package:eqmonitor/gen/fonts.gen.dart'; @@ -11,8 +10,102 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:sheet/route.dart'; +part 'prefecture_intensity.g.dart'; + +typedef _Arg = ({ + List? cities, + List prefectures, + List? stations +}); + +@riverpod +Future>> _calculator( + _CalculatorRef ref, + _Arg arg, +) => + compute<_Arg, Map>>( + ( + _Arg arg, + ) { + final cities = arg.cities; + final prefectures = arg.prefectures; + final stations = arg.stations; + + if (stations != null && cities != null) { + final stationsGroupedByIntensity = stations + .where((e) => e.maxInt != null) + .groupListsBy((e) => e.maxInt!); + return stationsGroupedByIntensity.map((intensity, stations) { + final stationsGroupedByCity = + stations.groupListsBy((e) => '${e.code.substring(0, 5)}00'); + // マージ + final mergedCity = stationsGroupedByCity.entries + .map((e) { + final cityCode = e.key; + final cityStations = e.value; + final city = + cities.firstWhereOrNull((e) => e.code == cityCode); + if (city == null) { + return null; + } + return _CityIntensity( + code: city.code, + name: city.name, + intensity: intensity, + stations: cityStations, + ); + }) + .whereType<_CityIntensity>() + .toList(); + + // 都道府県ごとにまとめる + final citiesGroupedByPrefecture = + mergedCity.groupListsBy((e) => e.code.substring(0, 2)); + // マージ + final mergedPrefecture = citiesGroupedByPrefecture.entries + .map((e) { + final prefectureCode = e.key; + final prefectureCities = e.value; + final prefecture = prefectures + .firstWhereOrNull((e) => e.code == prefectureCode); + if (prefecture == null) { + return null; + } + return _PrefectureIntensity( + code: prefecture.code, + name: prefecture.name, + intensity: intensity, + cities: prefectureCities, + ); + }) + .whereType<_PrefectureIntensity>() + .toList(); + return MapEntry(intensity, mergedPrefecture); + }); + } else { + return prefectures.groupListsBy((e) => e.maxInt!).map( + (intensity, prefectures) => MapEntry( + intensity, + prefectures + .map( + (e) => _PrefectureIntensity( + code: e.code, + name: e.name, + intensity: intensity, + cities: null, + ), + ) + .toList(), + ), + ); + } + }, + arg, + ); + class PrefectureIntensityWidget extends HookConsumerWidget { const PrefectureIntensityWidget({ super.key, @@ -23,6 +116,7 @@ class PrefectureIntensityWidget extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { + print('PrefectureIntensityWidget#build'); final theme = Theme.of(context); final textTheme = theme.textTheme; @@ -30,101 +124,75 @@ class PrefectureIntensityWidget extends HookConsumerWidget { if (intensity == null) { return const SizedBox.shrink(); } - final mergedPrefecturesFuture = useFuture( - // 重めなので別Isolateで計算 - compute( + final mergedPrefecturesFuture = ref.watch( + _calculatorProvider( ( - ({ - List? cities, - List prefectures, - List? stations - }) arg, - ) { - final result = arg.prefectures.map( - (e) => _MergedPrefectureIntensity.fromIntensity( - e, - arg.cities ?? [], - arg.stations ?? [], - ), - ); - - // 最大震度ごとにグループ - final intensityGroupedPrefectures = - result.groupListsBy((e) => e.prefecture.maxInt); - return intensityGroupedPrefectures; - }, - ( - prefectures: intensity.prefectures, cities: intensity.cities, + prefectures: intensity.prefectures, stations: intensity.stations, ), - debugLabel: 'prefecture', ), ); - final mergedPrefectures = mergedPrefecturesFuture.data; - - if (mergedPrefectures != null && mergedPrefectures.isNotEmpty) { - return BorderedContainer( - elevation: 1, - padding: const EdgeInsets.symmetric( - horizontal: 8, - vertical: 4, - ), - child: Column( - children: [ - const SheetHeader( - title: '各地の震度', - ), - // 震度一覧 - for (final kv in mergedPrefectures.toList - .where((kv) => kv.key != null) - .cast< - ({ - JmaIntensity key, - List<_MergedPrefectureIntensity> value - })>()) - () { - final hasChildren = - kv.value.any((element) => element.cities.isNotEmpty); - return ListTile( - titleAlignment: ListTileTitleAlignment.titleHeight, - leading: JmaIntensityIcon( - intensity: kv.key, - type: IntensityIconType.filled, - size: 16, - ), - title: Text( - '震度${kv.key.type.replaceAll("+", "強").replaceAll("-", "弱")}', - style: textTheme.titleMedium!.copyWith( - fontFamily: FontFamily.jetBrainsMono, - fontFamilyFallback: [FontFamily.notoSansJP], - ), - ), - subtitle: Text( - kv.value.map((e) => e.prefecture.name).join(', '), - ), - onTap: hasChildren - ? () => _PrefectureModalBottomSheet.show( - context: context, - intensity: kv.key, - prefectures: kv.value, - ) - : null, - trailing: - hasChildren ? const Icon(Icons.chevron_right) : null, - ); - }(), - ], - ), - ); - } - return switch (mergedPrefecturesFuture.connectionState) { - ConnectionState.waiting => const Center( + return switch (mergedPrefecturesFuture) { + AsyncLoading() => const Center( child: Padding( padding: EdgeInsets.all(8), child: CircularProgressIndicator.adaptive(), ), ), + AsyncData(:final value) => BorderedContainer( + elevation: 1, + padding: const EdgeInsets.symmetric( + horizontal: 8, + vertical: 4, + ), + child: Column( + children: [ + const SheetHeader( + title: '各地の震度', + ), + // 震度一覧 + for (final kv in value.entries) + () { + final intensity = kv.key; + final prefectures = kv.value; + final hasCities = prefectures.any( + (prefecture) => + prefecture.cities + ?.any((city) => city.stations.isNotEmpty) ?? + false, + ); + return ListTile( + titleAlignment: ListTileTitleAlignment.titleHeight, + leading: JmaIntensityIcon( + intensity: intensity, + type: IntensityIconType.filled, + size: 16, + ), + title: Text( + '震度${intensity.type.replaceAll("+", "強").replaceAll("-", "弱")}', + style: textTheme.titleMedium!.copyWith( + fontFamily: FontFamily.jetBrainsMono, + fontFamilyFallback: [FontFamily.notoSansJP], + ), + ), + subtitle: Text( + prefectures.map((e) => e.name).join(', '), + ), + onTap: hasCities + ? () => _PrefectureModalBottomSheet.show( + context: context, + intensity: kv.key, + prefectures: kv.value, + ) + : null, + trailing: + hasCities ? const Icon(Icons.chevron_right) : null, + ); + }(), + ], + ), + ), _ => const SizedBox.shrink(), }; } @@ -139,7 +207,7 @@ class _PrefectureModalBottomSheet extends StatelessWidget { static Future show({ required BuildContext context, required JmaIntensity intensity, - required List<_MergedPrefectureIntensity> prefectures, + required List<_PrefectureIntensity> prefectures, }) => Navigator.of(context).push( SheetRoute( @@ -153,7 +221,7 @@ class _PrefectureModalBottomSheet extends StatelessWidget { ); final JmaIntensity intensity; - final List<_MergedPrefectureIntensity> prefectures; + final List<_PrefectureIntensity> prefectures; @override Widget build(BuildContext context) { @@ -179,14 +247,14 @@ class _PrefectureListTile extends HookWidget { required this.prefecture, }); - final _MergedPrefectureIntensity prefecture; + final _PrefectureIntensity prefecture; @override Widget build(BuildContext context) { final isExpanded = useState(false); final shrinked = ListTile( title: Text( - prefecture.prefecture.name, + prefecture.name, style: const TextStyle( fontWeight: FontWeight.bold, ), @@ -196,7 +264,7 @@ class _PrefectureListTile extends HookWidget { ); final expanded = ListTile( title: Text( - prefecture.prefecture.name, + prefecture.name, style: const TextStyle( fontWeight: FontWeight.bold, ), @@ -204,12 +272,12 @@ class _PrefectureListTile extends HookWidget { subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - for (final city in prefecture.cities) + for (final city in prefecture.cities ?? <_CityIntensity>[]) Text.rich( TextSpan( children: [ TextSpan( - text: '${city.city.name}: ', + text: '${city.name}: ', style: const TextStyle( fontWeight: FontWeight.bold, ), @@ -240,45 +308,30 @@ class _PrefectureListTile extends HookWidget { } } -class _MergedPrefectureIntensity { - factory _MergedPrefectureIntensity.fromIntensity( - RegionIntensity prefecture, - List allCities, - List allStations, - ) { - final prefectureCode = prefecture.code; - final cities = allCities - .where((e) => e.code.startsWith(prefectureCode)) - .map((e) => _MergedCityIntensity.fromIntensity(e, allStations)) - .toList(); - return _MergedPrefectureIntensity._( - prefecture: prefecture, - cities: cities, - ); - } - - _MergedPrefectureIntensity._({ - required this.prefecture, +class _PrefectureIntensity { + _PrefectureIntensity({ + required this.code, + required this.name, + required this.intensity, required this.cities, }); - final RegionIntensity prefecture; - final List<_MergedCityIntensity> cities; + final String code; + final String name; + final JmaIntensity intensity; + final List<_CityIntensity>? cities; } -class _MergedCityIntensity { - factory _MergedCityIntensity.fromIntensity( - RegionIntensity city, - List allStations, - ) { - // ex: `0320700` -> `03207` - final cityCode = city.code.substring(0, 5); - final stations = - allStations.where((e) => e.code.startsWith(cityCode)).toList(); - return _MergedCityIntensity._(city: city, stations: stations); - } - _MergedCityIntensity._({required this.city, required this.stations}); +class _CityIntensity { + _CityIntensity({ + required this.code, + required this.name, + required this.intensity, + required this.stations, + }); - final RegionIntensity city; + final String code; + final String name; + final JmaIntensity intensity; final List stations; } diff --git a/lib/feature/earthquake_history_details/component/prefecture_intensity.g.dart b/lib/feature/earthquake_history_details/component/prefecture_intensity.g.dart new file mode 100644 index 000000000..8f926d753 --- /dev/null +++ b/lib/feature/earthquake_history_details/component/prefecture_intensity.g.dart @@ -0,0 +1,186 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: type=lint, duplicate_ignore + +part of 'prefecture_intensity.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$calculatorHash() => r'0d904c3c6d4fdb0bc1ea3e404efb330055a3ada8'; + +/// Copied from Dart SDK +class _SystemHash { + _SystemHash._(); + + static int combine(int hash, int value) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + value); + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); + return hash ^ (hash >> 6); + } + + static int finish(int hash) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); + // ignore: parameter_assignments + hash = hash ^ (hash >> 11); + return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); + } +} + +/// See also [_calculator]. +@ProviderFor(_calculator) +const _calculatorProvider = _CalculatorFamily(); + +/// See also [_calculator]. +class _CalculatorFamily + extends Family>>> { + /// See also [_calculator]. + const _CalculatorFamily(); + + /// See also [_calculator]. + _CalculatorProvider call( + ({ + List? cities, + List prefectures, + List? stations + }) arg, + ) { + return _CalculatorProvider( + arg, + ); + } + + @override + _CalculatorProvider getProviderOverride( + covariant _CalculatorProvider provider, + ) { + return call( + provider.arg, + ); + } + + static const Iterable? _dependencies = null; + + @override + Iterable? get dependencies => _dependencies; + + static const Iterable? _allTransitiveDependencies = null; + + @override + Iterable? get allTransitiveDependencies => + _allTransitiveDependencies; + + @override + String? get name => r'_calculatorProvider'; +} + +/// See also [_calculator]. +class _CalculatorProvider extends AutoDisposeFutureProvider< + Map>> { + /// See also [_calculator]. + _CalculatorProvider( + ({ + List? cities, + List prefectures, + List? stations + }) arg, + ) : this._internal( + (ref) => _calculator( + ref as _CalculatorRef, + arg, + ), + from: _calculatorProvider, + name: r'_calculatorProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$calculatorHash, + dependencies: _CalculatorFamily._dependencies, + allTransitiveDependencies: + _CalculatorFamily._allTransitiveDependencies, + arg: arg, + ); + + _CalculatorProvider._internal( + super._createNotifier, { + required super.name, + required super.dependencies, + required super.allTransitiveDependencies, + required super.debugGetCreateSourceHash, + required super.from, + required this.arg, + }) : super.internal(); + + final ({ + List? cities, + List prefectures, + List? stations + }) arg; + + @override + Override overrideWith( + FutureOr>> Function( + _CalculatorRef provider) + create, + ) { + return ProviderOverride( + origin: this, + override: _CalculatorProvider._internal( + (ref) => create(ref as _CalculatorRef), + from: from, + name: null, + dependencies: null, + allTransitiveDependencies: null, + debugGetCreateSourceHash: null, + arg: arg, + ), + ); + } + + @override + AutoDisposeFutureProviderElement< + Map>> createElement() { + return _CalculatorProviderElement(this); + } + + @override + bool operator ==(Object other) { + return other is _CalculatorProvider && other.arg == arg; + } + + @override + int get hashCode { + var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, arg.hashCode); + + return _SystemHash.finish(hash); + } +} + +mixin _CalculatorRef on AutoDisposeFutureProviderRef< + Map>> { + /// The parameter `arg` of this provider. + ({ + List? cities, + List prefectures, + List? stations + }) get arg; +} + +class _CalculatorProviderElement extends AutoDisposeFutureProviderElement< + Map>> with _CalculatorRef { + _CalculatorProviderElement(super.provider); + + @override + ({ + List? cities, + List prefectures, + List? stations + }) get arg => (origin as _CalculatorProvider).arg; +} +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member diff --git a/lib/feature/earthquake_history_details/screen/earthquake_history_details.dart b/lib/feature/earthquake_history_details/screen/earthquake_history_details.dart index ce8af13ab..db6c4315a 100644 --- a/lib/feature/earthquake_history_details/screen/earthquake_history_details.dart +++ b/lib/feature/earthquake_history_details/screen/earthquake_history_details.dart @@ -10,7 +10,6 @@ import 'package:eqmonitor/core/provider/config/theme/intensity_color/model/inten import 'package:eqmonitor/core/provider/topology_map/provider/topology_maps.dart'; import 'package:eqmonitor/core/router/router.dart'; import 'package:eqmonitor/feature/earthquake_history/model/state/earthquake_history_item.dart'; -import 'package:eqmonitor/feature/earthquake_history/viewmodel/earthquake_history_view_model.dart'; import 'package:eqmonitor/feature/earthquake_history_details/component/earthquake_map.dart'; import 'package:eqmonitor/feature/earthquake_history_details/component/prefecture_intensity.dart'; import 'package:eqmonitor/feature/earthquake_history_details/component/prefecture_lpgm_intensity.dart'; @@ -27,50 +26,14 @@ import 'package:url_launcher/url_launcher.dart'; class EarthquakeHistoryDetailsPage extends HookConsumerWidget { const EarthquakeHistoryDetailsPage({ - required this.eventId, + required this.data, super.key, }); - final int eventId; + final EarthquakeHistoryItem data; @override Widget build(BuildContext context, WidgetRef ref) { - // 当該データがアレばOK - final data = ref - .watch(earthquakeHistoryViewModelProvider) - ?.value - ?.firstWhereOrNull((e) => e.eventId == eventId); - if (data == null) { - final state = ref.watch(earthquakeHistoryViewModelProvider); - final isLoading = state?.isLoading ?? false; - final isReloading = state?.isReloading ?? false; - final disableLoading = isLoading || isReloading; - return Scaffold( - body: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Text('当該データが見つかりませんでした\n再度地震の履歴を読み込んでください'), - const SizedBox(height: 8), - FilledButton( - onPressed: disableLoading - ? null - : () => ref - .read(earthquakeHistoryViewModelProvider.notifier) - .fetch(isLoadMore: true), - child: const Text('追加で地震履歴を読み込む'), - ), - if (disableLoading) ...[ - const SizedBox(height: 8), - const Center( - child: CircularProgressIndicator.adaptive(), - ), - ], - ], - ), - ), - ); - } final sheetController = SheetController(); final zoomCachedMapData = ref.watch(zoomCachedProjectedFeatureLayerProvider).valueOrNull; @@ -174,6 +137,7 @@ class _Sheet extends StatelessWidget { @override Widget build(BuildContext context) { + print('_Sheet.build'); return SafeArea( bottom: false, child: BasicModalSheet( @@ -193,11 +157,9 @@ class _Sheet extends StatelessWidget { ListTile( title: const Text('この地震に関する緊急地震速報'), subtitle: Text('${item.eewList.length}件'), - onTap: () => context.push( - EewDetailedHistoryRoute( - item.eventId, - ).location, - ), + onTap: () => EewHisotryDetailRoute( + $extra: item, + ).push(context), ), ], ), diff --git a/lib/feature/eew_detailed_history/eew_detailed_history_screen.dart b/lib/feature/eew_detailed_history/eew_detailed_history_screen.dart index 321f8ea38..b50d08a54 100644 --- a/lib/feature/eew_detailed_history/eew_detailed_history_screen.dart +++ b/lib/feature/eew_detailed_history/eew_detailed_history_screen.dart @@ -1,9 +1,7 @@ -import 'package:collection/collection.dart'; import 'package:eqapi_types/eqapi_types.dart'; import 'package:eqmonitor/core/provider/config/theme/intensity_color/intensity_color_provider.dart'; import 'package:eqmonitor/core/provider/config/theme/intensity_color/model/intensity_color_model.dart'; import 'package:eqmonitor/feature/earthquake_history/model/state/earthquake_history_item.dart'; -import 'package:eqmonitor/feature/earthquake_history/viewmodel/earthquake_history_view_model.dart'; import 'package:eqmonitor/gen/fonts.gen.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; @@ -12,28 +10,22 @@ import 'package:two_dimensional_scrollables/two_dimensional_scrollables.dart'; class EewDetailedHistoryScreen extends HookConsumerWidget { const EewDetailedHistoryScreen({ - required this.eventId, + required this.data, super.key, }); - final int eventId; + final EarthquakeHistoryItem data; @override Widget build(BuildContext context, WidgetRef ref) { final theme = Theme.of(context); final colorScheme = theme.colorScheme; - final data = ref - .watch(earthquakeHistoryViewModelProvider) - ?.value - ?.firstWhereOrNull((e) => e.eventId == eventId); - final eews = data?.eewList.reversed.toList(); - if (eews == null) { - return Scaffold( + final eews = data.eewList.reversed.toList(); + if (eews.isEmpty) { + return const Scaffold( body: Center( child: Text( - data == null - ? '当該IDの地震情報が見つかりませんでした。\n再読み込みしてください' - : '当該IDの地震情報に対する緊急地震速報が見つかりませんでした。', + '当該IDの地震情報に対する緊急地震速報が見つかりませんでした。', ), ), ); diff --git a/lib/feature/home/component/eew/eew_widget.dart b/lib/feature/home/component/eew/eew_widget.dart index b5b54fc7b..a1b518ffc 100644 --- a/lib/feature/home/component/eew/eew_widget.dart +++ b/lib/feature/home/component/eew/eew_widget.dart @@ -11,7 +11,6 @@ import 'package:eqmonitor/feature/home/features/eew/provider/eew_alive_telegram. import 'package:eqmonitor/gen/fonts.gen.dart'; import 'package:extensions/extensions.dart'; import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:intl/intl.dart'; @@ -333,7 +332,7 @@ class EewWidget extends ConsumerWidget { final maxLgInt = eew.forecastMaxLgInt?.toDisplayMaxLgInt(); final card = InkWell( onLongPress: () => - context.push(EewDetailedHistoryRoute(telegram.eventId).location), + EewHisotryDetailRoute($extra: item).push(context), child: Card( margin: const EdgeInsets.all(4), elevation: 0, diff --git a/lib/feature/home/component/sheet/earthquake_history_widget.dart b/lib/feature/home/component/sheet/earthquake_history_widget.dart index 5fee8b886..7dcaca9bd 100644 --- a/lib/feature/home/component/sheet/earthquake_history_widget.dart +++ b/lib/feature/home/component/sheet/earthquake_history_widget.dart @@ -60,9 +60,8 @@ class EarthquakeHistorySheetWidget extends HookConsumerWidget { for (final item in items) EarthquakeHistoryTileWidget( item: item, - onTap: (p0) => context.push( - EarthquakeHistoryDetailsRoute(p0.eventId).location, - ), + onTap: (p0) => EarthquakeHistoryDetailsRoute($extra: p0) + .push(context), showBackgroundColor: false, ), ]; @@ -79,9 +78,9 @@ class EarthquakeHistorySheetWidget extends HookConsumerWidget { EarthquakeHistoryTileWidget( showBackgroundColor: false, item: item, - onTap: (p0) => context.push( - EarthquakeHistoryDetailsRoute(p0.eventId).location, - ), + onTap: (p0) => + EarthquakeHistoryDetailsRoute($extra: p0) + .push(context), ), ]; }