@@ -3,49 +3,86 @@ import 'package:flutter/material.dart';
33import 'package:supabase_flutter/supabase_flutter.dart' ;
44import 'package:athlete_alumni/core/di/injection.dart' as di;
55import 'package:athlete_alumni/core/router/app_router.dart' ;
6- import 'package:flutter_dotenv/flutter_dotenv.dart' ;
6+ import 'package:athlete_alumni/utils/environment.dart' ;
7+ import 'package:athlete_alumni/core/config/supabase_config.dart' ;
78
89void main () async {
910 WidgetsFlutterBinding .ensureInitialized ();
1011
11- // Load .env file first
1212 try {
13- await dotenv.load (fileName: ".env" );
14- print ('✅ Loaded .env file successfully' );
15-
16- // Get and log Supabase configuration (without the actual key)
17- final supabaseUrl = dotenv.get ('SUPABASE_URL' );
18- print ('🔍 Supabase URL configured as: $supabaseUrl ' );
13+ // Initialize environment variables first
14+ await Environment .initialize ();
15+ if (kDebugMode) {
16+ print ('✅ Environment initialized successfully' );
17+
18+ // Get and log Supabase configuration
19+ final supabaseUrl = Environment .supabaseUrl;
20+ print ('🔍 Supabase URL configured as: $supabaseUrl ' );
21+ print ('🔍 URL length: ${supabaseUrl .length }' );
22+ }
1923
20- // Initialize Supabase
21- await Supabase .initialize (
22- url: supabaseUrl,
23- anonKey: dotenv.get ('SUPABASE_ANON_KEY' ),
24- );
25- print ('✅ Supabase initialized successfully' );
24+ // Initialize Supabase using our config
25+ await SupabaseConfig .initialize ();
26+ if (kDebugMode) {
27+ print ('✅ Supabase initialized successfully' );
28+ }
2629
2730 // Initialize dependency injection
2831 await di.init ();
29- print ('✅ Dependency injection initialized' );
32+ if (kDebugMode) {
33+ print ('✅ Dependency injection initialized' );
34+ }
3035
3136 runApp (const MyApp ());
3237
33- } catch (e) {
34- print ('❌ Error during initialization:' );
35- print ('Error type: ${e .runtimeType }' );
36- print ('Error details: $e ' );
37-
38- if (e is Error ) {
39- print ('Stack trace: ${e .stackTrace }' );
38+ } catch (e, stackTrace) {
39+ if (kDebugMode) {
40+ print ('❌ Error during initialization:' );
41+ print ('Error type: ${e .runtimeType }' );
42+ print ('Error details: $e ' );
43+ print ('Stack trace: $stackTrace ' );
4044 }
4145
4246 // Show error UI instead of crashing
4347 runApp (MaterialApp (
4448 home: Scaffold (
4549 body: Center (
46- child: Text (
47- 'Error initializing app: ${e .toString ()}' ,
48- style: const TextStyle (color: Colors .red),
50+ child: Padding (
51+ padding: const EdgeInsets .all (20.0 ),
52+ child: Column (
53+ mainAxisAlignment: MainAxisAlignment .center,
54+ children: [
55+ const Icon (
56+ Icons .error_outline,
57+ color: Colors .red,
58+ size: 60 ,
59+ ),
60+ const SizedBox (height: 20 ),
61+ Text (
62+ 'Error initializing app:' ,
63+ style: const TextStyle (
64+ color: Colors .red,
65+ fontSize: 18 ,
66+ fontWeight: FontWeight .bold,
67+ ),
68+ ),
69+ const SizedBox (height: 10 ),
70+ Text (
71+ e.toString (),
72+ style: const TextStyle (color: Colors .red),
73+ textAlign: TextAlign .center,
74+ ),
75+ const SizedBox (height: 30 ),
76+ ElevatedButton (
77+ onPressed: () {
78+ // This is a simple restart attempt
79+ // In a real app, you'd want a more robust solution
80+ main ();
81+ },
82+ child: const Text ('Try Again' ),
83+ ),
84+ ],
85+ ),
4986 ),
5087 ),
5188 ),
0 commit comments