Merge pull request #104 from SyncrowIOT/fix-back-button-status

Refactor screen titles to use bloc device info
This commit is contained in:
mohammadnemer1
2025-05-19 11:06:57 +03:00
committed by GitHub
4 changed files with 458 additions and 410 deletions

View File

@ -28,406 +28,449 @@ class SettingsPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DefaultScaffold( return PopScope(
title: 'Device Settings', canPop: false,
child: BlocProvider( onPopInvoked: (didPop) {
create: (context) => DeviceSettingBloc(deviceId: device?.uuid ?? '') if (didPop) {
..add(const DeviceSettingInitial()) return;
..add(const DeviceSettingInitialInfo()), }
child: BlocBuilder<DeviceSettingBloc, DeviceSettingState>( Navigator.of(context).pop(true);
builder: (context, state) { },
final _bloc = BlocProvider.of<DeviceSettingBloc>(context); child: DefaultScaffold(
title: 'Device Settings',
child: BlocProvider(
create: (context) => DeviceSettingBloc(deviceId: device?.uuid ?? '')
..add(const DeviceSettingInitial())
..add(const DeviceSettingInitialInfo()),
child: BlocBuilder<DeviceSettingBloc, DeviceSettingState>(
builder: (context, state) {
final _bloc = BlocProvider.of<DeviceSettingBloc>(context);
return state is DeviceSettingLoadingState return state is DeviceSettingLoadingState
? const Center( ? const Center(
child: child: DefaultContainer(
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()), width: 50,
) height: 50,
: ListView( child: CircularProgressIndicator()),
children: [ )
Padding( : ListView(
padding: const EdgeInsets.symmetric( children: [
vertical: 10, Padding(
), padding: const EdgeInsets.symmetric(
child: InkWell( vertical: 10,
onTap: () async {
bool val = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SettingProfilePage(
device: device,
),
),
);
if (val == true) {
_bloc.add(const DeviceSettingInitialInfo());
}
},
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: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
child: Text(
_bloc.deviceInfo.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: ColorsManager.grayColor,
),
overflow: TextOverflow
.ellipsis, // Adds ellipsis (...) when the text overflows.
maxLines:
1, // Restricts the text to a single line.
)),
const SizedBox(
height: 5,
),
BodySmall(
text: _bloc.deviceInfo.subspace.subspaceName),
],
),
),
SvgPicture.asset(
Assets.editNameSetting,
fit: BoxFit.contain,
height: 30,
),
],
),
),
),
),
],
),
Positioned(
top: 0,
left: 20,
child: CircleAvatar(
radius: 43,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 40,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 40,
backgroundColor: ColorsManager.backgroundColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
device!.type == 'NCPS'
? SizedBox(
height: 80,
width: 50,
child: SvgPicture.asset(
Assets.flushIcon,
fit: BoxFit.contain,
),
):
device!.type == "SOS"
? ClipOval(
child: SvgPicture.asset(
Assets.sosHomeIcon,
fit: BoxFit.contain,
height: 70,
),
)
: Padding(
padding: device!.type == "4S"
? const EdgeInsets.only(top: 5)
: const EdgeInsets.only(top: 0),
child: SizedBox(
height: 70,
child: SvgPicture.asset(
device!.type == "4S"
? Assets.fourSceneIcon
: Assets.sixSceneIcon,
fit: BoxFit.contain,
),
),
),
],
),
),
)),
),
],
), ),
), child: InkWell(
), onTap: () async {
const SizedBox(height: 20), bool val = await Navigator.of(context).push(
const BodyMedium( MaterialPageRoute(
text: 'Device Management', builder: (context) => SettingProfilePage(
fontWeight: FontWeight.w700, device: device,
fontSize: 12, ),
fontColor: ColorsManager.grayColor, ),
), );
DefaultContainer( if (val == true) {
child: Column( _bloc.add(const DeviceSettingInitialInfo());
children: [ }
SettingWidget( },
onTap: () { child: Stack(
Navigator.of(context).push( children: [
MaterialPageRoute( Column(
builder: (context) => SettingInfoPage( crossAxisAlignment:
device: device!, CrossAxisAlignment.stretch,
)),
);
},
text: 'Device Information',
icon: Assets.infoIcon,
),
// const Divider(
// color: ColorsManager.dividerColor,
// ),
// SettingWidget(
// onTap: () {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) =>
// ShareFourScenePage(
// device: device!)),
// );
// },
// text: 'Tap-to Run and Automation',
// icon: Assets.tapRunIcon,
// ),
],
),
),
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<DeviceSettingBloc>()
// .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) =>
// ShareDevicePage(device: device!)),
// );
// },
// text: 'Share Device',
// icon: Assets.shareIcon,
// ),
// // const Divider(
// // color: ColorsManager.dividerColor,
// // ),
// // SettingWidget(
// // onTap: () {
// // Navigator.of(context).push(
// // MaterialPageRoute(
// // builder: (context) =>
// // FourSceneCreateGroup(
// // device: device!)),
// // );
// // },
// // text: 'Create Group',
// // icon: Assets.createGroupIcon,
// // ),
// const Divider(
// color: ColorsManager.dividerColor,
// ),
// SettingWidget(
// onTap: () {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) =>
// FaqSettingPage(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: () {
// Navigator.of(context).pop();
// },
// );
// },
// );
// },
// isUpdate: true,
// onTap: () {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) =>
// const UpdatePageSetting()),
// );
// },
// 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: [ 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: () {
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), const SizedBox(height: 20),
Row( DefaultContainer(
mainAxisAlignment: MainAxisAlignment.spaceBetween, borderRadius: const BorderRadius.all(
children: [ Radius.circular(30)),
InkWell( child: Padding(
onTap: () { padding: const EdgeInsets.all(10.0),
showDialog( child: Padding(
context: context, padding:
builder: (context) { const EdgeInsets.only(left: 90),
return DisconnectWipeData( child: Row(
cancelTab: () { mainAxisAlignment:
Navigator.of(context).pop(); MainAxisAlignment.spaceBetween,
}, children: [
confirmTab: () { Expanded(
_bloc.add(DeleteDeviceEvent()); child: Column(
}, crossAxisAlignment:
); CrossAxisAlignment.start,
}, children: [
); SizedBox(
}, child: Text(
child: const BodyMedium( _bloc.deviceInfo.name,
text: 'Disconnect Device and Wipe Data', style: const TextStyle(
fontWeight: FontWeight.w400, fontSize: 16,
fontSize: 15, fontWeight:
fontColor: ColorsManager.textPrimaryColor, FontWeight.w700,
color: ColorsManager
.grayColor,
),
overflow: TextOverflow
.ellipsis, // Adds ellipsis (...) when the text overflows.
maxLines:
1, // Restricts the text to a single line.
)),
const SizedBox(
height: 5,
),
BodySmall(
text: _bloc
.deviceInfo
.subspace
.subspaceName),
],
),
),
SvgPicture.asset(
Assets.editNameSetting,
fit: BoxFit.contain,
height: 30,
),
],
), ),
), ),
const Icon( ),
Icons.keyboard_arrow_right,
color: ColorsManager.textGray,
)
],
), ),
], ],
), ),
); Positioned(
}, top: 0,
); left: 20,
}, child: CircleAvatar(
child: const Center( radius: 43,
child: BodyMedium( backgroundColor: Colors.white,
text: 'Remove Device', child: CircleAvatar(
fontWeight: FontWeight.w400, radius: 40,
fontSize: 15, backgroundColor: Colors.white,
fontColor: ColorsManager.red, child: CircleAvatar(
radius: 40,
backgroundColor:
ColorsManager.backgroundColor,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
device!.type == 'NCPS'
? SizedBox(
height: 80,
width: 50,
child: SvgPicture.asset(
Assets.flushIcon,
fit: BoxFit.contain,
),
)
: device!.type == "SOS"
? ClipOval(
child:
SvgPicture.asset(
Assets.sosHomeIcon,
fit: BoxFit.contain,
height: 70,
),
)
: Padding(
padding: device!
.type ==
"4S"
? const EdgeInsets
.only(top: 5)
: const EdgeInsets
.only(top: 0),
child: SizedBox(
height: 70,
child: SvgPicture
.asset(
device!.type ==
"4S"
? Assets
.fourSceneIcon
: Assets
.sixSceneIcon,
fit: BoxFit
.contain,
),
),
),
],
),
),
)),
),
],
),
), ),
), ),
), const SizedBox(height: 20),
], const BodyMedium(
); text: 'Device Management',
}, fontWeight: FontWeight.w700,
fontSize: 12,
fontColor: ColorsManager.grayColor,
),
DefaultContainer(
child: Column(
children: [
SettingWidget(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SettingInfoPage(
device: device!,
)),
);
},
text: 'Device Information',
icon: Assets.infoIcon,
),
// const Divider(
// color: ColorsManager.dividerColor,
// ),
// SettingWidget(
// onTap: () {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) =>
// ShareFourScenePage(
// device: device!)),
// );
// },
// text: 'Tap-to Run and Automation',
// icon: Assets.tapRunIcon,
// ),
],
),
),
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<DeviceSettingBloc>()
// .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) =>
// ShareDevicePage(device: device!)),
// );
// },
// text: 'Share Device',
// icon: Assets.shareIcon,
// ),
// // const Divider(
// // color: ColorsManager.dividerColor,
// // ),
// // SettingWidget(
// // onTap: () {
// // Navigator.of(context).push(
// // MaterialPageRoute(
// // builder: (context) =>
// // FourSceneCreateGroup(
// // device: device!)),
// // );
// // },
// // text: 'Create Group',
// // icon: Assets.createGroupIcon,
// // ),
// const Divider(
// color: ColorsManager.dividerColor,
// ),
// SettingWidget(
// onTap: () {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) =>
// FaqSettingPage(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: () {
// Navigator.of(context).pop();
// },
// );
// },
// );
// },
// isUpdate: true,
// onTap: () {
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (context) =>
// const UpdatePageSetting()),
// );
// },
// 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: () {
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: () {
_bloc.add(
DeleteDeviceEvent());
},
);
},
);
},
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,
),
),
),
],
);
},
),
), ),
), ),
); );

