From b90179107913acf7cf83cb2c8dfaf5d2016089c3 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Tue, 22 Apr 2025 02:33:50 +0300 Subject: [PATCH] Update Flutter run and build commands, and added main_staging file --- ...e-static-web-apps-mango-bush-01e607f10.yml | 2 +- ...static-web-apps-polite-smoke-017c65c10.yml | 2 +- .vscode/launch.json | 39 +++++---- README.md | 9 +- lib/main_staging.dart | 86 +++++++++++++++++++ .../space_tree/view/space_tree_view.dart | 82 ++++++++---------- 6 files changed, 157 insertions(+), 63 deletions(-) create mode 100644 lib/main_staging.dart diff --git a/.github/workflows/azure-static-web-apps-mango-bush-01e607f10.yml b/.github/workflows/azure-static-web-apps-mango-bush-01e607f10.yml index f0379c95..cd1168fc 100644 --- a/.github/workflows/azure-static-web-apps-mango-bush-01e607f10.yml +++ b/.github/workflows/azure-static-web-apps-mango-bush-01e607f10.yml @@ -31,7 +31,7 @@ jobs: run: flutter pub get - name: Build Flutter Web App - run: flutter build web --release --dart-define=FLAVOR=production + run: flutter build web --web-renderer canvaskit --flavor production -t lib/main.dart - name: Build And Deploy id: builddeploy diff --git a/.github/workflows/azure-static-web-apps-polite-smoke-017c65c10.yml b/.github/workflows/azure-static-web-apps-polite-smoke-017c65c10.yml index 28cf00a2..1edcb974 100644 --- a/.github/workflows/azure-static-web-apps-polite-smoke-017c65c10.yml +++ b/.github/workflows/azure-static-web-apps-polite-smoke-017c65c10.yml @@ -31,7 +31,7 @@ jobs: run: flutter pub get - name: Build Flutter Web App - run: flutter build web --release --dart-define=FLAVOR=development + run: flutter build web --web-renderer canvaskit --flavor development -t lib/main_dev.dart - name: Build And Deploy id: builddeploy diff --git a/.vscode/launch.json b/.vscode/launch.json index b6f83bdc..ab5f8f0e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,11 +10,14 @@ "type": "dart", "args": [ - - "--dart-define", - - "FLAVOR=development" - + "-d", + "chrome", + "--web-port", + "3000", + "--flavor", + "development", + "-t", + "lib/main_dev.dart", ], "flutterMode": "debug" @@ -28,11 +31,14 @@ "type": "dart", "args": [ - - "--dart-define", - - "FLAVOR=staging" - + "-d", + "chrome", + "--web-port", + "3000", + "--flavor", + "staging", + "-t", + "lib/main_staging.dart", ], "flutterMode": "debug" @@ -46,11 +52,14 @@ "type": "dart", "args": [ - - "--dart-define", - - "FLAVOR=production" - + "-d", + "chrome", + "--web-port", + "3000", + "--flavor", + "production", + "-t", + "lib/main_staging.dart", ], "flutterMode": "debug" diff --git a/README.md b/README.md index 745fe6f0..6a3cc51b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,12 @@ samples, guidance on mobile development, and a full API reference. ## USEFUL COMMANDS -Run on chrome: flutter run -d chrome --dart-define=FLAVOR='ENV_NAME' +- Building for the Web + - CanvasKit + - `flutter build web --web-renderer canvaskit --flavor development -t lib/main_dev.dart --output=build/web_dev` - build for DEVELOPMENT. + - `flutter build web --web-renderer canvaskit --flavor staging -t lib/main_staging.dart --output=build/web_stg` - build for STAGING. + - `flutter build web --web-renderer canvaskit --flavor production -t lib/main.dart --output=build/web` - build for PRODUCTION. + +- run command: `flutter run -d chrome --flavor development --target=lib/main_dev.dart` -Build: flutter build web --release --dart-define=FLAVOR='ENV_NAME' diff --git a/lib/main_staging.dart b/lib/main_staging.dart new file mode 100644 index 00000000..b0505c85 --- /dev/null +++ b/lib/main_staging.dart @@ -0,0 +1,86 @@ +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/create_routine_bloc/create_routine_bloc.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: 'staging'); + 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) => CreateRoutineBloc(), + ), + 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, + )); + } +} diff --git a/lib/pages/space_tree/view/space_tree_view.dart b/lib/pages/space_tree/view/space_tree_view.dart index 3d5d00bf..bfe3a2bd 100644 --- a/lib/pages/space_tree/view/space_tree_view.dart +++ b/lib/pages/space_tree/view/space_tree_view.dart @@ -41,14 +41,12 @@ class _SpaceTreeViewState extends State { @override Widget build(BuildContext context) { return BlocBuilder(builder: (context, state) { - final communities = state.searchQuery.isNotEmpty - ? state.filteredCommunity - : state.communityList; + final communities = + state.searchQuery.isNotEmpty ? state.filteredCommunity : state.communityList; return Container( height: MediaQuery.sizeOf(context).height, decoration: widget.isSide == true - ? subSectionContainerDecoration.copyWith( - color: ColorsManager.whiteColors) + ? subSectionContainerDecoration.copyWith(color: ColorsManager.whiteColors) : const BoxDecoration(color: ColorsManager.whiteColors), child: state is SpaceTreeLoadingState ? const Center(child: CircularProgressIndicator()) @@ -81,12 +79,10 @@ class _SpaceTreeViewState extends State { style: context.textTheme.bodyMedium?.copyWith( color: ColorsManager.blackColor, ), - onChanged: (value) => - context.read().add( - SearchQueryEvent(value), - ), - decoration: - textBoxDecoration(radios: 20)?.copyWith( + onChanged: (value) => context.read().add( + SearchQueryEvent(value), + ), + decoration: textBoxDecoration(radios: 20)?.copyWith( fillColor: Colors.white, suffixIcon: Padding( padding: const EdgeInsets.only(right: 16), @@ -96,8 +92,7 @@ class _SpaceTreeViewState extends State { height: 24, ), ), - hintStyle: - context.textTheme.bodyMedium?.copyWith( + hintStyle: context.textTheme.bodyMedium?.copyWith( fontWeight: FontWeight.w400, fontSize: 12, color: ColorsManager.textGray, @@ -121,27 +116,30 @@ class _SpaceTreeViewState extends State { child: state.isSearching ? const Center(child: CircularProgressIndicator()) : SidebarCommunitiesList( - onScrollToEnd: () => context.read().add( - PaginationEvent( - state.paginationModel, - state.communityList, - ), - ), + onScrollToEnd: () { + if (!state.paginationIsLoading) { + context.read().add( + PaginationEvent( + state.paginationModel, + state.communityList, + ), + ); + } + }, scrollController: _scrollController, communities: communities, itemBuilder: (context, index) { return CustomExpansionTileSpaceTree( title: communities[index].name, - isSelected: state.selectedCommunities - .contains(communities[index].uuid), - isSoldCheck: state.selectedCommunities - .contains(communities[index].uuid), - onExpansionChanged: () => - context.read().add( - OnCommunityExpanded( - communities[index].uuid, - ), - ), + isSelected: + state.selectedCommunities.contains(communities[index].uuid), + isSoldCheck: + state.selectedCommunities.contains(communities[index].uuid), + onExpansionChanged: () => context.read().add( + OnCommunityExpanded( + communities[index].uuid, + ), + ), isExpanded: state.expandedCommunities.contains( communities[index].uuid, ), @@ -158,8 +156,7 @@ class _SpaceTreeViewState extends State { (space) { return CustomExpansionTileSpaceTree( title: space.name, - isExpanded: - state.expandedSpaces.contains(space.uuid), + isExpanded: state.expandedSpaces.contains(space.uuid), onItemSelected: () { context.read().add( OnSpaceSelected( @@ -170,18 +167,15 @@ class _SpaceTreeViewState extends State { ); widget.onSelect(); }, - onExpansionChanged: () => - context.read().add( - OnSpaceExpanded( - communities[index].uuid, - space.uuid ?? '', - ), - ), - isSelected: state.selectedSpaces - .contains(space.uuid) || - state.soldCheck.contains(space.uuid), - isSoldCheck: + onExpansionChanged: () => context.read().add( + OnSpaceExpanded( + communities[index].uuid, + space.uuid ?? '', + ), + ), + isSelected: state.selectedSpaces.contains(space.uuid) || state.soldCheck.contains(space.uuid), + isSoldCheck: state.soldCheck.contains(space.uuid), children: _buildNestedSpaces( context, state, @@ -210,8 +204,8 @@ class _SpaceTreeViewState extends State { ) { return space.children.map((child) { return CustomExpansionTileSpaceTree( - isSelected: state.selectedSpaces.contains(child.uuid) || - state.soldCheck.contains(child.uuid), + isSelected: + state.selectedSpaces.contains(child.uuid) || state.soldCheck.contains(child.uuid), isSoldCheck: state.soldCheck.contains(child.uuid), title: child.name, isExpanded: state.expandedSpaces.contains(child.uuid),