diff --git a/frontend/complycore_flutter/lib/config/env.dart b/frontend/complycore_flutter/lib/config/env.dart new file mode 100644 index 0000000..ae7e22c --- /dev/null +++ b/frontend/complycore_flutter/lib/config/env.dart @@ -0,0 +1,11 @@ +// lib/config/env.dart +import 'package:flutter_dotenv/flutter_dotenv.dart'; + +class Env { + static Future load() async { + await dotenv.load(); // loads .env from assets + } + + static String get supabaseUrl => dotenv.get('SUPABASE_URL'); + static String get supabaseAnon => dotenv.get('SUPABASE_ANON_KEY'); +} diff --git a/frontend/complycore_flutter/lib/main.dart b/frontend/complycore_flutter/lib/main.dart index 95b9df7..0a9cb64 100644 --- a/frontend/complycore_flutter/lib/main.dart +++ b/frontend/complycore_flutter/lib/main.dart @@ -1,4 +1,6 @@ +// lib/main.dart import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; import 'screens/splash_screen.dart'; @@ -6,17 +8,18 @@ import 'screens/splash_screen.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); - await Supabase.initialize( - url: const String.fromEnvironment( - 'SUPABASE_URL', - defaultValue: 'https://YOUR-SUPABASE-URL.supabase.co', - ), - anonKey: const String.fromEnvironment( - 'SUPABASE_ANON_KEY', - defaultValue: 'YOUR-SUPABASE-ANON-KEY', - ), - ); + // Load variables from .env (added as asset in pubspec.yaml) + await dotenv.load(fileName: '.env'); + final supabaseUrl = dotenv.env['SUPABASE_URL']; + final supabaseAnonKey = dotenv.env['SUPABASE_ANON_KEY']; + + assert(supabaseUrl != null && supabaseAnonKey != null); + + // Initialise Supabase with the values from .env + await Supabase.initialize(url: supabaseUrl!, anonKey: supabaseAnonKey!); + + // Launch the app runApp(const ComplyCoreApp()); } @@ -24,9 +27,11 @@ class ComplyCoreApp extends StatelessWidget { const ComplyCoreApp({super.key}); @override - Widget build(BuildContext context) => MaterialApp( - title: 'ComplyCore', - theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true), - home: const SplashScreen(), - ); + Widget build(BuildContext context) { + return MaterialApp( + title: 'ComplyCore', + theme: ThemeData(useMaterial3: true, primarySwatch: Colors.blue), + home: const SplashScreen(), + ); + } } diff --git a/frontend/complycore_flutter/pubspec.yaml b/frontend/complycore_flutter/pubspec.yaml index 309457e..79f3515 100644 --- a/frontend/complycore_flutter/pubspec.yaml +++ b/frontend/complycore_flutter/pubspec.yaml @@ -40,6 +40,7 @@ dependencies: http: ^1.2.0 dart_jsonwebtoken: ^2.12.1 + dev_dependencies: flutter_test: sdk: flutter @@ -57,12 +58,14 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: + # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true - # To add assets to your application, add an assets section, like this: + assets: + - .env # assets: # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg