Skip to content

Commit

Permalink
Refactor main.dart to use ProviderScope instead of ProviderContainer …
Browse files Browse the repository at this point in the history
…for app initialization; update MapComponentsRenderer to utilize parent ProviderScope for widget capturing; add progress logging in MainMapView; log cache failure in HomeView.
  • Loading branch information
YumNumm committed Nov 29, 2024
1 parent 3f4781f commit 9e7629e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 31 deletions.
31 changes: 26 additions & 5 deletions app/lib/feature/home/component/render/map_components_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:eqapi_types/eqapi_types.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/component/intenisty/jma_lg_intensity_icon.dart';
import 'package:eqmonitor/main.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:screenshot/screenshot.dart';
Expand All @@ -17,6 +16,10 @@ class MapComponentsRenderer {
IntensityIconType type,
) async {
final pixelRatio = MediaQuery.devicePixelRatioOf(context);
final parentContainer = ProviderScope.containerOf(context);
final container = ProviderContainer(
parent: parentContainer,
);
final result = await _controller.captureFromWidget(
UncontrolledProviderScope(
container: container,
Expand All @@ -37,6 +40,10 @@ class MapComponentsRenderer {
IntensityIconType type,
) async {
final pixelRatio = MediaQuery.devicePixelRatioOf(context);
final parentContainer = ProviderScope.containerOf(context);
final container = ProviderContainer(
parent: parentContainer,
);
final result = await _controller.captureFromWidget(
UncontrolledProviderScope(
container: container,
Expand All @@ -56,10 +63,17 @@ class MapComponentsRenderer {
HypocenterType type,
) async {
final pixelRatio = MediaQuery.devicePixelRatioOf(context);
final parentContainer = ProviderScope.containerOf(context);
final container = ProviderContainer(
parent: parentContainer,
);
final result = await _controller.captureFromWidget(
CustomPaint(
UncontrolledProviderScope(
container: container,
child: CustomPaint(
painter: _HypocenterPainter(type: type),
size: const Size(80, 80),
size: const Size(80, 80),
),
),
context: context,
pixelRatio: pixelRatio,
Expand All @@ -71,10 +85,17 @@ class MapComponentsRenderer {
BuildContext context,
) async {
final pixelRatio = MediaQuery.devicePixelRatioOf(context);
final parentContainer = ProviderScope.containerOf(context);
final container = ProviderContainer(
parent: parentContainer,
);
final result = await _controller.captureFromWidget(
const CustomPaint(
UncontrolledProviderScope(
container: container,
child: const CustomPaint(
painter: _CurrentLocationPainter(),
size: Size(80, 80),
size: Size(80, 80),
),
),
context: context,
pixelRatio: pixelRatio,
Expand Down
10 changes: 10 additions & 0 deletions app/lib/feature/home/features/map/view/main_map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ class MainMapView extends HookConsumerWidget {
!images.intensityIconFill.isAllRendered() ||
!hasTravelTimeDepthMapValue ||
images.currentLocationIcon == null) {
final progress = [
stylePath.value == null,
images.hypocenterIcon == null,
images.hypocenterLowPreciseIcon == null,
!images.intenistyIcon.isAllRendered(),
!images.intensityIconFill.isAllRendered(),
!hasTravelTimeDepthMapValue,
images.currentLocationIcon == null,
];
log('progress: $progress');
return const Scaffold(
body: Center(
child: CircularProgressIndicator.adaptive(),
Expand Down
1 change: 1 addition & 0 deletions app/lib/feature/home/view/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class _HomeBodyWidget extends HookConsumerWidget {
return true;
// ignore: avoid_catches_without_on_clauses
} catch (e) {
log('画像のキャッシュ 失敗: $e');
await Future<void>.delayed(
const Duration(milliseconds: 1000),
);
Expand Down
49 changes: 23 additions & 26 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import 'package:shared_preference_app_group/shared_preference_app_group.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:talker_flutter/talker_flutter.dart';

late final ProviderContainer container;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -142,32 +141,30 @@ Future<void> main() async {
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(!kDebugMode),
);
}
container = ProviderContainer(
overrides: [
sharedPreferencesProvider.overrideWithValue(results.$1.$1),
kyoshinObservationPointsProvider.overrideWithValue(results.$1.$2),
talkerProvider.overrideWithValue(talker),
packageInfoProvider.overrideWithValue(results.$1.$3),
if (results.$1.$4 != null)
androidDeviceInfoProvider.overrideWithValue(results.$1.$4!),
if (results.$1.$5 != null)
iosDeviceInfoProvider.overrideWithValue(results.$1.$5!),
if (results.$1.$7 != null)
applicationDocumentsDirectoryProvider.overrideWithValue(results.$1.$7!),
jmaCodeTableProvider.overrideWithValue(results.$1.$8),
if (results.$2.$3 != null)
kyoshinColorMapProvider.overrideWithValue(results.$2.$3!),
],
observers: [
if (kDebugMode)
CustomProviderObserver(
talker,
),
],
);
runApp(
UncontrolledProviderScope(
container: container,
ProviderScope(
overrides: [
sharedPreferencesProvider.overrideWithValue(results.$1.$1),
kyoshinObservationPointsProvider.overrideWithValue(results.$1.$2),
talkerProvider.overrideWithValue(talker),
packageInfoProvider.overrideWithValue(results.$1.$3),
if (results.$1.$4 != null)
androidDeviceInfoProvider.overrideWithValue(results.$1.$4!),
if (results.$1.$5 != null)
iosDeviceInfoProvider.overrideWithValue(results.$1.$5!),
if (results.$1.$7 != null)
applicationDocumentsDirectoryProvider
.overrideWithValue(results.$1.$7!),
jmaCodeTableProvider.overrideWithValue(results.$1.$8),
if (results.$2.$3 != null)
kyoshinColorMapProvider.overrideWithValue(results.$2.$3!),
],
observers: [
if (kDebugMode)
CustomProviderObserver(
talker,
),
],
child: const App(),
),
);
Expand Down

0 comments on commit 9e7629e

Please sign in to comment.