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,7 +28,15 @@ class SettingsPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DefaultScaffold( return PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (didPop) {
return;
}
Navigator.of(context).pop(true);
},
child: DefaultScaffold(
title: 'Device Settings', title: 'Device Settings',
child: BlocProvider( child: BlocProvider(
create: (context) => DeviceSettingBloc(deviceId: device?.uuid ?? '') create: (context) => DeviceSettingBloc(deviceId: device?.uuid ?? '')
@ -40,8 +48,10 @@ class SettingsPage extends StatelessWidget {
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,
child: CircularProgressIndicator()),
) )
: ListView( : ListView(
children: [ children: [
@ -65,29 +75,36 @@ class SettingsPage extends StatelessWidget {
child: Stack( child: Stack(
children: [ children: [
Column( Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [ children: [
const SizedBox(height: 20), const SizedBox(height: 20),
DefaultContainer( DefaultContainer(
borderRadius: const BorderRadius.all(Radius.circular(30)), borderRadius: const BorderRadius.all(
Radius.circular(30)),
child: Padding( child: Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Padding( child: Padding(
padding: const EdgeInsets.only(left: 90), padding:
const EdgeInsets.only(left: 90),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
Expanded( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment:
CrossAxisAlignment.start,
children: [ children: [
SizedBox( SizedBox(
child: Text( child: Text(
_bloc.deviceInfo.name, _bloc.deviceInfo.name,
style: const TextStyle( style: const TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w700, fontWeight:
color: ColorsManager.grayColor, FontWeight.w700,
color: ColorsManager
.grayColor,
), ),
overflow: TextOverflow overflow: TextOverflow
.ellipsis, // Adds ellipsis (...) when the text overflows. .ellipsis, // Adds ellipsis (...) when the text overflows.
@ -98,7 +115,10 @@ class SettingsPage extends StatelessWidget {
height: 5, height: 5,
), ),
BodySmall( BodySmall(
text: _bloc.deviceInfo.subspace.subspaceName), text: _bloc
.deviceInfo
.subspace
.subspaceName),
], ],
), ),
), ),
@ -125,10 +145,13 @@ class SettingsPage extends StatelessWidget {
backgroundColor: Colors.white, backgroundColor: Colors.white,
child: CircleAvatar( child: CircleAvatar(
radius: 40, radius: 40,
backgroundColor: ColorsManager.backgroundColor, backgroundColor:
ColorsManager.backgroundColor,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment:
mainAxisAlignment: MainAxisAlignment.center, CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [ children: [
device!.type == 'NCPS' device!.type == 'NCPS'
? SizedBox( ? SizedBox(
@ -138,26 +161,36 @@ class SettingsPage extends StatelessWidget {
Assets.flushIcon, Assets.flushIcon,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
): )
device!.type == "SOS" : device!.type == "SOS"
? ClipOval( ? ClipOval(
child: SvgPicture.asset( child:
SvgPicture.asset(
Assets.sosHomeIcon, Assets.sosHomeIcon,
fit: BoxFit.contain, fit: BoxFit.contain,
height: 70, height: 70,
), ),
) )
: Padding( : Padding(
padding: device!.type == "4S" padding: device!
? const EdgeInsets.only(top: 5) .type ==
: const EdgeInsets.only(top: 0), "4S"
? const EdgeInsets
.only(top: 5)
: const EdgeInsets
.only(top: 0),
child: SizedBox( child: SizedBox(
height: 70, height: 70,
child: SvgPicture.asset( child: SvgPicture
device!.type == "4S" .asset(
? Assets.fourSceneIcon device!.type ==
: Assets.sixSceneIcon, "4S"
fit: BoxFit.contain, ? Assets
.fourSceneIcon
: Assets
.sixSceneIcon,
fit: BoxFit
.contain,
), ),
), ),
), ),
@ -346,7 +379,8 @@ class SettingsPage extends StatelessWidget {
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
InkWell( InkWell(
onTap: () { onTap: () {
@ -355,10 +389,12 @@ class SettingsPage extends StatelessWidget {
builder: (context) { builder: (context) {
return DisconnectDeviceDialog( return DisconnectDeviceDialog(
cancelTab: () { cancelTab: () {
Navigator.of(context).pop(); Navigator.of(context)
.pop();
}, },
confirmTab: () { confirmTab: () {
Navigator.of(context).pop(); Navigator.of(context)
.pop();
}, },
); );
}, },
@ -368,7 +404,8 @@ class SettingsPage extends StatelessWidget {
text: 'Disconnect Device', text: 'Disconnect Device',
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
fontSize: 15, fontSize: 15,
fontColor: ColorsManager.textPrimaryColor, fontColor: ColorsManager
.textPrimaryColor,
), ),
), ),
const Icon( const Icon(
@ -379,7 +416,8 @@ class SettingsPage extends StatelessWidget {
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
InkWell( InkWell(
onTap: () { onTap: () {
@ -388,20 +426,24 @@ class SettingsPage extends StatelessWidget {
builder: (context) { builder: (context) {
return DisconnectWipeData( return DisconnectWipeData(
cancelTab: () { cancelTab: () {
Navigator.of(context).pop(); Navigator.of(context)
.pop();
}, },
confirmTab: () { confirmTab: () {
_bloc.add(DeleteDeviceEvent()); _bloc.add(
DeleteDeviceEvent());
}, },
); );
}, },
); );
}, },
child: const BodyMedium( child: const BodyMedium(
text: 'Disconnect Device and Wipe Data', text:
'Disconnect Device and Wipe Data',
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
fontSize: 15, fontSize: 15,
fontColor: ColorsManager.textPrimaryColor, fontColor: ColorsManager
.textPrimaryColor,
), ),
), ),
const Icon( const Icon(
@ -430,6 +472,7 @@ class SettingsPage extends StatelessWidget {
}, },
), ),
), ),
),
); );
} }
} }

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,7 +130,8 @@ class SosScreen extends StatelessWidget {
onTap: () { onTap: () {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => SosRecordsScreen( builder: (context) =>
SosRecordsScreen(
sosId: device!.uuid!), 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(