View File

@ -46,7 +46,7 @@ class SixSceneScreen extends StatelessWidget {
model = state.device; model = state.device;
} }
return DefaultScaffold( return DefaultScaffold(
title: device?.name ?? '6 Scene Switch', title: bloc.deviceInfo.name ,
actions: [ actions: [
InkWell( InkWell(
onTap: () async { onTap: () async {
@ -55,7 +55,7 @@ class SixSceneScreen extends StatelessWidget {
builder: (context) => SettingsPage(device: device!), builder: (context) => SettingsPage(device: device!),
), ),
); );
if (val == null) { if (val == null || val == true) {
bloc.add(const SixSceneInitialInfo()); bloc.add(const SixSceneInitialInfo());
bloc.add(const SixSceneInitial()); bloc.add(const SixSceneInitial());
bloc.add(const SexSceneSwitchInitial()); bloc.add(const SexSceneSwitchInitial());
@ -195,8 +195,8 @@ class SixSceneScreen extends StatelessWidget {
); );
if (value == true) { if (value == true) {
Future.delayed( Future.delayed(
const Duration(milliseconds: 200), const Duration(
() { milliseconds: 200), () {
bloc.add( bloc.add(
const SexSceneSwitchInitial()); const SexSceneSwitchInitial());
}); });

View File

@ -47,7 +47,7 @@ class FourSceneScreen extends StatelessWidget {
} }
return DefaultScaffold( return DefaultScaffold(
title: device?.name ?? '4 Scene', title: _bloc.deviceInfo.name,
actions: [ actions: [
InkWell( InkWell(
onTap: () async { onTap: () async {
@ -56,7 +56,7 @@ class FourSceneScreen extends StatelessWidget {
builder: (context) => SettingsPage(device: device!), builder: (context) => SettingsPage(device: device!),
), ),
); );
if (val == null) { if (val == null || val == true) {
_bloc.add(const FourSceneInitial()); _bloc.add(const FourSceneInitial());
_bloc.add(const FourSceneInitialInfo()); _bloc.add(const FourSceneInitialInfo());
_bloc.add(const FourSceneSwitchInitial()); _bloc.add(const FourSceneSwitchInitial());
@ -164,8 +164,7 @@ class FourSceneScreen extends StatelessWidget {
cancelTab: () { cancelTab: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
confirmTab: confirmTab: (switchSelected) {
(switchSelected) {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>

View File

@ -29,7 +29,7 @@ class SosScreen extends StatelessWidget {
builder: (context, state) { builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context); final sensor = BlocProvider.of<SosBloc>(context);
return DefaultScaffold( return DefaultScaffold(
title: device?.name, title: sensor.deviceInfo.name,
actions: [ actions: [
InkWell( InkWell(
onTap: () async { onTap: () async {
@ -38,7 +38,7 @@ class SosScreen extends StatelessWidget {
builder: (context) => SettingsPage(device: device!), builder: (context) => SettingsPage(device: device!),
), ),
); );
if (val == null) { if (val == null || val == true) {
sensor.add(SosInitialDeviseInfo()); sensor.add(SosInitialDeviseInfo());
sensor.add(const SosInitial()); sensor.add(const SosInitial());
} }
@ -72,33 +72,38 @@ class SosScreen extends StatelessWidget {
Expanded( Expanded(
flex: 4, flex: 4,
child: InkWell( child: InkWell(
overlayColor: overlayColor: WidgetStateProperty.all(
WidgetStateProperty.all(Colors.transparent), Colors.transparent),
onTap: () { onTap: () {
// Add functionality for the main SOS button here // Add functionality for the main SOS button here
}, },
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment:
CrossAxisAlignment.center,
children: [ children: [
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(890), borderRadius:
BorderRadius.circular(890),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.white.withOpacity(0.1), color:
Colors.white.withOpacity(0.1),
blurRadius: 24, blurRadius: 24,
offset: const Offset(-5, -5), offset: const Offset(-5, -5),
blurStyle: BlurStyle.outer, blurStyle: BlurStyle.outer,
), ),
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.11), color: Colors.black
.withOpacity(0.11),
blurRadius: 25, blurRadius: 25,
offset: const Offset(5, 5), offset: const Offset(5, 5),
blurStyle: BlurStyle.outer, blurStyle: BlurStyle.outer,
), ),
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.13), color: Colors.black
.withOpacity(0.13),
blurRadius: 30, blurRadius: 30,
offset: const Offset(5, 5), offset: const Offset(5, 5),
blurStyle: BlurStyle.inner, blurStyle: BlurStyle.inner,
@ -125,8 +130,9 @@ class SosScreen extends StatelessWidget {
onTap: () { onTap: () {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => SosRecordsScreen( builder: (context) =>
sosId: device!.uuid!), SosRecordsScreen(
sosId: device!.uuid!),
), ),
); );
}, },
@ -181,8 +187,8 @@ class SosScreen extends StatelessWidget {
maxHeight: 46, maxHeight: 46,
maxWidth: 50, maxWidth: 50,
), ),
child: SvgPicture.asset( child: SvgPicture.asset(Assets
Assets.doorNotificationSetting), .doorNotificationSetting),
), ),
const SizedBox(height: 15), const SizedBox(height: 15),
const Flexible( const Flexible(