This commit is contained in:
mohammad
2024-11-14 10:23:00 +03:00
parent 6920d9129e
commit 48327fbbe5
9 changed files with 16 additions and 15 deletions

View File

@ -42,7 +42,7 @@ class SosBloc extends Bloc<SosEvent, SosState> {
bool closingReminder = false;
bool waterAlarm = false;
SosModel deviceStatus =
SosModel(waterContactState: 'normal', batteryPercentage: 0);
SosModel(sosContactState: 'normal', batteryPercentage: 0);
void _fetchStatus(SosInitial event, Emitter<SosState> emit) async {
emit(SosLoadingState());

View File

@ -1,27 +1,27 @@
import 'package:syncrow_app/features/devices/model/status_model.dart';
class SosModel {
String waterContactState;
String sosContactState;
int batteryPercentage;
SosModel({
required this.waterContactState,
required this.sosContactState,
required this.batteryPercentage,
});
factory SosModel.fromJson(List<StatusModel> jsonList) {
late String _waterContactState;
late String _sosContactState;
late int _batteryPercentage;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'sossensor_state') {
_waterContactState = jsonList[i].value ?? false;
if (jsonList[i].code == 'sos') {
_sosContactState = jsonList[i].value ?? '';
} else if (jsonList[i].code == 'battery_percentage') {
_batteryPercentage = jsonList[i].value ?? 0;
}
}
return SosModel(
waterContactState: _waterContactState,
sosContactState: _sosContactState,
batteryPercentage: _batteryPercentage,
);
}

View File

@ -44,7 +44,7 @@ class SosScreen extends StatelessWidget {
builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context);
SosModel model =
SosModel(batteryPercentage: 0, waterContactState: 'normal');
SosModel(batteryPercentage: 0, sosContactState: 'normal');
if (state is LoadingNewSate) {
model = state.sosSensor;
} else if (state is UpdateState) {
@ -68,6 +68,7 @@ class SosScreen extends StatelessWidget {
child: Column(
children: [
BatteryBar(
batteryPercentage: model.batteryPercentage,
),
Expanded(
@ -110,7 +111,7 @@ class SosScreen extends StatelessWidget {
],
),
child: SvgPicture.asset(
model.waterContactState == 'normal'
model.sosContactState == 'normal'
? Assets.redSos
: Assets.greenSos,
fit: BoxFit.fill,

View File

@ -26,7 +26,7 @@ class LocationSosPage extends StatelessWidget {
builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context);
SosModel model =
SosModel(batteryPercentage: 0, waterContactState: 'normal');
SosModel(batteryPercentage: 0, sosContactState: 'normal');
return state is SosLoadingState
? const Center(

View File

@ -29,7 +29,7 @@ class QuestionPage extends StatelessWidget {
builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context);
SosModel model =
SosModel(batteryPercentage: 0, waterContactState: 'normal');
SosModel(batteryPercentage: 0, sosContactState: 'normal');
if (state is LoadingNewSate) {
model = state.sosSensor;
} else if (state is UpdateState) {

View File

@ -28,7 +28,7 @@ class ShareSosPage extends StatelessWidget {
builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context);
SosModel model =
SosModel(batteryPercentage: 0, waterContactState: 'normal');
SosModel(batteryPercentage: 0, sosContactState: 'normal');
if (state is LoadingNewSate) {
model = state.sosSensor;
} else if (state is UpdateState) {

View File

@ -28,7 +28,7 @@ class SosInfoPge extends StatelessWidget {
builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context);
SosModel model =
SosModel(batteryPercentage: 0, waterContactState: 'normal');
SosModel(batteryPercentage: 0, sosContactState: 'normal');
if (state is LoadingNewSate) {
model = state.sosSensor;
} else if (state is UpdateState) {

View File

@ -32,7 +32,7 @@ class SosProfilePage extends StatelessWidget {
builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context);
SosModel model =
SosModel(batteryPercentage: 0, waterContactState: 'normal');
SosModel(batteryPercentage: 0, sosContactState: 'normal');
if (state is LoadingNewSate) {
model = state.sosSensor;
} else if (state is UpdateState) {

View File

@ -37,7 +37,7 @@ class SosSettings extends StatelessWidget {
builder: (context, state) {
final sensor = BlocProvider.of<SosBloc>(context);
SosModel model =
SosModel(batteryPercentage: 0, waterContactState: 'normal');
SosModel(batteryPercentage: 0, sosContactState: 'normal');
if (state is LoadingNewSate) {
model = state.sosSensor;
} else if (state is UpdateState) {