mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 10:04:54 +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:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/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/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/network_exception.dart';
|
||||||
import 'package:syncrow_app/services/api/spaces_api.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 'spaces_state.dart';
|
||||||
|
|
||||||
class SpacesCubit extends Cubit<SpacesState> {
|
class SpacesCubit extends Cubit<SpacesState> {
|
||||||
SpacesCubit() : super(SpacesInitial()) {
|
SpacesCubit() : super(SpacesInitial()) {
|
||||||
|
if (SpacesCubit.spaces != null) {
|
||||||
|
if (selectedSpace == null) {
|
||||||
fetchSpaces().then((value) {
|
fetchSpaces().then((value) {
|
||||||
if (selectedSpace != null) {
|
if (selectedSpace != null) {
|
||||||
|
print('selectedSpace: ${selectedSpace!.name}');
|
||||||
fetchRooms(selectedSpace!);
|
fetchRooms(selectedSpace!);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fetchSpaces(); // this is for the first time
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static SpacesCubit get(context) => BlocProvider.of(context);
|
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;
|
RoomModel? selectedRoom;
|
||||||
|
|
||||||
@ -33,7 +48,7 @@ class SpacesCubit extends Cubit<SpacesState> {
|
|||||||
|
|
||||||
selectSpace(SpaceModel space) {
|
selectSpace(SpaceModel space) {
|
||||||
selectedSpace = space;
|
selectedSpace = space;
|
||||||
emit(SpacesSelected(space));
|
emit(SpaceSelected(space));
|
||||||
}
|
}
|
||||||
|
|
||||||
roomSliderPageChanged(int index) {
|
roomSliderPageChanged(int index) {
|
||||||
@ -84,27 +99,177 @@ class SpacesCubit extends Cubit<SpacesState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchSpaces() async {
|
fetchSpaces() async {
|
||||||
emit(SpacesLoading());
|
emit(GetSpacesLoading());
|
||||||
try {
|
try {
|
||||||
spaces = await SpacesAPI.getSpaces();
|
spaces = await SpacesAPI.getSpaces();
|
||||||
spaces.isNotEmpty ? selectSpace(spaces.first) : null;
|
selectedSpace = spaces!.isNotEmpty ? selectSpace(spaces!.first) : null;
|
||||||
emit(SpacesLoaded(spaces));
|
emit(GetSpacesLoaded(spaces!));
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
emit(SpacesError(ServerFailure.fromDioError(e).errMessage));
|
emit(GetSpacesError(ServerFailure.fromDioError(e).errMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchRooms(SpaceModel space) async {
|
fetchRooms(SpaceModel space) async {
|
||||||
emit(SpaceRoomsLoading());
|
emit(GetSpaceRoomsLoading());
|
||||||
try {
|
try {
|
||||||
space.rooms = await SpacesAPI.getRooms(space.id!);
|
space.rooms = await SpacesAPI.getRooms(space.id!);
|
||||||
if (space.rooms != null) {
|
if (space.rooms != null) {
|
||||||
emit(SpaceRoomsLoaded(space.rooms!));
|
emit(GetSpaceRoomsLoaded(space.rooms!));
|
||||||
} else {
|
} else {
|
||||||
emit(SpaceRoomsError("No rooms found"));
|
emit(GetSpaceRoomsError("No rooms found"));
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} 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 SpacesInitial extends SpacesState {}
|
||||||
|
|
||||||
class SpacesLoading extends SpacesState {}
|
class GetSpacesLoading extends SpacesState {}
|
||||||
|
|
||||||
class SpacesLoaded extends SpacesState {
|
class GetSpacesLoaded extends SpacesState {
|
||||||
final List<SpaceModel> spaces;
|
final List<SpaceModel> spaces;
|
||||||
|
|
||||||
SpacesLoaded(this.spaces);
|
GetSpacesLoaded(this.spaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpacesError extends SpacesState {
|
class GetSpacesError extends SpacesState {
|
||||||
final String errMessage;
|
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;
|
final List<RoomModel> rooms;
|
||||||
|
|
||||||
SpaceRoomsLoaded(this.rooms);
|
GetSpaceRoomsLoaded(this.rooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpaceRoomsError extends SpacesError {
|
class GetSpaceRoomsError extends SpacesState {
|
||||||
SpaceRoomsError(super.errMessage);
|
final String errMessage;
|
||||||
|
GetSpaceRoomsError(this.errMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpacesSelected extends SpacesState {
|
class SpaceSelected extends SpacesState {
|
||||||
final SpaceModel space;
|
final SpaceModel space;
|
||||||
|
|
||||||
SpacesSelected(this.space);
|
SpaceSelected(this.space);
|
||||||
}
|
}
|
||||||
|
|
||||||
class RoomSelected extends SpacesState {
|
class RoomSelected extends SpacesState {
|
||||||
@ -43,3 +44,5 @@ class RoomSelected extends SpacesState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RoomUnSelected extends SpacesState {}
|
class RoomUnSelected extends SpacesState {}
|
||||||
|
|
||||||
|
class NavChangePage extends SpacesState {}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/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/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_app_bar.dart';
|
||||||
@ -26,7 +26,7 @@ class AppLayout extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
child: BlocListener<SpacesCubit, SpacesState>(
|
child: BlocListener<SpacesCubit, SpacesState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is SpacesError) {
|
if (state is GetSpacesError) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(state.errMessage),
|
content: Text(state.errMessage),
|
||||||
@ -36,7 +36,7 @@ class AppLayout extends StatelessWidget {
|
|||||||
.popUntil((route) => route.settings.name == Routes.authLogin);
|
.popUntil((route) => route.settings.name == Routes.authLogin);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: BlocBuilder<NavCubit, NavState>(
|
child: BlocBuilder<SpacesCubit, SpacesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return AnnotatedRegion(
|
return AnnotatedRegion(
|
||||||
value: SystemUiOverlayStyle(
|
value: SystemUiOverlayStyle(
|
||||||
@ -50,13 +50,13 @@ class AppLayout extends StatelessWidget {
|
|||||||
backgroundColor: ColorsManager.backgroundColor,
|
backgroundColor: ColorsManager.backgroundColor,
|
||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
appBar:
|
appBar: state is! GetSpacesLoading ||
|
||||||
state is! SpacesLoading || state is! SpaceRoomsLoading
|
state is! GetSpaceRoomsLoading
|
||||||
? const DefaultAppBar()
|
? const DefaultAppBar()
|
||||||
: null,
|
: null,
|
||||||
body: const AppBody(),
|
body: const AppBody(),
|
||||||
bottomNavigationBar:
|
bottomNavigationBar: state is! GetSpacesLoading ||
|
||||||
state is! SpacesLoading || state is! SpaceRoomsLoading
|
state is! GetSpaceRoomsLoading
|
||||||
? const DefaultNavBar()
|
? const DefaultNavBar()
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -17,7 +17,9 @@ class AppBarHomeDropdown extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||||
builder: (context, state) {
|
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),
|
padding: const EdgeInsets.only(left: 10, right: 10),
|
||||||
child: DropdownButton(
|
child: DropdownButton(
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
@ -29,7 +31,7 @@ class AppBarHomeDropdown extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
value: SpacesCubit.selectedSpace!.id,
|
value: SpacesCubit.selectedSpace!.id,
|
||||||
items: SpacesCubit.spaces.map((space) {
|
items: SpacesCubit.spaces!.map((space) {
|
||||||
return DropdownMenuItem(
|
return DropdownMenuItem(
|
||||||
value: space.id,
|
value: space.id,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
@ -65,7 +67,7 @@ class AppBarHomeDropdown extends StatelessWidget {
|
|||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
SpacesCubit.get(context).selectSpace(SpacesCubit.spaces
|
SpacesCubit.get(context).selectSpace(SpacesCubit.spaces!
|
||||||
.firstWhere((element) => element.id == value));
|
.firstWhere((element) => element.id == value));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/bloc/spaces_cubit.dart';
|
||||||
|
|
||||||
import '../../../../generated/assets.dart';
|
import '../../../../generated/assets.dart';
|
||||||
@ -12,7 +12,7 @@ class AppBody extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<NavCubit, NavState>(
|
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return Container(
|
return Container(
|
||||||
width: MediaQuery.sizeOf(context).width,
|
width: MediaQuery.sizeOf(context).width,
|
||||||
@ -28,7 +28,7 @@ class AppBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: BlocConsumer<SpacesCubit, SpacesState>(
|
child: BlocConsumer<SpacesCubit, SpacesState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is SpacesError) {
|
if (state is GetSpacesError) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(state.errMessage),
|
content: Text(state.errMessage),
|
||||||
@ -37,8 +37,9 @@ class AppBody extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return state is! SpacesLoading || state is! SpaceRoomsLoading
|
return state is! GetSpacesLoading ||
|
||||||
? NavCubit.of(context).pages[NavCubit.pageIndex]
|
state is! GetSpaceRoomsLoading
|
||||||
|
? SpacesCubit.get(context).pages[SpacesCubit.pageIndex]
|
||||||
: const Center(child: CircularProgressIndicator());
|
: const Center(child: CircularProgressIndicator());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/bloc/spaces_cubit.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
@ -9,8 +9,6 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<NavCubit, NavState>(
|
|
||||||
builder: (context, state) {
|
|
||||||
return BlocBuilder<SpacesCubit, SpacesState>(
|
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return Padding(
|
return Padding(
|
||||||
@ -21,18 +19,19 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
leadingWidth: 150,
|
leadingWidth: 150,
|
||||||
toolbarHeight: Constants.appBarHeight,
|
toolbarHeight: Constants.appBarHeight,
|
||||||
leading: SpacesCubit.spaces.isNotEmpty
|
leading: SpacesCubit.spaces != null
|
||||||
? NavCubit.appBarLeading[
|
? SpacesCubit.spaces!.isNotEmpty
|
||||||
NavCubit().bottomNavItems[NavCubit.pageIndex].label]
|
? SpacesCubit.appBarLeading[SpacesCubit()
|
||||||
|
.bottomNavItems[SpacesCubit.pageIndex]
|
||||||
|
.label]
|
||||||
|
: null
|
||||||
: null,
|
: null,
|
||||||
actions: NavCubit.appBarActions[
|
actions: SpacesCubit.appBarActions[
|
||||||
NavCubit().bottomNavItems[NavCubit.pageIndex].label],
|
SpacesCubit().bottomNavItems[SpacesCubit.pageIndex].label],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/bloc/spaces_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_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/color_manager.dart';
|
||||||
@ -13,9 +13,9 @@ class DefaultNavBar extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<NavCubit, NavState>(
|
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
var cubit = NavCubit.of(context);
|
var cubit = SpacesCubit.get(context);
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: Constants.bottomNavBarHeight,
|
height: Constants.bottomNavBarHeight,
|
||||||
child: BottomNavigationBar(
|
child: BottomNavigationBar(
|
||||||
@ -29,7 +29,7 @@ class DefaultNavBar extends StatelessWidget {
|
|||||||
SpacesCubit.get(context).unselectRoom();
|
SpacesCubit.get(context).unselectRoom();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
currentIndex: NavCubit.pageIndex,
|
currentIndex: SpacesCubit.pageIndex,
|
||||||
selectedItemColor: ColorsManager.primaryColor,
|
selectedItemColor: ColorsManager.primaryColor,
|
||||||
selectedLabelStyle: const TextStyle(
|
selectedLabelStyle: const TextStyle(
|
||||||
color: ColorsManager.primaryColor,
|
color: ColorsManager.primaryColor,
|
||||||
|
|||||||
@ -3,7 +3,8 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.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/login_with_email_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||||
@ -75,7 +76,7 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
try {
|
try {
|
||||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||||
await storage.delete(key: Token.loginAccessTokenKey);
|
await storage.delete(key: Token.loginAccessTokenKey);
|
||||||
NavCubit.clear();
|
SpacesCubit.clear();
|
||||||
emit(AuthLoggedOut());
|
emit(AuthLoggedOut());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
emit(AuthError(ServerFailure.fromDioError(e).errMessage));
|
emit(AuthError(ServerFailure.fromDioError(e).errMessage));
|
||||||
|
|||||||
@ -22,8 +22,10 @@ part 'devices_state.dart';
|
|||||||
|
|
||||||
class DevicesCubit extends Cubit<DevicesState> {
|
class DevicesCubit extends Cubit<DevicesState> {
|
||||||
DevicesCubit() : super(DevicesInitial()) {
|
DevicesCubit() : super(DevicesInitial()) {
|
||||||
|
if (SpacesCubit.selectedSpace != null) {
|
||||||
fetchGroups(SpacesCubit.selectedSpace!.id!);
|
fetchGroups(SpacesCubit.selectedSpace!.id!);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bool _isClosed = false;
|
bool _isClosed = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -8,16 +8,13 @@ class DevicesView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
create: (context) => DevicesCubit(),
|
|
||||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
|
||||||
builder: (context, state) => Container(
|
builder: (context, state) => Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
width: MediaQuery.sizeOf(context).width,
|
width: MediaQuery.sizeOf(context).width,
|
||||||
height: MediaQuery.sizeOf(context).height,
|
height: MediaQuery.sizeOf(context).height,
|
||||||
child: const DevicesViewBody(),
|
child: const DevicesViewBody(),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,9 +22,7 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
create: (context) => DevicesCubit(),
|
|
||||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return DefaultContainer(
|
return DefaultContainer(
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -145,7 +143,6 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,17 +16,14 @@ class ACsView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
create: (context) => DevicesCubit(),
|
|
||||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
DeviceModel? selectedAC;
|
DeviceModel? selectedAC;
|
||||||
if (DevicesCubit.get(context).getSelectedDevice()
|
if (DevicesCubit.get(context).getSelectedDevice() is DeviceModel) {
|
||||||
is DeviceModel) {
|
selectedAC =
|
||||||
selectedAC = DevicesCubit.get(context).getSelectedDevice()
|
DevicesCubit.get(context).getSelectedDevice() as DeviceModel;
|
||||||
as DeviceModel;
|
|
||||||
}
|
}
|
||||||
return AnnotatedRegion(
|
return AnnotatedRegion(
|
||||||
value: SystemUiOverlayStyle(
|
value: SystemUiOverlayStyle(
|
||||||
@ -70,7 +67,6 @@ class ACsView extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,7 @@ class CurtainView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
create: (context) => DevicesCubit(),
|
|
||||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return AnnotatedRegion(
|
return AnnotatedRegion(
|
||||||
value: SystemUiOverlayStyle(
|
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/room_page.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.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/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 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
import '../../bloc/devices_cubit.dart';
|
import '../../bloc/devices_cubit.dart';
|
||||||
@ -17,9 +18,7 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocBuilder<SpacesCubit, SpacesState>(
|
||||||
create: (context) => DevicesCubit(),
|
|
||||||
child: BlocBuilder<SpacesCubit, SpacesState>(
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
@ -61,20 +60,25 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
SpacesCubit.selectedSpace != null
|
||||||
|
? Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 7,
|
vertical: 7,
|
||||||
),
|
),
|
||||||
child: SmoothPageIndicator(
|
child: SmoothPageIndicator(
|
||||||
controller:
|
controller: SpacesCubit.get(context)
|
||||||
SpacesCubit.get(context).devicesPageController,
|
.devicesPageController,
|
||||||
count: SpacesCubit.selectedSpace!.rooms!.length + 1,
|
count:
|
||||||
|
SpacesCubit.selectedSpace!.rooms!.length + 1,
|
||||||
effect: const WormEffect(
|
effect: const WormEffect(
|
||||||
paintStyle: PaintingStyle.stroke,
|
paintStyle: PaintingStyle.stroke,
|
||||||
dotHeight: 8,
|
dotHeight: 8,
|
||||||
dotWidth: 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
create: (context) => DevicesCubit(),
|
|
||||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
DeviceModel? selectedLight;
|
DeviceModel? selectedLight;
|
||||||
if (DevicesCubit.get(context).getSelectedDevice()
|
if (DevicesCubit.get(context).getSelectedDevice() is DeviceModel) {
|
||||||
is DeviceModel) {
|
selectedLight =
|
||||||
selectedLight = DevicesCubit.get(context).getSelectedDevice()
|
DevicesCubit.get(context).getSelectedDevice() as DeviceModel;
|
||||||
as DeviceModel;
|
|
||||||
}
|
}
|
||||||
List<DeviceModel> lights = [];
|
List<DeviceModel> lights = [];
|
||||||
if (DevicesCubit.allCategories![1].devices != null) {
|
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/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/function_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';
|
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
|
||||||
@ -26,7 +27,7 @@ class LightSwitchesView extends StatelessWidget {
|
|||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
appBar: const CategoryViewAppBar(),
|
appBar: const CategoryViewAppBar(),
|
||||||
body: BlocBuilder<NavCubit, NavState>(
|
body: BlocBuilder<SpacesCubit, SpacesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return Container(
|
return Container(
|
||||||
width: MediaQuery.sizeOf(context).width,
|
width: MediaQuery.sizeOf(context).width,
|
||||||
|
|||||||
@ -12,13 +12,13 @@ class SplashView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<AuthCubit, AuthState>(
|
return BlocConsumer<AuthCubit, AuthState>(
|
||||||
builder: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is AuthTokenSuccess) {
|
if (state is AuthTokenSuccess) {
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
Navigator.pushReplacementNamed(context, Routes.homeRoute);
|
Navigator.pushReplacementNamed(context, Routes.homeRoute);
|
||||||
});
|
});
|
||||||
} else {
|
} else if (state is AuthTokenError) {
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
@ -26,7 +26,8 @@ class SplashView extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
builder: (context, state) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Stack(
|
body: Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/features/auth/bloc/auth_cubit.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
@ -24,10 +23,6 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => AuthCubit(),
|
create: (context) => AuthCubit(),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
|
||||||
lazy: false,
|
|
||||||
create: (context) => NavCubit(),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user