diff --git a/lib/firebase_options.dart b/lib/firebase_options_dev.dart similarity index 98% rename from lib/firebase_options.dart rename to lib/firebase_options_dev.dart index 703411a9..93e8600c 100644 --- a/lib/firebase_options.dart +++ b/lib/firebase_options_dev.dart @@ -14,7 +14,7 @@ import 'package:flutter/foundation.dart' /// options: DefaultFirebaseOptions.currentPlatform, /// ); /// ``` -class DefaultFirebaseOptions { +class DefaultFirebaseOptionsDev { static FirebaseOptions get currentPlatform { if (kIsWeb) { return web; diff --git a/lib/firebase_options_prod.dart b/lib/firebase_options_prod.dart new file mode 100644 index 00000000..485696b8 --- /dev/null +++ b/lib/firebase_options_prod.dart @@ -0,0 +1,77 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: type=lint +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb, TargetPlatform; + +/// Default [FirebaseOptions] for use with your Firebase apps. +/// +/// Example: +/// ```dart +/// import 'firebase_options.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptionsStaging { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + return web; + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return android; + case TargetPlatform.iOS: + return ios; + case TargetPlatform.macOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for macos - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.windows: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for windows - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions android = FirebaseOptions( + apiKey: 'AIzaSyDP9GpYfLE8gHTj3kZ1hW8fx_FkJqOqSQk', + appId: '1:786692570726:android:0ef7079c2b978d4417b7a7', + messagingSenderId: '786692570726', + projectId: 'syncrow-staging', + databaseURL: 'https://syncrow-staging-default-rtdb.firebaseio.com', + storageBucket: 'syncrow-staging.appspot.com', + ); + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyAWlRiuJ75FMlf2_UDdri1voWKvkaSHtRg', + appId: '1:786692570726:ios:455a6fcff77e130f17b7a7', + messagingSenderId: '786692570726', + projectId: 'syncrow-staging', + databaseURL: 'https://syncrow-staging-default-rtdb.firebaseio.com', + storageBucket: 'syncrow-staging.appspot.com', + iosBundleId: 'com.example.syncrow.app', + ); + + static const FirebaseOptions web = FirebaseOptions( + apiKey: 'AIzaSyDyGaQ3sZhb4meaY6sGke-YglhdhJ2is8Q', + appId: '1:786692570726:web:93c931e6701797b317b7a7', + messagingSenderId: '786692570726', + projectId: 'syncrow-staging', + authDomain: 'syncrow-staging.firebaseapp.com', + databaseURL: 'https://syncrow-staging-default-rtdb.firebaseio.com', + storageBucket: 'syncrow-staging.appspot.com', + measurementId: 'G-CZ3J3G6LMQ', + ); +} diff --git a/lib/main.dart b/lib/main.dart index 67880868..ecc3b947 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,7 +4,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:go_router/go_router.dart'; -import 'package:syncrow_web/firebase_options.dart'; +import 'package:syncrow_web/firebase_options_dev.dart'; +import 'package:syncrow_web/firebase_options_prod.dart'; import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart'; import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; import 'package:syncrow_web/pages/home/bloc/home_event.dart'; @@ -20,11 +21,11 @@ import 'package:syncrow_web/utils/theme/theme.dart'; Future main() async { try { const environment = - String.fromEnvironment('FLAVOR', defaultValue: 'development'); + String.fromEnvironment('FLAVOR', defaultValue: 'production'); await dotenv.load(fileName: '.env.$environment'); WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( - options: DefaultFirebaseOptions.currentPlatform, + options: DefaultFirebaseOptionsStaging.currentPlatform, ); initialSetup(); } catch (_) {} diff --git a/lib/main_dev.dart b/lib/main_dev.dart new file mode 100644 index 00000000..9d00ebf7 --- /dev/null +++ b/lib/main_dev.dart @@ -0,0 +1,84 @@ +import 'package:firebase_core/firebase_core.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:go_router/go_router.dart'; +import 'package:syncrow_web/firebase_options_dev.dart'; +import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart'; +import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; +import 'package:syncrow_web/pages/home/bloc/home_event.dart'; +import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; +import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart'; +import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart'; +import 'package:syncrow_web/services/locator.dart'; +import 'package:syncrow_web/utils/app_routes.dart'; +import 'package:syncrow_web/utils/constants/routes_const.dart'; +import 'package:syncrow_web/utils/theme/theme.dart'; + +Future main() async { + try { + const environment = + String.fromEnvironment('FLAVOR', defaultValue: 'development'); + await dotenv.load(fileName: '.env.$environment'); + WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp( + options: DefaultFirebaseOptionsDev.currentPlatform, + ); + initialSetup(); + } catch (_) {} + runApp(MyApp()); +} + +class MyApp extends StatelessWidget { + MyApp({ + super.key, + }); + + final GoRouter _router = GoRouter( + initialLocation: RoutesConst.auth, + routes: AppRoutes.getRoutes(), + redirect: (context, state) async { + String checkToken = await AuthBloc.getTokenAndValidate(); + final loggedIn = checkToken == 'Success'; + final goingToLogin = state.uri.toString() == RoutesConst.auth; + + if (!loggedIn && !goingToLogin) return RoutesConst.auth; + if (loggedIn && goingToLogin) return RoutesConst.home; + + return null; + }, + ); + + @override + Widget build(BuildContext context) { + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => HomeBloc()..add(const FetchUserInfo())), + BlocProvider( + create: (context) => VisitorPasswordBloc(), + ), + BlocProvider( + create: (context) => RoutineBloc(), + ), + BlocProvider( + create: (context) => SpaceTreeBloc()..add(InitialEvent()), + ), + ], + child: MaterialApp.router( + debugShowCheckedModeBanner: false, + scrollBehavior: const MaterialScrollBehavior().copyWith( + dragDevices: { + PointerDeviceKind.mouse, + PointerDeviceKind.touch, + PointerDeviceKind.stylus, + PointerDeviceKind.unknown, + }, + ), + theme: myTheme, + routerConfig: _router, + )); + } +}