mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
remove comment DevicesViewBody and fix home page
This commit is contained in:
@ -77,6 +77,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
static bool manageScene = false;
|
||||
static bool manageDeviceLocation = false;
|
||||
static bool visitorPasswordManagement = false;
|
||||
String errorMsg = '';
|
||||
|
||||
Future<void> fetchPermissions() async {
|
||||
try {
|
||||
@ -409,12 +410,11 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
return res['success'];
|
||||
} on DioException catch (e) {
|
||||
final errorMessage = e.response?.data['error']['message'];
|
||||
emitSafe(ActivationError(errMessage: errorMessage));
|
||||
return false;
|
||||
} catch (e) {
|
||||
emitSafe(ActivationError(errMessage: e.toString()));
|
||||
errorMsg = e.response?.data['error']['message'];
|
||||
emitSafe(ActivationError(errMessage: errorMsg));
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////// Nav ///////////////////////////////////////
|
||||
|
@ -14,8 +14,8 @@ class HomeError extends HomeState {
|
||||
}
|
||||
|
||||
class HomeSuccess extends HomeState {}
|
||||
class ActivationSuccess extends HomeState {}
|
||||
|
||||
class ActivationSuccess extends HomeState {}
|
||||
|
||||
class GetSpacesLoading extends HomeLoading {}
|
||||
|
||||
@ -64,8 +64,8 @@ class RoomSelected extends HomeState {
|
||||
class RoomUnSelected extends HomeState {}
|
||||
|
||||
class NavChangePage extends HomeState {}
|
||||
class HomePermissionUpdated extends HomeState {}
|
||||
|
||||
class HomePermissionUpdated extends HomeState {}
|
||||
|
||||
class HomeUserInfoLoaded extends HomeState {
|
||||
final UserModel user;
|
||||
|
@ -48,6 +48,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
return _instance ??= DevicesCubit._();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_instance = null;
|
||||
@ -710,7 +711,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> changeGarageSwitch(
|
||||
DeviceControlModel control, String deviceUuid) async {
|
||||
emit(SwitchControlLoading(code: control.code));
|
||||
|
@ -1,138 +1,3 @@
|
||||
// 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/home_cubit.dart';
|
||||
// import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
// import 'package:syncrow_app/features/devices/view/widgets/all_devices.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/wizard_page.dart';
|
||||
// import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||
// import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||
// import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
||||
// import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.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/strings_manager.dart';
|
||||
|
||||
// class DevicesViewPage extends StatelessWidget {
|
||||
// const DevicesViewPage({super.key});
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return BlocProvider(
|
||||
// create: (context) => SceneBloc(), // Initialize your SceneBloc here
|
||||
// child: DevicesViewBody(),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// class DevicesViewBody extends StatelessWidget {
|
||||
// const DevicesViewBody({
|
||||
// super.key,
|
||||
// });
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
// builder: (context, state) {
|
||||
// if (state is DevicesLoading ||
|
||||
// state is GetDevicesLoading ||
|
||||
// state is DevicesCategoriesLoading) {
|
||||
// return const Center(child: CircularProgressIndicator());
|
||||
// } else {
|
||||
// return HomeCubit.getInstance().spaces?.isEmpty ?? true
|
||||
// ? const CreateUnitWidget()
|
||||
// : Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// Row(
|
||||
// children: [
|
||||
// TitleMedium(
|
||||
// text: StringsManager.devices,
|
||||
// style: context.titleMedium.copyWith(
|
||||
// fontSize: 25,
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// SizedBox(
|
||||
// height: MediaQuery.of(context).size.height * 0.1,
|
||||
// child: const SceneView(
|
||||
// pageType: true,
|
||||
// )),
|
||||
// const SizedBox(
|
||||
// height: 20,
|
||||
// ),
|
||||
// const RoomsSlider(),
|
||||
// const SizedBox(
|
||||
// height: 10,
|
||||
// ),
|
||||
// Expanded(
|
||||
// child: PageView(
|
||||
// controller:
|
||||
// HomeCubit.getInstance().devicesPageController,
|
||||
// onPageChanged: (index) {
|
||||
// HomeCubit.getInstance().devicesPageChanged(index);
|
||||
// print(index);
|
||||
// if (index == 0) {
|
||||
// context.read<DevicesCubit>().fetchAllDevices(HomeCubit.getInstance().selectedSpace);
|
||||
// }
|
||||
// },
|
||||
// children: [
|
||||
// AllDevices(
|
||||
// allDevices: context.read<DevicesCubit>().allDevices,
|
||||
// ),
|
||||
// WizardPage(
|
||||
// groupsList:
|
||||
// DevicesCubit.getInstance().allCategories ?? [],
|
||||
// ),
|
||||
// if (HomeCubit.getInstance().selectedSpace != null)
|
||||
// ...HomeCubit.getInstance()
|
||||
// .selectedSpace!
|
||||
// .subspaces
|
||||
// .map(
|
||||
// (room) {
|
||||
// return RoomPage(
|
||||
// room: room,
|
||||
// );
|
||||
// },
|
||||
// )
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// HomeCubit.getInstance().selectedSpace != null
|
||||
// ? Padding(
|
||||
// padding: const EdgeInsets.symmetric(
|
||||
// vertical: 7,
|
||||
// ),
|
||||
// child: SmoothPageIndicator(
|
||||
// controller:
|
||||
// HomeCubit.getInstance().devicesPageController,
|
||||
// count: HomeCubit.getInstance()
|
||||
// .selectedSpace!
|
||||
// .subspaces
|
||||
// .length +
|
||||
// 2,
|
||||
// effect: const WormEffect(
|
||||
// paintStyle: PaintingStyle.stroke,
|
||||
// dotHeight: 8,
|
||||
// dotWidth: 8,
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// : const Center(
|
||||
// child: BodyLarge(text: 'No Home Found'),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||
@ -151,48 +16,63 @@ import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||
|
||||
class DevicesViewBody extends StatelessWidget {
|
||||
const DevicesViewBody({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, homeState) {
|
||||
final homeCubit = HomeCubit.getInstance();
|
||||
|
||||
// Handle state priority: Errors first
|
||||
if (homeState is ActivationError) {
|
||||
return const CreateUnitWidget();
|
||||
}
|
||||
|
||||
// Handle loading states
|
||||
if (homeState is GetSpacesLoading || homeState is HomeLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final spaces = homeCubit.spaces;
|
||||
|
||||
// Handle error states
|
||||
if (homeState is GetSpacesError) {
|
||||
return const CreateUnitWidget();
|
||||
}
|
||||
|
||||
// Handle success states
|
||||
if (homeState is GetSpacesSuccess ||
|
||||
homeState is RoomUnSelected ||
|
||||
homeState is RoomSelected ||
|
||||
homeState is NavChangePage) {
|
||||
// Show empty state if no spaces
|
||||
if (homeCubit.spaces.isEmpty) {
|
||||
return const CreateUnitWidget();
|
||||
}
|
||||
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, devicesState) {
|
||||
// Devices loading states
|
||||
if (devicesState is DevicesLoading ||
|
||||
devicesState is DevicesCategoriesLoading ||
|
||||
devicesState is GetDevicesLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (spaces.isEmpty) {
|
||||
return FutureBuilder(
|
||||
future: Future.delayed(
|
||||
const Duration(seconds: 1)),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(
|
||||
child:
|
||||
CircularProgressIndicator());
|
||||
}
|
||||
if (spaces.isEmpty) {
|
||||
return const CreateUnitWidget();
|
||||
}
|
||||
return Container();
|
||||
});
|
||||
}
|
||||
|
||||
// Devices error state
|
||||
if (devicesState is GetDevicesError) {
|
||||
return const Center(child: Text('Error'));
|
||||
return Center(child: BodyLarge(text: devicesState.errorMsg));
|
||||
}
|
||||
if (devicesState is GetDevicesSuccess ||
|
||||
devicesState is SwitchControlLoading ||
|
||||
devicesState is DeviceControlSuccess ||
|
||||
devicesState is DeviceControlError) {
|
||||
if (spaces.isEmpty) {
|
||||
return const CreateUnitWidget();
|
||||
} else {
|
||||
// Main content for both GetSpacesSuccess and RoomUnSelected
|
||||
return _buildMainContent(context, homeCubit);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback for unknown states
|
||||
return const Center(child: BodyLarge(text: ''));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMainContent(BuildContext context, HomeCubit homeCubit) {
|
||||
final devicesCubit = context.read<DevicesCubit>();
|
||||
|
||||
return Column(
|
||||
@ -220,18 +100,15 @@ class DevicesViewBody extends StatelessWidget {
|
||||
onPageChanged: (index) {
|
||||
homeCubit.devicesPageChanged(index);
|
||||
if (index == 0) {
|
||||
devicesCubit.fetchAllDevices(
|
||||
homeCubit.selectedSpace,
|
||||
);
|
||||
devicesCubit.fetchAllDevices(homeCubit.selectedSpace);
|
||||
}
|
||||
},
|
||||
children: [
|
||||
AllDevices(
|
||||
allDevices: DevicesCubit.getInstance().allDevices,
|
||||
allDevices: devicesCubit.allDevices,
|
||||
),
|
||||
WizardPage(
|
||||
groupsList:
|
||||
DevicesCubit.getInstance().allCategories ?? [],
|
||||
groupsList: devicesCubit.allCategories ?? [],
|
||||
),
|
||||
if (homeCubit.selectedSpace != null)
|
||||
...homeCubit.selectedSpace!.subspaces.map(
|
||||
@ -240,13 +117,18 @@ class DevicesViewBody extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
homeCubit.selectedSpace != null
|
||||
_buildPageIndicator(homeCubit),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPageIndicator(HomeCubit homeCubit) {
|
||||
return homeCubit.selectedSpace != null
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 7),
|
||||
child: SmoothPageIndicator(
|
||||
controller: homeCubit.devicesPageController,
|
||||
count:
|
||||
homeCubit.selectedSpace!.subspaces.length + 2,
|
||||
count: homeCubit.selectedSpace!.subspaces.length + 2,
|
||||
effect: const WormEffect(
|
||||
paintStyle: PaintingStyle.stroke,
|
||||
dotHeight: 8,
|
||||
@ -256,15 +138,6 @@ class DevicesViewBody extends StatelessWidget {
|
||||
)
|
||||
: const Center(
|
||||
child: BodyLarge(text: 'No Home Found'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class JoinHomeView extends StatelessWidget {
|
||||
const JoinHomeView({super.key});
|
||||
@ -57,14 +59,93 @@ class JoinHomeView extends StatelessWidget {
|
||||
'Please enter the invitation code');
|
||||
return;
|
||||
}
|
||||
if (await HomeCubit.getInstance().activationCode(textEditingController.text)) {
|
||||
if (await HomeCubit.getInstance()
|
||||
.activationCode(textEditingController.text)) {
|
||||
await HomeCubit.getInstance().fetchUnitsByUserId();
|
||||
|
||||
CustomSnackBar.displaySnackBar('Done successfully');
|
||||
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
CustomSnackBar.displaySnackBar('Wrong code!');
|
||||
// CustomSnackBar.displaySnackBar('Wrong code!');
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
content: SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.2,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
const BodyLarge(
|
||||
text: "Warning",
|
||||
fontWeight: FontWeight.w700,
|
||||
fontColor: ColorsManager.red,
|
||||
fontSize: 16,
|
||||
),
|
||||
const Padding(
|
||||
padding:
|
||||
EdgeInsets.only(left: 15, right: 15),
|
||||
child: Divider(
|
||||
color: ColorsManager.textGray,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 15,
|
||||
right: 20,
|
||||
top: 15,
|
||||
bottom: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
HomeCubit.getInstance().errorMsg,
|
||||
textAlign: TextAlign.center,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: ColorsManager.textGray,
|
||||
width: 1.0,
|
||||
),
|
||||
)),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 5, bottom: 5),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Ok',
|
||||
style: TextStyle(
|
||||
color: ColorsManager
|
||||
.switchButton
|
||||
.withOpacity(0.6),
|
||||
fontSize: 14,
|
||||
fontWeight:
|
||||
FontWeight.w400),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(
|
||||
|
@ -16,7 +16,8 @@ class CreateUnitWidget extends StatelessWidget {
|
||||
TextEditingController textEditingController = TextEditingController();
|
||||
return BlocConsumer<HomeCubit, HomeState>(
|
||||
listener: (context, state) {
|
||||
// if (state is ActivationError) {}
|
||||
// if (state is ActivationError) {
|
||||
// }
|
||||
},
|
||||
builder: (context, state) {
|
||||
return SingleChildScrollView(
|
||||
@ -101,9 +102,6 @@ class CreateUnitWidget extends StatelessWidget {
|
||||
() {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
CustomSnackBar.displaySnackBar(
|
||||
'Wrong code!');
|
||||
}
|
||||
},
|
||||
icon: const Icon(
|
||||
@ -113,14 +111,14 @@ class CreateUnitWidget extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
// state is ActivationError
|
||||
// ? Text(
|
||||
// state.errMessage,
|
||||
// style: const TextStyle(
|
||||
// color: ColorsManager.red,
|
||||
// fontWeight: FontWeight.w400),
|
||||
// )
|
||||
// : const SizedBox()
|
||||
state is ActivationError
|
||||
? Text(
|
||||
state.errMessage,
|
||||
style: const TextStyle(
|
||||
color: ColorsManager.red,
|
||||
fontWeight: FontWeight.w400),
|
||||
)
|
||||
: const SizedBox()
|
||||
],
|
||||
),
|
||||
],
|
||||
|
Reference in New Issue
Block a user