mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-17 02:25:16 +00:00
Refactor device-related views and add error handling
Refactor device-related views to improve code structure and readability. Add error handling for authentication token in the splash view. Remove unnecessary NavCubit from the app initialization.
This commit is contained in:
@ -1,167 +0,0 @@
|
||||
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/view/widgets/app_bar_home_dropdown.dart';
|
||||
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
||||
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
||||
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
import '../../../generated/assets.dart';
|
||||
|
||||
part 'nav_state.dart';
|
||||
|
||||
class NavCubit extends Cubit<NavState> {
|
||||
NavCubit() : super(NavInitial());
|
||||
|
||||
static NavCubit of(context) => BlocProvider.of<NavCubit>(context);
|
||||
|
||||
static clear() {
|
||||
pageIndex = 0;
|
||||
}
|
||||
|
||||
static int pageIndex = 0;
|
||||
|
||||
static Map<String, List<Widget>> appBarActions = {
|
||||
'Dashboard': [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
'Devices': [
|
||||
// IconButton(
|
||||
// icon: Image.asset(
|
||||
// Assets.iconsFilter,
|
||||
// height: 20,
|
||||
// width: 20,
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// ),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
'Routine': [
|
||||
// IconButton(
|
||||
// icon: Image.asset(
|
||||
// Assets.iconsFilter,
|
||||
// height: 20,
|
||||
// width: 20,
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// ),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
'Menu': [
|
||||
IconButton(
|
||||
icon: SvgPicture.asset(
|
||||
Assets.iconsScan,
|
||||
height: 20,
|
||||
width: 20,
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
};
|
||||
|
||||
static Map<String, Widget?> appBarLeading = {
|
||||
'Dashboard': const AppBarHomeDropdown(),
|
||||
'Devices': const AppBarHomeDropdown(),
|
||||
'Routine': const AppBarHomeDropdown(),
|
||||
'Menu': Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Image.asset(
|
||||
Assets.imagesLogoHorizontal,
|
||||
height: 15,
|
||||
width: 100,
|
||||
fit: BoxFit.scaleDown,
|
||||
),
|
||||
),
|
||||
};
|
||||
|
||||
var bottomNavItems = [
|
||||
defaultBottomNavBarItem(icon: Assets.iconsDashboard, label: 'Dashboard'),
|
||||
// defaultBottomNavBarItem(icon: Assets.iconslayout, label: 'Layout'),
|
||||
defaultBottomNavBarItem(icon: Assets.iconsDevices, label: 'Devices'),
|
||||
defaultBottomNavBarItem(icon: Assets.iconsRoutines, label: 'Routine'),
|
||||
defaultBottomNavBarItem(icon: Assets.iconsMenu, label: 'Menu'),
|
||||
];
|
||||
|
||||
final List<Widget> pages = [
|
||||
const DashboardView(),
|
||||
// const LayoutPage(),
|
||||
const DevicesViewBody(),
|
||||
const SceneView(),
|
||||
const MenuView(),
|
||||
];
|
||||
|
||||
void updatePageIndex(int index) {
|
||||
pageIndex = index;
|
||||
|
||||
emit(NavChangePage());
|
||||
}
|
||||
}
|
||||
|
||||
BottomNavigationBarItem defaultBottomNavBarItem(
|
||||
{required String icon, required String label}) {
|
||||
return BottomNavigationBarItem(
|
||||
icon: SvgPicture.asset(icon),
|
||||
activeIcon: SvgPicture.asset(
|
||||
icon.replaceAll('.svg', '-fill.svg'),
|
||||
colorFilter: const ColorFilter.mode(
|
||||
ColorsManager.primaryColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
label: label,
|
||||
);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
part of 'nav_cubit.dart';
|
||||
|
||||
abstract class NavState {}
|
||||
|
||||
class NavInitial extends NavState {}
|
||||
|
||||
class NavChangePage extends NavState {}
|
@ -1,27 +1,42 @@
|
||||
import 'package:dio/dio.dart';
|
||||
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/model/space_model.dart';
|
||||
import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdown.dart';
|
||||
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
||||
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
||||
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
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';
|
||||
|
||||
class SpacesCubit extends Cubit<SpacesState> {
|
||||
SpacesCubit() : super(SpacesInitial()) {
|
||||
if (SpacesCubit.spaces != null) {
|
||||
if (selectedSpace == null) {
|
||||
fetchSpaces().then((value) {
|
||||
if (selectedSpace != null) {
|
||||
print('selectedSpace: ${selectedSpace!.name}');
|
||||
fetchRooms(selectedSpace!);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
fetchSpaces(); // this is for the first time
|
||||
}
|
||||
}
|
||||
|
||||
static SpacesCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
static List<SpaceModel> spaces = [];
|
||||
static List<SpaceModel>? spaces;
|
||||
|
||||
static SpaceModel? selectedSpace = spaces.isNotEmpty ? spaces.first : null;
|
||||
static SpaceModel? selectedSpace;
|
||||
|
||||
RoomModel? selectedRoom;
|
||||
|
||||
@ -33,7 +48,7 @@ class SpacesCubit extends Cubit<SpacesState> {
|
||||
|
||||
selectSpace(SpaceModel space) {
|
||||
selectedSpace = space;
|
||||
emit(SpacesSelected(space));
|
||||
emit(SpaceSelected(space));
|
||||
}
|
||||
|
||||
roomSliderPageChanged(int index) {
|
||||
@ -84,27 +99,177 @@ class SpacesCubit extends Cubit<SpacesState> {
|
||||
}
|
||||
|
||||
fetchSpaces() async {
|
||||
emit(SpacesLoading());
|
||||
emit(GetSpacesLoading());
|
||||
try {
|
||||
spaces = await SpacesAPI.getSpaces();
|
||||
spaces.isNotEmpty ? selectSpace(spaces.first) : null;
|
||||
emit(SpacesLoaded(spaces));
|
||||
selectedSpace = spaces!.isNotEmpty ? selectSpace(spaces!.first) : null;
|
||||
emit(GetSpacesLoaded(spaces!));
|
||||
} on DioException catch (e) {
|
||||
emit(SpacesError(ServerFailure.fromDioError(e).errMessage));
|
||||
emit(GetSpacesError(ServerFailure.fromDioError(e).errMessage));
|
||||
}
|
||||
}
|
||||
|
||||
fetchRooms(SpaceModel space) async {
|
||||
emit(SpaceRoomsLoading());
|
||||
emit(GetSpaceRoomsLoading());
|
||||
try {
|
||||
space.rooms = await SpacesAPI.getRooms(space.id!);
|
||||
if (space.rooms != null) {
|
||||
emit(SpaceRoomsLoaded(space.rooms!));
|
||||
emit(GetSpaceRoomsLoaded(space.rooms!));
|
||||
} else {
|
||||
emit(SpaceRoomsError("No rooms found"));
|
||||
emit(GetSpaceRoomsError("No rooms found"));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
emit(SpacesError(ServerFailure.fromDioError(e).errMessage));
|
||||
emit(GetSpacesError(ServerFailure.fromDioError(e).errMessage));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////Nav////////////////////////////////////////
|
||||
|
||||
static clear() {
|
||||
pageIndex = 0;
|
||||
}
|
||||
|
||||
static int pageIndex = 0;
|
||||
|
||||
static Map<String, List<Widget>> appBarActions = {
|
||||
'Dashboard': [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
'Devices': [
|
||||
// IconButton(
|
||||
// icon: Image.asset(
|
||||
// Assets.iconsFilter,
|
||||
// height: 20,
|
||||
// width: 20,
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// ),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
'Routine': [
|
||||
// IconButton(
|
||||
// icon: Image.asset(
|
||||
// Assets.iconsFilter,
|
||||
// height: 20,
|
||||
// width: 20,
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// ),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
size: 25,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
MaterialStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
'Menu': [
|
||||
IconButton(
|
||||
icon: SvgPicture.asset(
|
||||
Assets.iconsScan,
|
||||
height: 20,
|
||||
width: 20,
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
};
|
||||
|
||||
static Map<String, Widget?> appBarLeading = {
|
||||
'Dashboard': const AppBarHomeDropdown(),
|
||||
'Devices': const AppBarHomeDropdown(),
|
||||
'Routine': const AppBarHomeDropdown(),
|
||||
'Menu': Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Image.asset(
|
||||
Assets.imagesLogoHorizontal,
|
||||
height: 15,
|
||||
width: 100,
|
||||
fit: BoxFit.scaleDown,
|
||||
),
|
||||
),
|
||||
};
|
||||
|
||||
var bottomNavItems = [
|
||||
defaultBottomNavBarItem(icon: Assets.iconsDashboard, label: 'Dashboard'),
|
||||
// defaultBottomNavBarItem(icon: Assets.iconslayout, label: 'Layout'),
|
||||
defaultBottomNavBarItem(icon: Assets.iconsDevices, label: 'Devices'),
|
||||
defaultBottomNavBarItem(icon: Assets.iconsRoutines, label: 'Routine'),
|
||||
defaultBottomNavBarItem(icon: Assets.iconsMenu, label: 'Menu'),
|
||||
];
|
||||
|
||||
final List<Widget> pages = [
|
||||
const DashboardView(),
|
||||
// const LayoutPage(),
|
||||
const DevicesViewBody(),
|
||||
const SceneView(),
|
||||
const MenuView(),
|
||||
];
|
||||
|
||||
void updatePageIndex(int index) {
|
||||
pageIndex = index;
|
||||
|
||||
emit(NavChangePage());
|
||||
}
|
||||
}
|
||||
|
||||
BottomNavigationBarItem defaultBottomNavBarItem(
|
||||
{required String icon, required String label}) {
|
||||
return BottomNavigationBarItem(
|
||||
icon: SvgPicture.asset(icon),
|
||||
activeIcon: SvgPicture.asset(
|
||||
icon.replaceAll('.svg', '-fill.svg'),
|
||||
colorFilter: const ColorFilter.mode(
|
||||
ColorsManager.primaryColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
label: label,
|
||||
);
|
||||
}
|
||||
|
@ -4,36 +4,37 @@ abstract class SpacesState {}
|
||||
|
||||
class SpacesInitial extends SpacesState {}
|
||||
|
||||
class SpacesLoading extends SpacesState {}
|
||||
class GetSpacesLoading extends SpacesState {}
|
||||
|
||||
class SpacesLoaded extends SpacesState {
|
||||
class GetSpacesLoaded extends SpacesState {
|
||||
final List<SpaceModel> spaces;
|
||||
|
||||
SpacesLoaded(this.spaces);
|
||||
GetSpacesLoaded(this.spaces);
|
||||
}
|
||||
|
||||
class SpacesError extends SpacesState {
|
||||
class GetSpacesError extends SpacesState {
|
||||
final String errMessage;
|
||||
|
||||
SpacesError(this.errMessage);
|
||||
GetSpacesError(this.errMessage);
|
||||
}
|
||||
|
||||
class SpaceRoomsLoading extends SpacesLoading {}
|
||||
class GetSpaceRoomsLoading extends SpacesState {}
|
||||
|
||||
class SpaceRoomsLoaded extends SpacesLoading {
|
||||
class GetSpaceRoomsLoaded extends SpacesState {
|
||||
final List<RoomModel> rooms;
|
||||
|
||||
SpaceRoomsLoaded(this.rooms);
|
||||
GetSpaceRoomsLoaded(this.rooms);
|
||||
}
|
||||
|
||||
class SpaceRoomsError extends SpacesError {
|
||||
SpaceRoomsError(super.errMessage);
|
||||
class GetSpaceRoomsError extends SpacesState {
|
||||
final String errMessage;
|
||||
GetSpaceRoomsError(this.errMessage);
|
||||
}
|
||||
|
||||
class SpacesSelected extends SpacesState {
|
||||
class SpaceSelected extends SpacesState {
|
||||
final SpaceModel space;
|
||||
|
||||
SpacesSelected(this.space);
|
||||
SpaceSelected(this.space);
|
||||
}
|
||||
|
||||
class RoomSelected extends SpacesState {
|
||||
@ -43,3 +44,5 @@ class RoomSelected extends SpacesState {
|
||||
}
|
||||
|
||||
class RoomUnSelected extends SpacesState {}
|
||||
|
||||
class NavChangePage extends SpacesState {}
|
||||
|
@ -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/nav_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_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';
|
||||
@ -26,7 +26,7 @@ class AppLayout extends StatelessWidget {
|
||||
],
|
||||
child: BlocListener<SpacesCubit, SpacesState>(
|
||||
listener: (context, state) {
|
||||
if (state is SpacesError) {
|
||||
if (state is GetSpacesError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errMessage),
|
||||
@ -36,7 +36,7 @@ class AppLayout extends StatelessWidget {
|
||||
.popUntil((route) => route.settings.name == Routes.authLogin);
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<NavCubit, NavState>(
|
||||
child: BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
@ -50,13 +50,13 @@ class AppLayout extends StatelessWidget {
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar:
|
||||
state is! SpacesLoading || state is! SpaceRoomsLoading
|
||||
appBar: state is! GetSpacesLoading ||
|
||||
state is! GetSpaceRoomsLoading
|
||||
? const DefaultAppBar()
|
||||
: null,
|
||||
body: const AppBody(),
|
||||
bottomNavigationBar:
|
||||
state is! SpacesLoading || state is! SpaceRoomsLoading
|
||||
bottomNavigationBar: state is! GetSpacesLoading ||
|
||||
state is! GetSpaceRoomsLoading
|
||||
? const DefaultNavBar()
|
||||
: null,
|
||||
);
|
||||
|
@ -17,7 +17,9 @@ class AppBarHomeDropdown extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
return SpacesCubit.selectedSpace == null
|
||||
? const Center(child: BodyMedium(text: 'No Home Selected'))
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(left: 10, right: 10),
|
||||
child: DropdownButton(
|
||||
icon: const Icon(
|
||||
@ -29,7 +31,7 @@ class AppBarHomeDropdown extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(0),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
value: SpacesCubit.selectedSpace!.id,
|
||||
items: SpacesCubit.spaces.map((space) {
|
||||
items: SpacesCubit.spaces!.map((space) {
|
||||
return DropdownMenuItem(
|
||||
value: space.id,
|
||||
child: SizedBox(
|
||||
@ -65,7 +67,7 @@ class AppBarHomeDropdown extends StatelessWidget {
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
SpacesCubit.get(context).selectSpace(SpacesCubit.spaces
|
||||
SpacesCubit.get(context).selectSpace(SpacesCubit.spaces!
|
||||
.firstWhere((element) => element.id == value));
|
||||
}
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/nav_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
|
||||
import '../../../../generated/assets.dart';
|
||||
@ -12,7 +12,7 @@ class AppBody extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NavCubit, NavState>(
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
@ -28,7 +28,7 @@ class AppBody extends StatelessWidget {
|
||||
),
|
||||
child: BlocConsumer<SpacesCubit, SpacesState>(
|
||||
listener: (context, state) {
|
||||
if (state is SpacesError) {
|
||||
if (state is GetSpacesError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errMessage),
|
||||
@ -37,8 +37,9 @@ class AppBody extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return state is! SpacesLoading || state is! SpaceRoomsLoading
|
||||
? NavCubit.of(context).pages[NavCubit.pageIndex]
|
||||
return state is! GetSpacesLoading ||
|
||||
state is! GetSpaceRoomsLoading
|
||||
? SpacesCubit.get(context).pages[SpacesCubit.pageIndex]
|
||||
: const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/nav_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
@ -9,8 +9,6 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NavCubit, NavState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
@ -21,18 +19,19 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
backgroundColor: Colors.transparent,
|
||||
leadingWidth: 150,
|
||||
toolbarHeight: Constants.appBarHeight,
|
||||
leading: SpacesCubit.spaces.isNotEmpty
|
||||
? NavCubit.appBarLeading[
|
||||
NavCubit().bottomNavItems[NavCubit.pageIndex].label]
|
||||
leading: SpacesCubit.spaces != null
|
||||
? SpacesCubit.spaces!.isNotEmpty
|
||||
? SpacesCubit.appBarLeading[SpacesCubit()
|
||||
.bottomNavItems[SpacesCubit.pageIndex]
|
||||
.label]
|
||||
: null
|
||||
: null,
|
||||
actions: NavCubit.appBarActions[
|
||||
NavCubit().bottomNavItems[NavCubit.pageIndex].label],
|
||||
actions: SpacesCubit.appBarActions[
|
||||
SpacesCubit().bottomNavItems[SpacesCubit.pageIndex].label],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/nav_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@ -13,9 +13,9 @@ class DefaultNavBar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NavCubit, NavState>(
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
var cubit = NavCubit.of(context);
|
||||
var cubit = SpacesCubit.get(context);
|
||||
return SizedBox(
|
||||
height: Constants.bottomNavBarHeight,
|
||||
child: BottomNavigationBar(
|
||||
@ -29,7 +29,7 @@ class DefaultNavBar extends StatelessWidget {
|
||||
SpacesCubit.get(context).unselectRoom();
|
||||
}
|
||||
},
|
||||
currentIndex: NavCubit.pageIndex,
|
||||
currentIndex: SpacesCubit.pageIndex,
|
||||
selectedItemColor: ColorsManager.primaryColor,
|
||||
selectedLabelStyle: const TextStyle(
|
||||
color: ColorsManager.primaryColor,
|
||||
|
@ -3,7 +3,8 @@ 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/nav_cubit.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
|
||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||
@ -75,7 +76,7 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
try {
|
||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||
await storage.delete(key: Token.loginAccessTokenKey);
|
||||
NavCubit.clear();
|
||||
SpacesCubit.clear();
|
||||
emit(AuthLoggedOut());
|
||||
} on DioException catch (e) {
|
||||
emit(AuthError(ServerFailure.fromDioError(e).errMessage));
|
||||
|
@ -22,8 +22,10 @@ part 'devices_state.dart';
|
||||
|
||||
class DevicesCubit extends Cubit<DevicesState> {
|
||||
DevicesCubit() : super(DevicesInitial()) {
|
||||
if (SpacesCubit.selectedSpace != null) {
|
||||
fetchGroups(SpacesCubit.selectedSpace!.id!);
|
||||
}
|
||||
}
|
||||
bool _isClosed = false;
|
||||
|
||||
@override
|
||||
|
@ -8,16 +8,13 @@ class DevicesView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) => Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
child: const DevicesViewBody(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,7 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
child: Column(
|
||||
@ -145,7 +143,6 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,14 @@ class ACsView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
DeviceModel? selectedAC;
|
||||
if (DevicesCubit.get(context).getSelectedDevice()
|
||||
is DeviceModel) {
|
||||
selectedAC = DevicesCubit.get(context).getSelectedDevice()
|
||||
as DeviceModel;
|
||||
if (DevicesCubit.get(context).getSelectedDevice() is DeviceModel) {
|
||||
selectedAC =
|
||||
DevicesCubit.get(context).getSelectedDevice() as DeviceModel;
|
||||
}
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
@ -70,7 +67,6 @@ class ACsView extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,7 @@ class CurtainView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
@ -53,7 +51,6 @@ class CurtainView extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import 'package:syncrow_app/features/devices/view/widgets/devices_view_header.da
|
||||
import 'package:syncrow_app/features/devices/view/widgets/room_page.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/wizard_page.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
import '../../bloc/devices_cubit.dart';
|
||||
@ -17,9 +18,7 @@ class DevicesViewBody extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<SpacesCubit, SpacesState>(
|
||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
@ -61,20 +60,25 @@ class DevicesViewBody extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
SpacesCubit.selectedSpace != null
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 7,
|
||||
),
|
||||
child: SmoothPageIndicator(
|
||||
controller:
|
||||
SpacesCubit.get(context).devicesPageController,
|
||||
count: SpacesCubit.selectedSpace!.rooms!.length + 1,
|
||||
controller: SpacesCubit.get(context)
|
||||
.devicesPageController,
|
||||
count:
|
||||
SpacesCubit.selectedSpace!.rooms!.length + 1,
|
||||
effect: const WormEffect(
|
||||
paintStyle: PaintingStyle.stroke,
|
||||
dotHeight: 8,
|
||||
dotWidth: 8,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Center(
|
||||
child: BodyLarge(text: 'No Home Found'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -83,7 +87,6 @@ class DevicesViewBody extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,17 +14,14 @@ class LightsView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
DeviceModel? selectedLight;
|
||||
if (DevicesCubit.get(context).getSelectedDevice()
|
||||
is DeviceModel) {
|
||||
selectedLight = DevicesCubit.get(context).getSelectedDevice()
|
||||
as DeviceModel;
|
||||
if (DevicesCubit.get(context).getSelectedDevice() is DeviceModel) {
|
||||
selectedLight =
|
||||
DevicesCubit.get(context).getSelectedDevice() as DeviceModel;
|
||||
}
|
||||
List<DeviceModel> lights = [];
|
||||
if (DevicesCubit.allCategories![1].devices != null) {
|
||||
@ -65,7 +62,6 @@ class LightsView extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
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/nav_cubit.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
|
||||
@ -26,7 +27,7 @@ class LightSwitchesView extends StatelessWidget {
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: const CategoryViewAppBar(),
|
||||
body: BlocBuilder<NavCubit, NavState>(
|
||||
body: BlocBuilder<SpacesCubit, SpacesState>(
|
||||
builder: (context, state) {
|
||||
return Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
|
@ -12,13 +12,13 @@ class SplashView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthCubit, AuthState>(
|
||||
builder: (context, state) {
|
||||
return BlocConsumer<AuthCubit, AuthState>(
|
||||
listener: (context, state) {
|
||||
if (state is AuthTokenSuccess) {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Navigator.pushReplacementNamed(context, Routes.homeRoute);
|
||||
});
|
||||
} else {
|
||||
} else if (state is AuthTokenError) {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
@ -26,7 +26,8 @@ class SplashView extends StatelessWidget {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
alignment: Alignment.center,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/nav_cubit.dart';
|
||||
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
@ -24,10 +23,6 @@ class MyApp extends StatelessWidget {
|
||||
BlocProvider(
|
||||
create: (context) => AuthCubit(),
|
||||
),
|
||||
BlocProvider(
|
||||
lazy: false,
|
||||
create: (context) => NavCubit(),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
Reference in New Issue
Block a user