ponshu-room-lite/lib/main.dart

113 lines
3.9 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; // Localization
import 'package:hive_flutter/hive_flutter.dart';
import 'models/sake_item.dart';
import 'models/user_profile.dart';
import 'models/menu_settings.dart';
import 'providers/theme_provider.dart';
import 'screens/main_screen.dart';
import 'services/migration_service.dart';
/// Pro版かLite版かを判定するビルド時フラグ
///
/// ビルドコマンド:
/// - Pro版: flutter build apk --release --dart-define=IS_PRO_VERSION=true
/// - Lite版: flutter build apk --release --dart-define=IS_PRO_VERSION=false
///
/// デフォルトはfalseLite版 ※ponshu_room_liteディレクトリのため
const bool isProVersion = bool.fromEnvironment('IS_PRO_VERSION', defaultValue: false);
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 🔍 DEBUG: Check IS_PRO_VERSION flag
debugPrint('🔍 IS_PRO_VERSION = $isProVersion');
// Initialize Hive
await Hive.initFlutter();
// Register Adapters
Hive.registerAdapter(SakeItemAdapter());
Hive.registerAdapter(UserProfileAdapter());
Hive.registerAdapter(MenuSettingsAdapter());
// Phase 0 New Adapters
Hive.registerAdapter(DisplayDataAdapter());
Hive.registerAdapter(HiddenSpecsAdapter());
Hive.registerAdapter(UserDataAdapter());
Hive.registerAdapter(GamificationAdapter());
Hive.registerAdapter(MetadataAdapter());
Hive.registerAdapter(ItemTypeAdapter()); // Restored missing adapter
// Open all boxes first (faster to open them together)
// Reverted to synchronous wait to ensure Providers have data immediately
// Open all boxes in parallel (Much faster than sequential)
await Future.wait([
Hive.openBox('settings'),
Hive.openBox<UserProfile>('user_profile'),
Hive.openBox<SakeItem>('sake_items'),
Hive.openBox<MenuSettings>('menu_settings'),
]);
// Run Phase 0 Migration (Only once)
final box = Hive.box('settings');
final migrationCompleted = box.get('migration_completed', defaultValue: false);
if (!migrationCompleted) {
debugPrint('🚀 Running MigrationService...');
await MigrationService.runMigration();
await box.put('migration_completed', true);
} else {
debugPrint('✅ Migration already completed. Skipping.');
}
// ✅ AI解析キャッシュは使うときに初期化するLazy initialization
// AnalysisCacheService.init()はサービス内でLazy実装されているため、
// ここで呼び出すと起動が遅くなる。必要なときに自動初期化される。
runApp(
const ProviderScope(
child: MyApp(),
),
);
}
class MyApp extends ConsumerWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final lightTheme = ref.watch(lightThemeProvider);
final darkTheme = ref.watch(darkThemeProvider);
final themeMode = ref.watch(themeModeProvider);
final locale = ref.watch(localeProvider); // NEW: User-selected locale
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Ponshu Room Lite',
theme: lightTheme,
darkTheme: darkTheme,
themeMode: themeMode,
locale: locale, // NEW: Apply user's locale choice
// Localization (UPDATED)
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('ja'), // 日本語
Locale('en'), // English
// Phase 2: フランス語・ドイツ語を追加予定
// Locale('fr'), // Français
// Locale('de'), // Deutsch
],
navigatorObservers: [routeObserver],
home: const MainScreen(),
);
}
}
// Global RouteObserver
final RouteObserver<ModalRoute<void>> routeObserver = RouteObserver<ModalRoute<void>>();