diff --git a/lib/features/app_layout/bloc/nav_cubit.dart b/lib/features/app_layout/bloc/nav_cubit.dart index cec0c46..bb00d0d 100644 --- a/lib/features/app_layout/bloc/nav_cubit.dart +++ b/lib/features/app_layout/bloc/nav_cubit.dart @@ -147,11 +147,13 @@ class NavCubit extends Cubit { const MenuView(), ]; - Widget get currentPage => NavCubit().pages[pageIndex]; + final PageController pageController = PageController(); - void updatePageIndex(int index, BuildContext context) { - emit(NavChangePage()); + void updatePageIndex(int index) { pageIndex = index; + pageController.animateToPage(index, + duration: const Duration(milliseconds: 150), curve: Curves.easeIn); + emit(NavChangePage()); } } diff --git a/lib/features/app_layout/view/widgets/app_body.dart b/lib/features/app_layout/view/widgets/app_body.dart index 3456f4d..a3335a4 100644 --- a/lib/features/app_layout/view/widgets/app_body.dart +++ b/lib/features/app_layout/view/widgets/app_body.dart @@ -14,19 +14,26 @@ class AppBody extends StatelessWidget { return BlocBuilder( builder: (context, state) { return Container( - width: MediaQuery.sizeOf(context).width, - height: MediaQuery.sizeOf(context).height, - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage( - Assets.imagesBackground, + width: MediaQuery.sizeOf(context).width, + height: MediaQuery.sizeOf(context).height, + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage( + Assets.imagesBackground, + ), + fit: BoxFit.cover, + opacity: 0.4, ), - fit: BoxFit.cover, - opacity: 0.4, ), - ), - child: NavCubit.of(context).currentPage, - ); + child: PageView( + onPageChanged: (int index) { + NavCubit.of(context).updatePageIndex(index); + }, + controller: NavCubit.of(context).pageController, + children: NavCubit.of(context).pages, + ) + // NavCubit.of(context).currentPage, + ); }, ); } 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 38b7c28..e280bc1 100644 --- a/lib/features/app_layout/view/widgets/default_app_bar.dart +++ b/lib/features/app_layout/view/widgets/default_app_bar.dart @@ -19,6 +19,7 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget { child: AppBar( backgroundColor: Colors.transparent, leadingWidth: 150, + toolbarHeight: Constants.appBarHeight, leading: NavCubit.appBarLeading[ NavCubit().bottomNavItems[NavCubit.pageIndex].label], actions: NavCubit.appBarActions[ 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 031bb3e..2db04ff 100644 --- a/lib/features/app_layout/view/widgets/default_nav_bar.dart +++ b/lib/features/app_layout/view/widgets/default_nav_bar.dart @@ -20,7 +20,7 @@ class DefaultNavBar extends StatelessWidget { child: BottomNavigationBar( backgroundColor: Colors.transparent, onTap: (int index) { - cubit.updatePageIndex(index, context); + cubit.updatePageIndex(index); if (DevicesCubit.get(context).chosenCategoryView != null) { DevicesCubit().clearCategoriesSelection(context); } diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 58eb672..8b706a6 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -263,6 +263,15 @@ class DevicesCubit extends Cubit { return null; } + DevicesCategoryModel? get chosenCategory { + for (var category in allCategories) { + if (category.isSelected) { + return category; + } + } + return null; + } + selectDevice(DeviceModel device) { for (var category in allCategories) { for (var device in category.devices) { diff --git a/lib/features/devices/view/widgets/ACs/acs_view.dart b/lib/features/devices/view/widgets/ACs/acs_view.dart index 517fb7a..2a73a10 100644 --- a/lib/features/devices/view/widgets/ACs/acs_view.dart +++ b/lib/features/devices/view/widgets/ACs/acs_view.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart'; import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_list.dart'; +import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; import '../../../../../generated/assets.dart'; @@ -38,7 +38,7 @@ class ACsView extends StatelessWidget { backgroundColor: ColorsManager.backgroundColor, extendBodyBehindAppBar: true, extendBody: true, - appBar: DefaultAppBar(context), + appBar: const CategoryViewAppBar(), body: Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, diff --git a/lib/features/devices/view/widgets/ACs/category_view_app_bar.dart b/lib/features/devices/view/widgets/ACs/category_view_app_bar.dart new file mode 100644 index 0000000..c1f845f --- /dev/null +++ b/lib/features/devices/view/widgets/ACs/category_view_app_bar.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; +import 'package:syncrow_app/features/shared_widgets/text_widgets/display_medium.dart'; +import 'package:syncrow_app/utils/context_extension.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; + +import '../../../../../utils/resource_manager/color_manager.dart'; + +class CategoryViewAppBar extends StatelessWidget + implements PreferredSizeWidget { + const CategoryViewAppBar({ + super.key, + }); + + @override + Widget build(BuildContext context) { + return AppBar( + backgroundColor: Colors.transparent, + elevation: 0, + toolbarHeight: Constants.appBarHeight, + centerTitle: true, + title: DisplayMedium( + text: DevicesCubit.get(context).chosenCategory!.name, + style: context.displayMedium.copyWith( + color: ColorsManager.primaryColor, + fontWeight: FontWeight.bold, + ), + ), + leading: IconButton( + icon: const Icon( + Icons.arrow_back_ios, + color: ColorsManager.textPrimaryColor, + ), + onPressed: () { + DevicesCubit.get(context).clearCategoriesSelection(context); + }, + ), + ); + } + + @override + Size get preferredSize => Size.fromHeight(Constants.appBarHeight); +} diff --git a/lib/features/devices/view/widgets/curtains/curtain_view.dart b/lib/features/devices/view/widgets/curtains/curtain_view.dart index ac28052..27cdb76 100644 --- a/lib/features/devices/view/widgets/curtains/curtain_view.dart +++ b/lib/features/devices/view/widgets/curtains/curtain_view.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart'; import 'package:syncrow_app/features/devices/bloc/curtains/curtains_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; +import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart'; import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_list.dart'; import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; @@ -30,7 +30,7 @@ class CurtainView extends StatelessWidget { backgroundColor: ColorsManager.backgroundColor, extendBodyBehindAppBar: true, extendBody: true, - appBar: DefaultAppBar(context), + appBar: const CategoryViewAppBar(), body: Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, diff --git a/lib/features/devices/view/widgets/lights/lights_view.dart b/lib/features/devices/view/widgets/lights/lights_view.dart index 32671a1..efdadef 100644 --- a/lib/features/devices/view/widgets/lights/lights_view.dart +++ b/lib/features/devices/view/widgets/lights/lights_view.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart'; import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view_list.dart'; import '../../../../../generated/assets.dart'; import '../../../../../utils/resource_manager/color_manager.dart'; -import '../../../../app_layout/view/widgets/default_app_bar.dart'; import '../../../bloc/devices_cubit.dart'; import '../../../bloc/lights/lights_cubit.dart'; import '../../../model/light_model.dart'; @@ -43,7 +43,7 @@ class LightsView extends StatelessWidget { backgroundColor: ColorsManager.backgroundColor, extendBodyBehindAppBar: true, extendBody: true, - appBar: DefaultAppBar(context), + appBar: const CategoryViewAppBar(), body: Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, diff --git a/lib/utils/resource_manager/constants.dart b/lib/utils/resource_manager/constants.dart index 4332027..b185b28 100644 --- a/lib/utils/resource_manager/constants.dart +++ b/lib/utils/resource_manager/constants.dart @@ -4,7 +4,7 @@ abstract class Constants { static const String countryCode = "US"; - static const double appBarHeightPercentage = 0.1175; + static const double appBarHeightPercentage = 0.12; static const double bottomNavBarHeightPercentage = 0.1175; static late double appBarHeight; static late double bottomNavBarHeight;