issue fixes

This commit is contained in:
mohammad
2024-11-24 17:04:29 +03:00
parent b365f7e347
commit efe68ecb1a
14 changed files with 332 additions and 269 deletions

View File

@ -47,6 +47,7 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
on<FetchRoomsEvent>(_fetchRoomsAndDevices); on<FetchRoomsEvent>(_fetchRoomsAndDevices);
on<SixSceneInitialQuestion>(_onSixSceneInitial); on<SixSceneInitialQuestion>(_onSixSceneInitial);
on<DeleteDeviceEvent>(deleteDevice); on<DeleteDeviceEvent>(deleteDevice);
on<ToggleEnableAlarmEvent>(_toggleLowBattery);
} }
final TextEditingController nameController = final TextEditingController nameController =
@ -101,6 +102,19 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
), ),
); );
bool enableAlarm = false;
void _toggleLowBattery(
ToggleEnableAlarmEvent event, Emitter<SixSceneState> emit) async {
emit(LoadingNewSate(device: deviceStatus));
try {
enableAlarm = event.isLowBatteryEnabled;
emit(UpdateState(device: deviceStatus));
} catch (e) {
emit(SixSceneFailedState(errorMessage: e.toString()));
}
}
List<SubSpaceModel> roomsList = []; List<SubSpaceModel> roomsList = [];
void _fetchRoomsAndDevices( void _fetchRoomsAndDevices(

View File

@ -48,6 +48,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
on<GetSceneBySwitchName>(getSceneByName); on<GetSceneBySwitchName>(getSceneByName);
on<SelectSceneEvent>(_selectScene); on<SelectSceneEvent>(_selectScene);
on<DeleteDeviceEvent>(deleteDevice); on<DeleteDeviceEvent>(deleteDevice);
on<ToggleEnableAlarmEvent>(_toggleLowBattery);
} }
final TextEditingController nameController = final TextEditingController nameController =
@ -144,6 +145,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
} }
bool selecedScene = false; bool selecedScene = false;
bool enableAlarm = false;
String _selectedOption = ''; String _selectedOption = '';
bool _hasSelectionChanged = false; bool _hasSelectionChanged = false;
@ -259,6 +261,18 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
} }
} }
void _toggleLowBattery(
ToggleEnableAlarmEvent event, Emitter<FourSceneState> emit) async {
emit(LoadingNewSate(device: deviceStatus));
try {
enableAlarm = event.isLowBatteryEnabled;
emit(UpdateState(device: deviceStatus));
} catch (e) {
emit(FourSceneFailedState(errorMessage: e.toString()));
}
}
// void _controlDevice( // void _controlDevice(
// ControlDeviceScene event, Emitter<FourSceneState> emit) async { // ControlDeviceScene event, Emitter<FourSceneState> emit) async {
// emit(FourSceneLoadingState()); // emit(FourSceneLoadingState());
@ -320,7 +334,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
ToggleNotificationEvent event, Emitter<FourSceneState> emit) async { ToggleNotificationEvent event, Emitter<FourSceneState> emit) async {
emit(LoadingNewSate(device: deviceStatus)); emit(LoadingNewSate(device: deviceStatus));
try { try {
closingReminder = event.isClosingEnabled; enableAlarm = event.isClosingEnabled;
emit(UpdateState(device: deviceStatus)); emit(UpdateState(device: deviceStatus));
// API call to update the state, if necessary // API call to update the state, if necessary
// await DevicesAPI.controlDevice( // await DevicesAPI.controlDevice(
@ -483,6 +497,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
} }
emit(UpdateStateList(groupDevices: groupDevices, devices: devices)); emit(UpdateStateList(groupDevices: groupDevices, devices: devices));
} }
void _assignDevice( void _assignDevice(
AssignRoomEvent event, Emitter<FourSceneState> emit) async { AssignRoomEvent event, Emitter<FourSceneState> emit) async {
try { try {

View File

@ -38,12 +38,13 @@ class SosBloc extends Bloc<SosEvent, SosState> {
on<SaveSelectionEvent>(_onSaveSelection); on<SaveSelectionEvent>(_onSaveSelection);
on<AssignRoomEvent>(_assignDevice); on<AssignRoomEvent>(_assignDevice);
on<SosInitialDeviseInfo>(fetchDeviceInfo); on<SosInitialDeviseInfo>(fetchDeviceInfo);
on<SaveNameEvent>(saveName);
// on<UnassignRoomEvent>(_unassignDevice); // on<UnassignRoomEvent>(_unassignDevice);
// on<ToggleWaterLeakAlarmEvent>(_toggleWaterLeakAlarm); // on<ToggleWaterLeakAlarmEvent>(_toggleWaterLeakAlarm);
} }
final TextEditingController nameController = final TextEditingController nameController =
TextEditingController(text: '${'firstName'}'); TextEditingController(text: deviceName);
bool isSaving = false; bool isSaving = false;
bool editName = false; bool editName = false;
final FocusNode focusNode = FocusNode(); final FocusNode focusNode = FocusNode();
@ -52,7 +53,7 @@ class SosBloc extends Bloc<SosEvent, SosState> {
bool closingReminder = false; bool closingReminder = false;
bool waterAlarm = false; bool waterAlarm = false;
SosModel deviceStatus = SosModel deviceStatus =
SosModel(sosContactState: 'normal', batteryPercentage: 0); SosModel(sosContactState: 'sos', batteryPercentage: 0);
void _fetchStatus(SosInitial event, Emitter<SosState> emit) async { void _fetchStatus(SosInitial event, Emitter<SosState> emit) async {
emit(SosLoadingState()); emit(SosLoadingState());
@ -156,16 +157,6 @@ class SosBloc extends Bloc<SosEvent, SosState> {
try { try {
closingReminder = event.isClosingReminderEnabled; closingReminder = event.isClosingReminderEnabled;
emit(UpdateState(sensor: deviceStatus)); emit(UpdateState(sensor: deviceStatus));
// API call to update the state, if necessary
// await DevicesAPI.controlDevice(
// DeviceControlModel(
// deviceId: sosId,
// code: 'closing_reminder',
// value: closingReminder,
// ),
// sosId,
// );
} catch (e) { } catch (e) {
emit(SosFailedState(errorMessage: e.toString())); emit(SosFailedState(errorMessage: e.toString()));
} }

View File

@ -71,10 +71,14 @@ class SixSceneInfoPage extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
BodySmall( SizedBox(
width:
MediaQuery.of(context).size.width * 0.61,
child: BodySmall(
text: _bloc.deviceInfo.productUuid, text: _bloc.deviceInfo.productUuid,
fontColor: ColorsManager.primaryTextColor, fontColor: ColorsManager.primaryTextColor,
), ),
),
InkWell( InkWell(
onTap: () { onTap: () {
Clipboard.setData( Clipboard.setData(

View File

@ -194,7 +194,12 @@ class SixSceneSettings extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
SettingWidget( SettingWidget(
onChanged: (p0) {}, value: _bloc.enableAlarm,
onChanged: (p0) {
context
.read<SixSceneBloc>()
.add(ToggleEnableAlarmEvent(p0));
},
isNotification: true, isNotification: true,
onTap: () {}, onTap: () {},
text: 'Offline Notification', text: 'Offline Notification',
@ -430,6 +435,7 @@ class SixSceneSettings extends StatelessWidget {
class SettingWidget extends StatelessWidget { class SettingWidget extends StatelessWidget {
final String? text; final String? text;
final bool? isUpdate; final bool? isUpdate;
final bool? value;
final bool? isNotification; final bool? isNotification;
final String? icon; final String? icon;
final Function()? onTap; final Function()? onTap;
@ -440,6 +446,7 @@ class SettingWidget extends StatelessWidget {
this.text, this.text,
this.icon, this.icon,
this.onTap, this.onTap,
this.value,
this.isUpdate, this.isUpdate,
this.onChanged, this.onChanged,
this.isNotification = false, this.isNotification = false,
@ -502,7 +509,7 @@ class SettingWidget extends StatelessWidget {
: Transform.scale( : Transform.scale(
scale: .8, scale: .8,
child: CupertinoSwitch( child: CupertinoSwitch(
value: true, value: value!,
onChanged: onChanged, onChanged: onChanged,
applyTheme: true, applyTheme: true,
), ),

View File

@ -24,22 +24,7 @@ class SixSceneScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DefaultScaffold( return BlocProvider(
title: '6 Scene Switch',
actions: [
InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SixSceneSettings(device: device!)),
);
},
child: SvgPicture.asset(Assets.assetsIconsSettings)),
const SizedBox(
width: 10,
)
],
child: BlocProvider(
create: (context) => SixSceneBloc(sixSceneId: device?.uuid ?? '') create: (context) => SixSceneBloc(sixSceneId: device?.uuid ?? '')
..add(const SixSceneInitial()) ..add(const SixSceneInitial())
..add(const SixSceneInitialInfo()) ..add(const SixSceneInitialInfo())
@ -47,6 +32,7 @@ class SixSceneScreen extends StatelessWidget {
child: BlocBuilder<SixSceneBloc, SixSceneState>( child: BlocBuilder<SixSceneBloc, SixSceneState>(
builder: (context, state) { builder: (context, state) {
final _bloc = BlocProvider.of<SixSceneBloc>(context); final _bloc = BlocProvider.of<SixSceneBloc>(context);
SixSceneModel model = SixSceneModel( SixSceneModel model = SixSceneModel(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
@ -55,19 +41,37 @@ class SixSceneScreen extends StatelessWidget {
scene_5: '', scene_5: '',
scene_6: '', scene_6: '',
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '',
);
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.device; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.device; model = state.device;
} }
return state is SixSceneLoadingState
return DefaultScaffold(
title: _bloc.deviceInfo.subspace.subspaceName,
actions: [
InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SixSceneSettings(device: device!),
),
);
},
child: SvgPicture.asset(Assets.assetsIconsSettings),
),
const SizedBox(width: 10),
],
child: state is SixSceneLoadingState
? const Center( ? const Center(
child: DefaultContainer( child: DefaultContainer(
width: 50, width: 50,
height: 50, height: 50,
child: CircularProgressIndicator()), child: CircularProgressIndicator(),
),
) )
: RefreshIndicator( : RefreshIndicator(
onRefresh: () async { onRefresh: () async {
@ -86,28 +90,22 @@ class SixSceneScreen extends StatelessWidget {
switch4Title: model.scene_4, switch4Title: model.scene_4,
switch5Title: model.scene_5, switch5Title: model.scene_5,
switch6Title: model.scene_6, switch6Title: model.scene_6,
switch1Down: switch1Down: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch1Up: switch1Up: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch2Down: switch2Down: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch2Up: switch2Up: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch3Up: switch3Up: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch3Down: switch3Down: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
onSwitch3DownTap: () { onSwitch3DownTap: () {
@ -136,7 +134,6 @@ class SixSceneScreen extends StatelessWidget {
child: DefaultContainer( child: DefaultContainer(
onTap: () { onTap: () {
_bloc.add(ChangeSwitchStatusEvent()); _bloc.add(ChangeSwitchStatusEvent());
}, },
child: Column( child: Column(
crossAxisAlignment: crossAxisAlignment:
@ -146,13 +143,13 @@ class SixSceneScreen extends StatelessWidget {
children: [ children: [
ConstrainedBox( ConstrainedBox(
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxHeight: 46, maxWidth: 50), maxHeight: 46,
maxWidth: 50,
),
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.backlightIcon), Assets.backlightIcon),
), ),
const SizedBox( const SizedBox(height: 15),
height: 15,
),
const Flexible( const Flexible(
child: FittedBox( child: FittedBox(
child: BodySmall( child: BodySmall(
@ -165,9 +162,7 @@ class SixSceneScreen extends StatelessWidget {
), ),
), ),
), ),
const SizedBox( const SizedBox(width: 10),
width: 10,
),
Expanded( Expanded(
child: DefaultContainer( child: DefaultContainer(
onTap: () async { onTap: () async {
@ -189,10 +184,10 @@ class SixSceneScreen extends StatelessWidget {
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>
SixSelectSceneFourPage( SixSelectSceneFourPage(
deviceId: deviceId: device!.uuid,
device!.uuid,
switchSelected: v, switchSelected: v,
)), ),
),
); );
}, },
); );
@ -214,13 +209,13 @@ class SixSceneScreen extends StatelessWidget {
children: [ children: [
ConstrainedBox( ConstrainedBox(
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxHeight: 46, maxWidth: 50), maxHeight: 46,
maxWidth: 50,
),
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.addSceneIcon), Assets.addSceneIcon),
), ),
const SizedBox( const SizedBox(height: 15),
height: 15,
),
const Flexible( const Flexible(
child: FittedBox( child: FittedBox(
child: BodySmall( child: BodySmall(
@ -235,16 +230,16 @@ class SixSceneScreen extends StatelessWidget {
), ),
], ],
), ),
) ),
], ],
), ),
), ),
], ],
), ),
),
); );
}, },
), ),
),
); );
} }
} }

View File

@ -24,22 +24,7 @@ class FourSceneScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DefaultScaffold( return BlocProvider(
title: '4 Scene Switch',
actions: [
InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => FourSceneSettings(device: device!)),
);
},
child: SvgPicture.asset(Assets.assetsIconsSettings)),
const SizedBox(
width: 10,
)
],
child: BlocProvider(
create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '') create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
..add(const FourSceneInitial()) ..add(const FourSceneInitial())
..add(const FourSceneInitialInfo()) ..add(const FourSceneInitialInfo())
@ -47,24 +32,44 @@ class FourSceneScreen extends StatelessWidget {
child: BlocBuilder<FourSceneBloc, FourSceneState>( child: BlocBuilder<FourSceneBloc, FourSceneState>(
builder: (context, state) { builder: (context, state) {
final _bloc = BlocProvider.of<FourSceneBloc>(context); final _bloc = BlocProvider.of<FourSceneBloc>(context);
FourSceneModelState model = FourSceneModelState( FourSceneModelState model = FourSceneModelState(
scene_1: '', scene_1: '',
scene_2: '', scene_2: '',
scene_3: '', scene_3: '',
scene_4: '', scene_4: '',
scene_id_group_id: '', scene_id_group_id: '',
switch_backlight: ''); switch_backlight: '',
);
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.device; model = state.device;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.device; model = state.device;
} }
return state is FourSceneLoadingState
return DefaultScaffold(
title: _bloc.deviceInfo.name,
actions: [
InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => FourSceneSettings(device: device!),
),
);
},
child: SvgPicture.asset(Assets.assetsIconsSettings),
),
const SizedBox(width: 10),
],
child: state is FourSceneLoadingState
? const Center( ? const Center(
child: DefaultContainer( child: DefaultContainer(
width: 50, width: 50,
height: 50, height: 50,
child: CircularProgressIndicator()), child: CircularProgressIndicator(),
),
) )
: RefreshIndicator( : RefreshIndicator(
onRefresh: () async { onRefresh: () async {
@ -81,20 +86,16 @@ class FourSceneScreen extends StatelessWidget {
title2: model.scene_2, title2: model.scene_2,
title3: model.scene_3, title3: model.scene_3,
title4: model.scene_4, title4: model.scene_4,
switch1: switch1: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch2: switch2: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch3: switch3: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
switch4: switch4: _bloc.deviceStatus.switch_backlight
_bloc.deviceStatus.switch_backlight == true
? Assets.switchOn ? Assets.switchOn
: Assets.switchOff, : Assets.switchOff,
onSwitch1UpTap: () { onSwitch1UpTap: () {
@ -126,13 +127,13 @@ class FourSceneScreen extends StatelessWidget {
children: [ children: [
ConstrainedBox( ConstrainedBox(
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxHeight: 46, maxWidth: 50), maxHeight: 46,
maxWidth: 50,
),
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.backlightIcon), Assets.backlightIcon),
), ),
const SizedBox( const SizedBox(height: 15),
height: 15,
),
const Flexible( const Flexible(
child: FittedBox( child: FittedBox(
child: BodySmall( child: BodySmall(
@ -145,9 +146,7 @@ class FourSceneScreen extends StatelessWidget {
), ),
), ),
), ),
const SizedBox( const SizedBox(width: 10),
width: 10,
),
Expanded( Expanded(
child: DefaultContainer( child: DefaultContainer(
onTap: () async { onTap: () async {
@ -162,13 +161,17 @@ class FourSceneScreen extends StatelessWidget {
cancelTab: () { cancelTab: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
confirmTab: (switchSelected) async { confirmTab:
(switchSelected) async {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>
FourSelectSceneFourPage( FourSelectSceneFourPage(
switchSelected:switchSelected, switchSelected:
deviceId: device!.uuid)), switchSelected,
deviceId: device!.uuid,
),
),
); );
}, },
); );
@ -190,13 +193,13 @@ class FourSceneScreen extends StatelessWidget {
children: [ children: [
ConstrainedBox( ConstrainedBox(
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxHeight: 46, maxWidth: 50), maxHeight: 46,
maxWidth: 50,
),
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.addSceneIcon), Assets.addSceneIcon),
), ),
const SizedBox( const SizedBox(height: 15),
height: 15,
),
const Flexible( const Flexible(
child: FittedBox( child: FittedBox(
child: BodySmall( child: BodySmall(
@ -211,19 +214,16 @@ class FourSceneScreen extends StatelessWidget {
), ),
], ],
), ),
) ),
], ],
), ),
), ),
], ],
), ),
),
); );
}, },
), ),
),
); );
} }
} }
//MohaM&&&uba1

