import 'package:flutter/cupertino.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/devices/bloc/sos_bloc/sos_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart'; import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/sos_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/sos/sos_setting/delete_dialog.dart'; import 'package:syncrow_app/features/devices/view/widgets/sos/sos_setting/sos_profile_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/sos/sos_setting/faq_sos_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/sos/sos_setting/share_sos_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/sos/sos_setting/sos_info_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/sos/sos_setting/sos_update_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/sos/sos_setting/update_dialog_sos.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_medium.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart'; import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class SosSettings extends StatelessWidget { final DeviceModel? device; const SosSettings({ super.key, this.device, }); @override Widget build(BuildContext context) { return DefaultScaffold( title: 'Device Settings', child: BlocProvider( create: (context) => SosBloc(sosId: device?.uuid ?? '') ..add(const SosInitial()) ..add(SosInitialDeviseInfo()), child: BlocBuilder( builder: (context, state) { final _bloc = BlocProvider.of(context); SosModel model = SosModel(batteryPercentage: 0, sosContactState: 'normal'); if (state is LoadingNewSate) { model = state.sosSensor; } else if (state is UpdateState) { model = state.sensor; } return state is SosLoadingState ? const Center( child: DefaultContainer( width: 50, height: 50, child: CircularProgressIndicator()), ) : ListView( children: [ Padding( padding: const EdgeInsets.symmetric( vertical: 10, ), child: InkWell( onTap: () async { bool val = await Navigator.of(context).push( MaterialPageRoute( builder: (context) => SosProfilePage( device: device, ), ), ); if (val == true) { _bloc.add(SosInitialDeviseInfo()); _bloc.add(const SosInitial()); } }, child: Stack( children: [ Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const SizedBox(height: 20), DefaultContainer( borderRadius: const BorderRadius.all( Radius.circular(30)), child: Padding( padding: const EdgeInsets.all(10.0), child: Padding( padding: const EdgeInsets.only(left: 90), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ BodyMedium( text: _bloc.deviceInfo.name, fontWeight: FontWeight.bold, ), const SizedBox( height: 5, ), BodySmall( text: _bloc.deviceInfo .subspace.subspaceName), ], ), const Icon( Icons.edit_outlined, color: ColorsManager.grayColor, ), ], ), ), ), ), ], ), Positioned( top: 0, left: 20, child: CircleAvatar( radius: 40, backgroundColor: Colors.white, child: CircleAvatar( radius: 40, backgroundColor: Colors.grey, child: ClipOval( child: SvgPicture.asset( Assets.sosProfileIcon, fit: BoxFit.fill, ), ), ), ), ), ], ), ), ), const SizedBox(height: 20), const BodyMedium( text: 'Device Management', fontWeight: FontWeight.w700, fontSize: 12, fontColor: ColorsManager.grayColor, ), DefaultContainer( child: SettingWidget( onTap: () { Navigator.of(context).push( MaterialPageRoute( builder: (context) => SosInfoPage(device: device!)), ); }, text: 'Device Information', icon: Assets.infoIcon, ), ), const SizedBox(height: 20), const BodyMedium( text: 'Device Offline Notification', fontWeight: FontWeight.w700, fontSize: 12, fontColor: ColorsManager.grayColor, ), DefaultContainer( child: Column( children: [ SettingWidget( value: _bloc.enableAlarm, onChanged: (p0) { context .read() .add(ToggleEnableAlarmEvent(p0)); }, isNotification: true, onTap: () {}, text: 'Offline Notification', icon: Assets.notificationIcon, ), ], ), ), const SizedBox(height: 20), const BodyMedium( text: 'Others', fontWeight: FontWeight.w700, fontSize: 12, fontColor: ColorsManager.grayColor, ), const SizedBox(height: 5), DefaultContainer( child: Column( children: [ SettingWidget( onTap: () { Navigator.of(context).push( MaterialPageRoute( builder: (context) => ShareSosPage(device: device!)), ); }, text: 'Share Device', icon: Assets.shareIcon, ), const Divider( color: ColorsManager.dividerColor, ), SettingWidget( onTap: () { Navigator.of(context).push( MaterialPageRoute( builder: (context) => FaqSosPage(device: device!)), ); }, text: 'Device FAQ', icon: Assets.faqIcon, ), const Divider( color: ColorsManager.dividerColor, ), SettingWidget( onTapUpdate: () { showDialog( context: context, builder: (context) { return UpdateInfoDialog( cancelTab: () { Navigator.of(context).pop(); }, confirmTab: () { // context // .read< // CreateSceneBloc>() // .add(DeleteSceneEvent( // sceneId: sceneId, // unitUuid: HomeCubit // .getInstance() // .selectedSpace! // .id!, // )); Navigator.of(context).pop(); }, ); }, ); }, isUpdate: true, onTap: () { Navigator.of(context).push( MaterialPageRoute( builder: (context) => const SosUpdatePage()), ); }, text: 'Device Update', icon: Assets.updateIcon, ), ], ), ), const SizedBox(height: 20), InkWell( onTap: () { showModalBottomSheet( context: context, builder: (BuildContext context) { return Container( height: 200, padding: const EdgeInsets.all(16.0), child: Column( mainAxisSize: MainAxisSize.min, children: [ const BodyMedium( text: 'Remove Device', fontWeight: FontWeight.w700, fontSize: 16, fontColor: ColorsManager.red, ), const SizedBox(height: 10), const SizedBox( width: 250, child: Divider( color: ColorsManager.dividerColor, ), ), const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ InkWell( onTap: () { showDialog( context: context, builder: (context) { return DisconnectDeviceDialog( cancelTab: () { Navigator.of(context).pop(); }, confirmTab: () { // context // .read< // CreateSceneBloc>() // .add(DeleteSceneEvent( // sceneId: sceneId, // unitUuid: HomeCubit // .getInstance() // .selectedSpace! // .id!, // )); Navigator.of(context).pop(); }, ); }, ); }, child: const BodyMedium( text: 'Disconnect Device', fontWeight: FontWeight.w400, fontSize: 15, fontColor: ColorsManager.textPrimaryColor, ), ), const Icon( Icons.keyboard_arrow_right, color: ColorsManager.textGray, ) ], ), const SizedBox(height: 20), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ InkWell( onTap: () { showDialog( context: context, builder: (context) { return DisconnectWipeData( cancelTab: () { Navigator.of(context).pop(); }, confirmTab: () { // context // .read< // CreateSceneBloc>() // .add(DeleteSceneEvent( // sceneId: sceneId, // unitUuid: HomeCubit // .getInstance() // .selectedSpace! // .id!, // )); Navigator.of(context).pop(); }, ); }, ); }, child: const BodyMedium( text: 'Disconnect Device and Wipe Data', fontWeight: FontWeight.w400, fontSize: 15, fontColor: ColorsManager.textPrimaryColor, ), ), const Icon( Icons.keyboard_arrow_right, color: ColorsManager.textGray, ) ], ), ], ), ); }, ); }, child: const Center( child: BodyMedium( text: 'Remove Device', fontWeight: FontWeight.w400, fontSize: 15, fontColor: ColorsManager.red, ), ), ), ], ); }, ), ), ); } } class SettingWidget extends StatelessWidget { final String? text; final bool? isUpdate; final bool? value; final bool? isNotification; final String? icon; final Function()? onTap; final Function()? onTapUpdate; final Function(bool)? onChanged; const SettingWidget( {super.key, this.text, this.icon, this.value, this.onTap, this.isUpdate, this.onChanged, this.isNotification = false, this.onTapUpdate}); @override Widget build(BuildContext context) { return InkWell( onTap: onTap, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: Row( children: [ Expanded( flex: 2, child: Container( padding: EdgeInsets.all(8), decoration: const BoxDecoration( color: ColorsManager.primaryColor, borderRadius: BorderRadius.all(Radius.circular(20))), child: SvgPicture.asset( icon!, fit: BoxFit.none, height: 30, ), ), ), const SizedBox( width: 8, ), Expanded( flex: isUpdate == true ? 5 : 10, child: BodyMedium( text: text!, fontSize: 15, fontWeight: FontWeight.w400, )), ], ), ), isUpdate == true ? InkWell( onTap: onTapUpdate, child: const BodyMedium( text: '1 Update Available', fontSize: 13, fontWeight: FontWeight.w400, fontColor: ColorsManager.blueColor, ), ) : SizedBox(), isNotification == false ? const Icon( Icons.arrow_forward_ios, color: ColorsManager.graysColor, size: 20, ) : Transform.scale( scale: .8, child: CupertinoSwitch( value: value!, onChanged: onChanged, applyTheme: true, ), ), ], ), ); } }