141 lines
5.9 KiB
Dart
141 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:lucide_icons/lucide_icons.dart';
|
|
import '../main.dart'; // Import isProVersion flag
|
|
import '../providers/theme_provider.dart'; // Access userProfileProvider
|
|
import '../providers/navigation_provider.dart'; // Track current tab index
|
|
import '../utils/translations.dart'; // Translation helper
|
|
import '../widgets/pro_locked_screen.dart'; // Pro版ロック画面
|
|
import 'home_screen.dart';
|
|
import 'soul_screen.dart';
|
|
import 'shop_settings_screen.dart';
|
|
import 'placeholders/placeholders.dart';
|
|
|
|
class MainScreen extends ConsumerStatefulWidget {
|
|
const MainScreen({super.key});
|
|
|
|
@override
|
|
ConsumerState<MainScreen> createState() => _MainScreenState();
|
|
}
|
|
|
|
class _MainScreenState extends ConsumerState<MainScreen> {
|
|
int _currentIndex = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Listen for mode changes to reset navigation to Home
|
|
ref.listen(userProfileProvider.select((value) => value.isBusinessMode), (previous, next) {
|
|
if (previous != next) {
|
|
setState(() {
|
|
_currentIndex = 0;
|
|
ref.read(currentTabIndexProvider.notifier).setIndex(0); // Reset to home tab
|
|
});
|
|
}
|
|
});
|
|
|
|
// CRITICAL FIX: Listen for external tab index changes (e.g. from SoulScreen)
|
|
ref.listen(currentTabIndexProvider, (previous, next) {
|
|
if (next != _currentIndex) {
|
|
setState(() {
|
|
_currentIndex = next;
|
|
});
|
|
}
|
|
});
|
|
|
|
final userProfile = ref.watch(userProfileProvider);
|
|
final isBusiness = userProfile.isBusinessMode;
|
|
final t = Translations(userProfile.locale); // Translation helper
|
|
|
|
// 🔍 DEBUG: Check IS_PRO_VERSION flag
|
|
debugPrint('🔍 MainScreen: IS_PRO_VERSION = $isProVersion, isBusiness = $isBusiness');
|
|
|
|
// Define Screens for each mode
|
|
// Pro版かLite版かで画面を切り替え
|
|
final List<Widget> screens = isBusiness
|
|
? [
|
|
const HomeScreen(), // Inventory Management (FAB opens Menu Creation)
|
|
// Instagram Support: Pro版のみ
|
|
isProVersion
|
|
? const InstaSupportScreen()
|
|
: ProLockedScreen(
|
|
featureName: t['promo'],
|
|
featureIcon: LucideIcons.instagram,
|
|
description: userProfile.locale == 'ja'
|
|
? 'Instagram用の魅力的な投稿を自動生成。\n酒の写真とAI解析を活用して、\nプロモーションをサポートします。'
|
|
: 'Auto-generate attractive Instagram posts.\nLeverage sake photos and AI analysis\nto boost your promotion.',
|
|
),
|
|
// Analytics: Pro版のみ
|
|
isProVersion
|
|
? const AnalyticsScreen()
|
|
: ProLockedScreen(
|
|
featureName: t['analytics'],
|
|
featureIcon: LucideIcons.barChart,
|
|
description: userProfile.locale == 'ja'
|
|
? '在庫状況や人気銘柄を分析。\nビジネスの意思決定を\nデータで支援します。'
|
|
: 'Analyze inventory and popular brands.\nSupport business decisions\nwith data insights.',
|
|
),
|
|
const ShopSettingsScreen(), // Shop Settings
|
|
]
|
|
: [
|
|
const HomeScreen(), // My Sake List
|
|
// QR Scan: Pro版のみ
|
|
isProVersion
|
|
? const ScanARScreen()
|
|
: ProLockedScreen(
|
|
featureName: t['scan'],
|
|
featureIcon: LucideIcons.scanLine,
|
|
description: userProfile.locale == 'ja'
|
|
? 'QRコードをスキャンして、\n酒の情報を素早く登録。\nAR表示で楽しく記録できます。'
|
|
: 'Scan QR codes to quickly register\nsake information.\nEnjoy recording with AR display.',
|
|
),
|
|
const SommelierScreen(),
|
|
const BreweryMapScreen(),
|
|
const SoulScreen(), // MyPage/Settings
|
|
];
|
|
|
|
// Define Navigation Items (with translation)
|
|
final List<NavigationDestination> destinations = isBusiness
|
|
? [
|
|
NavigationDestination(
|
|
icon: const Padding(padding: EdgeInsets.only(bottom: 2), child: Text('🍶', style: TextStyle(fontSize: 22))),
|
|
label: t['home'],
|
|
),
|
|
NavigationDestination(icon: const Icon(LucideIcons.instagram), label: t['promo']),
|
|
NavigationDestination(icon: const Icon(LucideIcons.barChart), label: t['analytics']),
|
|
NavigationDestination(icon: const Icon(LucideIcons.store), label: t['shop']),
|
|
]
|
|
: [
|
|
NavigationDestination(
|
|
icon: const Padding(padding: EdgeInsets.only(bottom: 2), child: Text('🍶', style: TextStyle(fontSize: 22))),
|
|
label: t['home'],
|
|
),
|
|
NavigationDestination(icon: const Icon(LucideIcons.scanLine), label: t['scan']),
|
|
NavigationDestination(icon: const Icon(LucideIcons.sparkles), label: t['sommelier']),
|
|
NavigationDestination(icon: const Icon(LucideIcons.map), label: t['map']),
|
|
NavigationDestination(icon: const Icon(LucideIcons.user), label: t['myPage']),
|
|
];
|
|
|
|
// Safety: Reset index if out of bounds (shouldn't happen if lengths match)
|
|
if (_currentIndex >= screens.length) _currentIndex = 0;
|
|
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: IndexedStack(
|
|
index: _currentIndex,
|
|
children: screens,
|
|
),
|
|
),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: _currentIndex,
|
|
onDestinationSelected: (index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
ref.read(currentTabIndexProvider.notifier).setIndex(index); // Update global tab state
|
|
});
|
|
},
|
|
destinations: destinations,
|
|
),
|
|
);
|
|
}
|
|
}
|