main function

void main()

Implementation

void main() async {
  final List<Override> overrides = [];

  // FIXME: Adding Mocks
  if (kDebugMode) {
    overrides.addAll(
      [
        // dailyMeasurementRecordRepositoryProvider.overrideWith(
        //   (ref) => MockDailyMeasurementRecordRepository(ref),
        // ),
        getDiseaseLearningChapterRepositoryProvider.overrideWith(
          (ref) => MockGetDiseaseLearningChapterRepository(ref),
        ),
        upsertDiseaseLearningHistoryRepositoryProvider.overrideWith(
          (ref) => MockUpsertDiseaseLearningHistoryRepository(ref),
        ),
        getDiseaseLearningContentRepositoryProvider.overrideWith(
          (ref) => MockGetDiseaseLearningContentRepository(ref),
        ),
        getDiseaseLearningQuizResultRepositoryProvider.overrideWith(
          (ref) => MockGetDiseaseLearningQuizResultRepository(ref),
        ),
        // FIXME: API実装後に削除
        messageRepositoryProvider.overrideWith(
          (ref) => MockMessageRepository(),
        ),
      ],
    );
  }

  final container = ProviderContainer(
    overrides: overrides,
  );
  final f = _setupFlavor(container);

  WidgetsFlutterBinding.ensureInitialized();

  // 通知の初期化
  container.read(notificationServiceProvider).initializePlatformNotifications();

  // Firebaseの設定を取得
  final firebaseConfig = container.read(firebaseConfigurationProvider);
  // Firebaseの初期化が完了していない場合は初期化
  if (Firebase.apps.isEmpty) {
    final app = await Firebase.initializeApp(
      options: firebaseConfig.options,
    );
    Logger().d(app.options.projectId);
  }

  final firebaseMessagingService =
      container.read(firebaseMessagingServiceProvider);
  firebaseMessagingService.setupFirebaseMessagingHandlers();

  try {
    await Amplify.addPlugin(AmplifyAuthCognito());
    await Amplify.configure(f.amplifyconfig);
  } on Exception catch (e) {
    if (kDebugMode) {
      print(e);
    }
  }

  cameras = await availableCameras();

  container.read(dateChangedTimerManagerProvider.notifier).startTimer();

  await SentryFlutter.init(
    (options) => options
      ..dsn =
          'https://3c1e8ebf128773a6d25eaa33200eee6b@o575887.ingest.sentry.io/4505917077127168'
      ..tracesSampleRate = 1.0
      ..environment = f.title
      ..attachScreenshot = true
      ..attachViewHierarchy = true,
    appRunner: () => runApp(
      DefaultAssetBundle(
        bundle: SentryAssetBundle(),
        child: UncontrolledProviderScope(
          container: container,
          child: SentryScreenshotWidget(
            child: const App(),
          ),
        ),
      ),
    ),
  );
  // キャッシュのサイズを設定
  int maxCacheSize = 100 * 1024 * 1024; // 100MB のキャッシュサイズ
  int maxCacheEntries = 100; // 最大100エントリ

  PaintingBinding.instance.imageCache.maximumSize = maxCacheEntries;
  PaintingBinding.instance.imageCache.maximumSizeBytes = maxCacheSize;
}