diff --git a/lib/features/app_layout/bloc/spaces_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart similarity index 96% rename from lib/features/app_layout/bloc/spaces_cubit.dart rename to lib/features/app_layout/bloc/home_cubit.dart index c763847..17cedeb 100644 --- a/lib/features/app_layout/bloc/spaces_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -14,11 +14,11 @@ import 'package:syncrow_app/services/api/network_exception.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; -part 'spaces_state.dart'; +part 'home_state.dart'; -class SpacesCubit extends Cubit { - SpacesCubit() : super(SpacesInitial()) { - if (SpacesCubit.spaces != null) { +class HomeCubit extends Cubit { + HomeCubit() : super(SpacesInitial()) { + if (HomeCubit.spaces != null) { if (selectedSpace == null) { fetchSpaces().then((value) { if (selectedSpace != null) { @@ -32,7 +32,7 @@ class SpacesCubit extends Cubit { } } - static SpacesCubit get(context) => BlocProvider.of(context); + static HomeCubit get(context) => BlocProvider.of(context); static List? spaces; @@ -236,7 +236,7 @@ class SpacesCubit extends Cubit { ), }; - var bottomNavItems = [ + static var bottomNavItems = [ defaultBottomNavBarItem(icon: Assets.iconsDashboard, label: 'Dashboard'), // defaultBottomNavBarItem(icon: Assets.iconslayout, label: 'Layout'), defaultBottomNavBarItem(icon: Assets.iconsDevices, label: 'Devices'), diff --git a/lib/features/app_layout/bloc/spaces_state.dart b/lib/features/app_layout/bloc/home_state.dart similarity index 96% rename from lib/features/app_layout/bloc/spaces_state.dart rename to lib/features/app_layout/bloc/home_state.dart index ddd144f..017fcf9 100644 --- a/lib/features/app_layout/bloc/spaces_state.dart +++ b/lib/features/app_layout/bloc/home_state.dart @@ -1,4 +1,4 @@ -part of 'spaces_cubit.dart'; +part of 'home_cubit.dart'; abstract class SpacesState {} diff --git a/lib/features/app_layout/view/app_layout.dart b/lib/features/app_layout/view/app_layout.dart index 4f8a9e2..6b7d0c4 100644 --- a/lib/features/app_layout/view/app_layout.dart +++ b/lib/features/app_layout/view/app_layout.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/app_layout/view/widgets/app_body.dart'; import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart'; import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart'; @@ -18,13 +18,13 @@ class AppLayout extends StatelessWidget { return MultiBlocProvider( providers: [ BlocProvider( - create: (context) => SpacesCubit(), + create: (context) => HomeCubit(), ), BlocProvider( create: (context) => DevicesCubit(), ), ], - child: BlocListener( + child: BlocListener( listener: (context, state) { if (state is GetSpacesError) { ScaffoldMessenger.of(context).showSnackBar( @@ -36,7 +36,7 @@ class AppLayout extends StatelessWidget { .popUntil((route) => route.settings.name == Routes.authLogin); } }, - child: BlocBuilder( + child: BlocBuilder( builder: (context, state) { return AnnotatedRegion( value: SystemUiOverlayStyle( @@ -44,7 +44,7 @@ class AppLayout extends StatelessWidget { statusBarIconBrightness: Brightness.light, ), child: SafeArea( - child: BlocBuilder( + child: BlocBuilder( builder: (context, state) { return Scaffold( backgroundColor: ColorsManager.backgroundColor, diff --git a/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart b/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart index aa2ac17..edbb684 100644 --- a/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart +++ b/lib/features/app_layout/view/widgets/app_bar_home_dropdown.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; @@ -15,9 +15,9 @@ class AppBarHomeDropdown extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { - return SpacesCubit.selectedSpace == null + return HomeCubit.selectedSpace == null ? const Center(child: BodyMedium(text: 'No Home Selected')) : Padding( padding: const EdgeInsets.only(left: 10, right: 10), @@ -30,8 +30,8 @@ class AppBarHomeDropdown extends StatelessWidget { underline: const SizedBox.shrink(), padding: const EdgeInsets.all(0), borderRadius: BorderRadius.circular(20), - value: SpacesCubit.selectedSpace!.id, - items: SpacesCubit.spaces!.map((space) { + value: HomeCubit.selectedSpace!.id, + items: HomeCubit.spaces!.map((space) { return DropdownMenuItem( value: space.id, child: SizedBox( @@ -67,7 +67,7 @@ class AppBarHomeDropdown extends StatelessWidget { }).toList(), onChanged: (value) { if (value != null) { - SpacesCubit.get(context).selectSpace(SpacesCubit.spaces! + HomeCubit.get(context).selectSpace(HomeCubit.spaces! .firstWhere((element) => element.id == value)); } }, diff --git a/lib/features/app_layout/view/widgets/app_body.dart b/lib/features/app_layout/view/widgets/app_body.dart index 0e3ddbd..e4ea499 100644 --- a/lib/features/app_layout/view/widgets/app_body.dart +++ b/lib/features/app_layout/view/widgets/app_body.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import '../../../../generated/assets.dart'; @@ -12,7 +12,7 @@ class AppBody extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { return Container( width: MediaQuery.sizeOf(context).width, @@ -26,7 +26,7 @@ class AppBody extends StatelessWidget { opacity: 0.4, ), ), - child: BlocConsumer( + child: BlocConsumer( listener: (context, state) { if (state is GetSpacesError) { ScaffoldMessenger.of(context).showSnackBar( @@ -39,7 +39,7 @@ class AppBody extends StatelessWidget { builder: (context, state) { return state is! GetSpacesLoading || state is! GetSpaceRoomsLoading - ? SpacesCubit.get(context).pages[SpacesCubit.pageIndex] + ? HomeCubit.get(context).pages[HomeCubit.pageIndex] : const Center(child: CircularProgressIndicator()); }, ), diff --git a/lib/features/app_layout/view/widgets/default_app_bar.dart b/lib/features/app_layout/view/widgets/default_app_bar.dart index 78fb2ef..7812e22 100644 --- a/lib/features/app_layout/view/widgets/default_app_bar.dart +++ b/lib/features/app_layout/view/widgets/default_app_bar.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget { @@ -9,7 +9,7 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { return Padding( padding: const EdgeInsets.only( @@ -19,15 +19,14 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget { backgroundColor: Colors.transparent, leadingWidth: 150, toolbarHeight: Constants.appBarHeight, - leading: SpacesCubit.spaces != null - ? SpacesCubit.spaces!.isNotEmpty - ? SpacesCubit.appBarLeading[SpacesCubit() - .bottomNavItems[SpacesCubit.pageIndex] - .label] + leading: HomeCubit.spaces != null + ? HomeCubit.spaces!.isNotEmpty + ? HomeCubit.appBarLeading[ + HomeCubit.bottomNavItems[HomeCubit.pageIndex].label] : null : null, - actions: SpacesCubit.appBarActions[ - SpacesCubit().bottomNavItems[SpacesCubit.pageIndex].label], + actions: HomeCubit.appBarActions[ + HomeCubit.bottomNavItems[HomeCubit.pageIndex].label], ), ); }, diff --git a/lib/features/app_layout/view/widgets/default_nav_bar.dart b/lib/features/app_layout/view/widgets/default_nav_bar.dart index d44a39f..21a01f4 100644 --- a/lib/features/app_layout/view/widgets/default_nav_bar.dart +++ b/lib/features/app_layout/view/widgets/default_nav_bar.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; @@ -13,9 +13,9 @@ class DefaultNavBar extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { - var cubit = SpacesCubit.get(context); + var cubit = HomeCubit.get(context); return SizedBox( height: Constants.bottomNavBarHeight, child: BottomNavigationBar( @@ -25,11 +25,11 @@ class DefaultNavBar extends StatelessWidget { if (DevicesCubit.get(context).chosenCategoryView != null) { DevicesCubit().clearCategoriesSelection(context); } - if (SpacesCubit.get(context).selectedRoom != null) { - SpacesCubit.get(context).unselectRoom(); + if (HomeCubit.get(context).selectedRoom != null) { + HomeCubit.get(context).unselectRoom(); } }, - currentIndex: SpacesCubit.pageIndex, + currentIndex: HomeCubit.pageIndex, selectedItemColor: ColorsManager.primaryColor, selectedLabelStyle: const TextStyle( color: ColorsManager.primaryColor, @@ -39,7 +39,7 @@ class DefaultNavBar extends StatelessWidget { unselectedItemColor: Colors.grey, type: BottomNavigationBarType.fixed, elevation: 0, - items: cubit.bottomNavItems, + items: HomeCubit.bottomNavItems, ), ); }, diff --git a/lib/features/auth/bloc/auth_cubit.dart b/lib/features/auth/bloc/auth_cubit.dart index a5cdf2b..d966e90 100644 --- a/lib/features/auth/bloc/auth_cubit.dart +++ b/lib/features/auth/bloc/auth_cubit.dart @@ -3,7 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/auth/model/login_with_email_model.dart'; import 'package:syncrow_app/features/auth/model/token.dart'; @@ -42,8 +42,6 @@ class AuthCubit extends Cubit { static Token token = Token.emptyConstructor(); - // (FlutterSecureStorage().read(key :'token')); - login() async { emit(AuthLoading()); try { @@ -76,7 +74,7 @@ class AuthCubit extends Cubit { try { FlutterSecureStorage storage = const FlutterSecureStorage(); await storage.delete(key: Token.loginAccessTokenKey); - SpacesCubit.clear(); + HomeCubit.clear(); emit(AuthLoggedOut()); } on DioException catch (e) { emit(AuthError(ServerFailure.fromDioError(e).errMessage)); diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 4376db0..ddb130b 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -3,7 +3,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/app_layout/model/space_model.dart'; import 'package:syncrow_app/features/devices/model/device_category_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; @@ -22,8 +22,8 @@ part 'devices_state.dart'; class DevicesCubit extends Cubit { DevicesCubit() : super(DevicesInitial()) { - if (SpacesCubit.selectedSpace != null) { - fetchGroups(SpacesCubit.selectedSpace!.id!); + if (HomeCubit.selectedSpace != null) { + fetchGroups(HomeCubit.selectedSpace!.id!); } } bool _isClosed = false; diff --git a/lib/features/devices/view/widgets/ACs/acs_list.dart b/lib/features/devices/view/widgets/ACs/acs_list.dart index 362118c..f8175f6 100644 --- a/lib/features/devices/view/widgets/ACs/acs_list.dart +++ b/lib/features/devices/view/widgets/ACs/acs_list.dart @@ -43,7 +43,7 @@ class ACsList extends StatelessWidget { itemBuilder: (context, index) { DeviceModel ac = DevicesCubit.get(context) .chosenCategory! - .devices![index] as DeviceModel; + .devices![index]; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/features/devices/view/widgets/devices_view_body.dart b/lib/features/devices/view/widgets/devices_view_body.dart index 0f4f339..4345611 100644 --- a/lib/features/devices/view/widgets/devices_view_body.dart +++ b/lib/features/devices/view/widgets/devices_view_body.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:smooth_page_indicator/smooth_page_indicator.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/devices/view/widgets/devices_view_header.dart'; import 'package:syncrow_app/features/devices/view/widgets/room_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart'; @@ -18,7 +18,7 @@ class DevicesViewBody extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { return BlocBuilder( builder: (context, state) { @@ -42,15 +42,15 @@ class DevicesViewBody extends StatelessWidget { Expanded( child: PageView( controller: - SpacesCubit.get(context).devicesPageController, + HomeCubit.get(context).devicesPageController, onPageChanged: (index) { - SpacesCubit.get(context).devicesPageChanged(index); + HomeCubit.get(context).devicesPageChanged(index); }, children: [ const WizardPage(), - if (SpacesCubit.selectedSpace != null) - if (SpacesCubit.selectedSpace!.rooms != null) - ...SpacesCubit.selectedSpace!.rooms!.map( + if (HomeCubit.selectedSpace != null) + if (HomeCubit.selectedSpace!.rooms != null) + ...HomeCubit.selectedSpace!.rooms!.map( (room) { return RoomPage( room: room, @@ -60,16 +60,15 @@ class DevicesViewBody extends StatelessWidget { ], ), ), - SpacesCubit.selectedSpace != null + HomeCubit.selectedSpace != null ? Padding( padding: const EdgeInsets.symmetric( vertical: 7, ), child: SmoothPageIndicator( - controller: SpacesCubit.get(context) - .devicesPageController, - count: - SpacesCubit.selectedSpace!.rooms!.length + 1, + controller: + HomeCubit.get(context).devicesPageController, + count: HomeCubit.selectedSpace!.rooms!.length + 1, effect: const WormEffect( paintStyle: PaintingStyle.stroke, dotHeight: 8, diff --git a/lib/features/devices/view/widgets/lights/light_interface_recent_color.dart b/lib/features/devices/view/widgets/lights/light_interface_recent_color.dart index ccc58e7..614d09a 100644 --- a/lib/features/devices/view/widgets/lights/light_interface_recent_color.dart +++ b/lib/features/devices/view/widgets/lights/light_interface_recent_color.dart @@ -41,8 +41,8 @@ class LightInterfaceRecentColor extends StatelessWidget { margin: const EdgeInsets.only(right: 10), width: 40, height: 40, - decoration: ShapeDecoration( - shape: const CircleBorder(), + decoration: const ShapeDecoration( + shape: CircleBorder(), // color: Color(light.recentColors[index]), ), ), diff --git a/lib/features/devices/view/widgets/lights_switches/light_switches.dart b/lib/features/devices/view/widgets/lights_switches/light_switches.dart index 6e087b7..86e5f52 100644 --- a/lib/features/devices/view/widgets/lights_switches/light_switches.dart +++ b/lib/features/devices/view/widgets/lights_switches/light_switches.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/function_model.dart'; @@ -27,7 +27,7 @@ class LightSwitchesView extends StatelessWidget { extendBodyBehindAppBar: true, extendBody: true, appBar: const CategoryViewAppBar(), - body: BlocBuilder( + body: BlocBuilder( builder: (context, state) { return Container( width: MediaQuery.sizeOf(context).width, diff --git a/lib/features/devices/view/widgets/rooms_slider.dart b/lib/features/devices/view/widgets/rooms_slider.dart index 0ed7b45..7c7add3 100644 --- a/lib/features/devices/view/widgets/rooms_slider.dart +++ b/lib/features/devices/view/widgets/rooms_slider.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart'; import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; @@ -13,48 +13,48 @@ class RoomsSlider extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { return SizedBox( height: 40, child: PageView( - controller: SpacesCubit.get(context).roomsPageController, + controller: HomeCubit.get(context).roomsPageController, onPageChanged: (index) { - SpacesCubit.get(context).roomSliderPageChanged(index); + HomeCubit.get(context).roomSliderPageChanged(index); }, children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 15), child: InkWell( onTap: () { - SpacesCubit.get(context).unselectRoom(); + HomeCubit.get(context).unselectRoom(); }, child: TitleMedium( text: StringsManager.wizard, style: context.titleMedium.copyWith( fontSize: 25, - color: SpacesCubit.get(context).selectedRoom == null + color: HomeCubit.get(context).selectedRoom == null ? ColorsManager.textPrimaryColor : ColorsManager.textPrimaryColor.withOpacity(.2), ), ), ), ), - if (SpacesCubit.selectedSpace != null) - if (SpacesCubit.selectedSpace!.rooms != null) - ...SpacesCubit.selectedSpace!.rooms!.map( + if (HomeCubit.selectedSpace != null) + if (HomeCubit.selectedSpace!.rooms != null) + ...HomeCubit.selectedSpace!.rooms!.map( (room) => Padding( padding: const EdgeInsets.symmetric(horizontal: 15), child: InkWell( onTap: () { - SpacesCubit.get(context).roomSliderPageChanged( - SpacesCubit.selectedSpace!.rooms!.indexOf(room)); + HomeCubit.get(context).roomSliderPageChanged( + HomeCubit.selectedSpace!.rooms!.indexOf(room)); }, child: TitleMedium( text: room.name!, style: context.titleMedium.copyWith( fontSize: 25, - color: SpacesCubit.get(context).selectedRoom == room + color: HomeCubit.get(context).selectedRoom == room ? ColorsManager.textPrimaryColor : ColorsManager.textPrimaryColor .withOpacity(.2), diff --git a/lib/features/splash/view/splash_view.dart b/lib/features/splash/view/splash_view.dart index ed1fe2c..06180a9 100644 --- a/lib/features/splash/view/splash_view.dart +++ b/lib/features/splash/view/splash_view.dart @@ -15,9 +15,8 @@ class SplashView extends StatelessWidget { return BlocConsumer( listener: (context, state) { if (state is AuthTokenSuccess) { - Future.delayed(const Duration(seconds: 1), () { - Navigator.pushReplacementNamed(context, Routes.homeRoute); - }); + Navigator.pushNamedAndRemoveUntil( + context, Routes.homeRoute, (route) => false); } else if (state is AuthTokenError) { Future.delayed(const Duration(seconds: 1), () { Navigator.pushReplacement(