View File

@ -69,10 +69,14 @@ class FourSceneInfoPage extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
BodySmall( Container(
width:
MediaQuery.of(context).size.width * 0.61,
child: BodySmall(
text: _bloc.deviceInfo.productUuid, text: _bloc.deviceInfo.productUuid,
fontColor: ColorsManager.primaryTextColor, fontColor: ColorsManager.primaryTextColor,
), ),
),
InkWell( InkWell(
onTap: () { onTap: () {
Clipboard.setData( Clipboard.setData(

View File

@ -144,6 +144,7 @@ class FourSceneProfilePage extends StatelessWidget {
fontSize: 12, fontSize: 12,
fontColor: ColorsManager.grayColor, fontColor: ColorsManager.grayColor,
), ),
const SizedBox(height: 7),
DefaultContainer( DefaultContainer(
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
child: InkWell( child: InkWell(

View File

@ -207,7 +207,12 @@ class FourSceneSettings extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
SettingWidget( SettingWidget(
onChanged: (p0) {}, value: _bloc.enableAlarm,
onChanged: (p0) {
context
.read<FourSceneBloc>()
.add(ToggleEnableAlarmEvent(p0));
},
isNotification: true, isNotification: true,
onTap: () {}, onTap: () {},
text: 'Offline Notification', text: 'Offline Notification',
@ -444,6 +449,7 @@ class FourSceneSettings extends StatelessWidget {
class SettingWidget extends StatelessWidget { class SettingWidget extends StatelessWidget {
final String? text; final String? text;
final bool? isUpdate; final bool? isUpdate;
final bool? value;
final bool? isNotification; final bool? isNotification;
final String? icon; final String? icon;
final Function()? onTap; final Function()? onTap;
@ -453,6 +459,7 @@ class SettingWidget extends StatelessWidget {
{super.key, {super.key,
this.text, this.text,
this.icon, this.icon,
this.value,
this.onTap, this.onTap,
this.isUpdate, this.isUpdate,
this.onChanged, this.onChanged,
@ -516,7 +523,7 @@ class SettingWidget extends StatelessWidget {
: Transform.scale( : Transform.scale(
scale: .8, scale: .8,
child: CupertinoSwitch( child: CupertinoSwitch(
value: true, value: value!,
onChanged: onChanged, onChanged: onChanged,
applyTheme: true, applyTheme: true,
), ),

View File

@ -18,45 +18,51 @@ import 'package:syncrow_app/generated/assets.dart';
class SosScreen extends StatelessWidget { class SosScreen extends StatelessWidget {
final DeviceModel? device; final DeviceModel? device;
const SosScreen({super.key, this.device}); const SosScreen({super.key, this.device});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DefaultScaffold( return BlocProvider(
title: 'SOS', create: (context) => SosBloc(sosId: device?.uuid ?? '')
actions: [ ..add(const SosInitial())
InkWell( ..add(SosInitialDeviseInfo()),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SosSettings(device: device!)),
);
},
child: SvgPicture.asset(Assets.assetsIconsSettings)),
const SizedBox(
width: 10,
)
],
child: BlocProvider(
create: (context) =>
SosBloc(sosId: device?.uuid ?? '')..add(const SosInitial()),
child: BlocBuilder<SosBloc, SosState>( child: BlocBuilder<SosBloc, SosState>(
builder: (context, state) { builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context); final sensor = BlocProvider.of<SosBloc>(context);
SosModel model = // Default SOS model in case no state is loaded
SosModel(batteryPercentage: 0, sosContactState: 'normal'); SosModel model = SosModel(
batteryPercentage: 0,
sosContactState: '',
);
// Update the model based on the state
if (state is LoadingNewSate) { if (state is LoadingNewSate) {
model = state.sosSensor; model = state.sosSensor;
} else if (state is UpdateState) { } else if (state is UpdateState) {
model = state.sensor; model = state.sensor;
} }
return state is SosLoadingState
return DefaultScaffold(
title: sensor.deviceInfo.name,
actions: [
InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SosSettings(device: device!),
),
);
},
child: SvgPicture.asset(Assets.assetsIconsSettings),
),
const SizedBox(width: 10),
],
child: state is SosLoadingState
? const Center( ? const Center(
child: DefaultContainer( child: DefaultContainer(
width: 50, width: 50,
height: 50, height: 50,
child: CircularProgressIndicator()), child: CircularProgressIndicator(),
),
) )
: RefreshIndicator( : RefreshIndicator(
onRefresh: () async { onRefresh: () async {
@ -69,14 +75,17 @@ class SosScreen extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
BatteryBar( BatteryBar(
batteryPercentage: model.batteryPercentage, batteryPercentage:
sensor.deviceStatus.batteryPercentage,
), ),
Expanded( Expanded(
flex: 4, flex: 4,
child: InkWell( child: InkWell(
overlayColor: WidgetStateProperty.all( overlayColor: MaterialStateProperty.all(
Colors.transparent), Colors.transparent),
onTap: () {}, onTap: () {
// Add functionality for the main SOS button here
},
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: crossAxisAlignment:
@ -111,7 +120,8 @@ class SosScreen extends StatelessWidget {
], ],
), ),
child: SvgPicture.asset( child: SvgPicture.asset(
model.sosContactState == 'normal' sensor.deviceStatus.sosContactState !=
'sos'
? Assets.redSos ? Assets.redSos
: Assets.greenSos, : Assets.greenSos,
fit: BoxFit.fill, fit: BoxFit.fill,
@ -131,7 +141,8 @@ class SosScreen extends StatelessWidget {
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>
SosRecordsScreen( SosRecordsScreen(
sosId: device!.uuid!)), sosId: device!.uuid!),
),
); );
}, },
child: Column( child: Column(
@ -142,13 +153,13 @@ class SosScreen extends StatelessWidget {
children: [ children: [
ConstrainedBox( ConstrainedBox(
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxHeight: 46, maxWidth: 50), maxHeight: 46,
maxWidth: 50,
),
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.doorRecordsIcon), Assets.doorRecordsIcon),
), ),
const SizedBox( const SizedBox(height: 15),
height: 15,
),
const Flexible( const Flexible(
child: FittedBox( child: FittedBox(
child: BodySmall( child: BodySmall(
@ -161,16 +172,15 @@ class SosScreen extends StatelessWidget {
), ),
), ),
), ),
const SizedBox( const SizedBox(width: 10),
width: 10,
),
Expanded( Expanded(
child: DefaultContainer( child: DefaultContainer(
onTap: () { onTap: () {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>
const AlarmManagementPage()), const AlarmManagementPage(),
),
); );
}, },
child: Column( child: Column(
@ -181,13 +191,13 @@ class SosScreen extends StatelessWidget {
children: [ children: [
ConstrainedBox( ConstrainedBox(
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxHeight: 46, maxWidth: 50), maxHeight: 46,
maxWidth: 50,
),
child: SvgPicture.asset(Assets child: SvgPicture.asset(Assets
.doorNotificationSetting), .doorNotificationSetting),
), ),
const SizedBox( const SizedBox(height: 15),
height: 15,
),
const Flexible( const Flexible(
child: FittedBox( child: FittedBox(
child: BodySmall( child: BodySmall(
@ -202,16 +212,16 @@ class SosScreen extends StatelessWidget {
), ),
], ],
), ),
) ),
], ],
), ),
), ),
], ],
), ),
),
); );
}, },
), ),
),
); );
} }
} }

View File

@ -64,10 +64,14 @@ class SosInfoPage extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
BodySmall( SizedBox(
width:
MediaQuery.of(context).size.width * 0.61,
child: BodySmall(
text: _bloc.deviceInfo.productUuid, text: _bloc.deviceInfo.productUuid,
fontColor: ColorsManager.primaryTextColor, fontColor: ColorsManager.primaryTextColor,
), ),
),
InkWell( InkWell(
onTap: () { onTap: () {
Clipboard.setData( Clipboard.setData(

View File

@ -64,21 +64,12 @@ class SosProfilePage extends StatelessWidget {
radius: 55, radius: 55,
backgroundColor: ColorsManager.graysColor, backgroundColor: ColorsManager.graysColor,
child: ClipOval( child: ClipOval(
child: Column( child: Center(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: 10,
),
Center(
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.fourSceneIcon, Assets.sosProfileIcon,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
],
),
), ),
), ),
), ),
@ -139,6 +130,7 @@ class SosProfilePage extends StatelessWidget {
fontSize: 12, fontSize: 12,
fontColor: ColorsManager.grayColor, fontColor: ColorsManager.grayColor,
), ),
const SizedBox(height: 7),
DefaultContainer( DefaultContainer(
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
child: InkWell( child: InkWell(

View File

@ -7,7 +7,6 @@ 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/bloc/sos_bloc/sos_state.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/sos_model.dart'; import 'package:syncrow_app/features/devices/model/sos_model.dart';
import 'package:syncrow_app/features/devices/model/subspace_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/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/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/faq_sos_page.dart';
@ -62,14 +61,18 @@ class SosSettings extends StatelessWidget {
vertical: 10, vertical: 10,
), ),
child: InkWell( child: InkWell(
onTap: () { onTap: () async {
Navigator.of(context).push( bool val = await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => SosProfilePage( builder: (context) => SosProfilePage(
device: device, device: device,
), ),
), ),
); );
if (val == true) {
_bloc.add(SosInitialDeviseInfo());
_bloc.add(const SosInitial());
}
}, },
child: Stack( child: Stack(
children: [ children: [
@ -93,8 +96,8 @@ class SosSettings extends StatelessWidget {
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.start, CrossAxisAlignment.start,
children: [ children: [
const BodyMedium( BodyMedium(
text: 'SOS', text: _bloc.deviceInfo.name,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
const SizedBox( const SizedBox(
@ -169,7 +172,21 @@ class SosSettings extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
SettingWidget( SettingWidget(
onChanged: (p0) {}, value: _bloc.enableAlarm,
onChanged: (p0) {
context
.read<SosBloc>()
.add(ToggleEnableAlarmEvent(p0));
// Transform.scale(
// scale: .8,
// child: CupertinoSwitch(
// value: _bloc.enableAlarm,
// onChanged: (value) {
// },
// applyTheme: true,
// )),
},
isNotification: true, isNotification: true,
onTap: () {}, onTap: () {},
text: 'Offline Notification', text: 'Offline Notification',
@ -400,6 +417,7 @@ class SosSettings extends StatelessWidget {
class SettingWidget extends StatelessWidget { class SettingWidget extends StatelessWidget {
final String? text; final String? text;
final bool? isUpdate; final bool? isUpdate;
final bool? value;
final bool? isNotification; final bool? isNotification;
final String? icon; final String? icon;
final Function()? onTap; final Function()? onTap;
@ -409,6 +427,7 @@ class SettingWidget extends StatelessWidget {
{super.key, {super.key,
this.text, this.text,
this.icon, this.icon,
this.value,
this.onTap, this.onTap,
this.isUpdate, this.isUpdate,
this.onChanged, this.onChanged,
@ -472,7 +491,7 @@ class SettingWidget extends StatelessWidget {
: Transform.scale( : Transform.scale(
scale: .8, scale: .8,
child: CupertinoSwitch( child: CupertinoSwitch(
value: true, value: value!,
onChanged: onChanged, onChanged: onChanged,
applyTheme: true, applyTheme: true,
), ),