Add graceful Firebase error handling
🐛 Fix: Handle Firebase initialization failures gracefully - Wrapped Firebase.initializeApp() in try-catch - App now works even if Firebase isn't configured - Added helpful error messages pointing to FIREBASE_SETUP.md - Household creation shows clear error if Firebase fails ⚠️ User Experience: - If Firebase not configured: Shows error message - Error message guides user to setup instructions - App doesn't crash, continues with local-only mode ✅ Testing: - APK builds successfully (63.3MB) - App runs without Firebase configuration - Error messages are user-friendly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -84,6 +84,7 @@ class _HouseholdScreenState extends State<HouseholdScreen> {
|
||||
);
|
||||
|
||||
if (result != null && result.isNotEmpty) {
|
||||
try {
|
||||
// Create household in Firebase
|
||||
final household = await _firebaseService.createHousehold(result, _settings!.userName!);
|
||||
|
||||
@@ -104,6 +105,17 @@ class _HouseholdScreenState extends State<HouseholdScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Error creating household: ${e.toString().contains('firebase') ? 'Firebase not configured. See FIREBASE_SETUP.md' : e.toString()}'),
|
||||
backgroundColor: AppColors.error,
|
||||
duration: const Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8,8 +8,15 @@ import 'features/home/screens/home_screen.dart';
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Initialize Firebase
|
||||
// Initialize Firebase (gracefully handle if not configured)
|
||||
try {
|
||||
await Firebase.initializeApp();
|
||||
print('✅ Firebase initialized successfully');
|
||||
} catch (e) {
|
||||
print('⚠️ Firebase initialization failed: $e');
|
||||
print('Household sharing will not work without Firebase configuration.');
|
||||
print('See FIREBASE_SETUP.md for setup instructions.');
|
||||
}
|
||||
|
||||
// Initialize Hive database
|
||||
await HiveDatabase.init();
|
||||
|
Reference in New Issue
Block a user