mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-17 02:25:16 +00:00
water leak
This commit is contained in:
3
assets/icons/leak_detected.svg
Normal file
3
assets/icons/leak_detected.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="7.5" cy="7.5" r="5" stroke="#FF4756" stroke-width="5"/>
|
||||
</svg>
|
After Width: | Height: | Size: 171 B |
3
assets/icons/leak_normal_icon.svg
Normal file
3
assets/icons/leak_normal_icon.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="7.5" cy="7.5" r="5" stroke="#023DFE" stroke-opacity="0.6" stroke-width="5"/>
|
||||
</svg>
|
After Width: | Height: | Size: 192 B |
@ -28,7 +28,7 @@ class WaterLeakBloc extends Bloc<WaterLeakEvent, WaterLeakState> {
|
||||
bool closingReminder = false;
|
||||
bool waterAlarm = false;
|
||||
WaterLeakModel deviceStatus =
|
||||
WaterLeakModel(waterContactState: false, batteryPercentage: 0);
|
||||
WaterLeakModel(waterContactState: 'normal', batteryPercentage: 0);
|
||||
|
||||
void _fetchStatus(
|
||||
WaterLeakInitial event, Emitter<WaterLeakState> emit) async {
|
||||
@ -43,6 +43,7 @@ class WaterLeakBloc extends Bloc<WaterLeakEvent, WaterLeakState> {
|
||||
statusModelList,
|
||||
);
|
||||
emit(UpdateState(waterSensor: deviceStatus));
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
_listenToChanges();
|
||||
} catch (e) {
|
||||
@ -115,39 +116,32 @@ class WaterLeakBloc extends Bloc<WaterLeakEvent, WaterLeakState> {
|
||||
}
|
||||
}
|
||||
|
||||
DeviceReport recordGroups = DeviceReport(
|
||||
startTime: '0',
|
||||
endTime: '0',
|
||||
data: [DeviceEvent(code: '111', eventTime: 23456789, value: 'tyuio')]);
|
||||
DeviceReport recordGroups =
|
||||
DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||
|
||||
Future<void> fetchLogsForLastMonth(
|
||||
ReportLogsInitial event, Emitter<WaterLeakState> emit) async {
|
||||
// Get the current date and time
|
||||
DateTime now = DateTime.now();
|
||||
|
||||
// Calculate the date one month ago
|
||||
DateTime lastMonth = DateTime(now.year, now.month - 1, now.day);
|
||||
|
||||
// Convert the date to milliseconds since epoch (Unix timestamp in milliseconds)
|
||||
int startTime = lastMonth.millisecondsSinceEpoch;
|
||||
int endTime = now.millisecondsSinceEpoch;
|
||||
try {
|
||||
emit(WaterLeakLoadingState());
|
||||
// var response = await DevicesAPI.getReportLogs(
|
||||
// startTime:
|
||||
// startTime.toString(), // Convert to String if the API expects it
|
||||
// endTime: endTime.toString(), // Convert to String if the API expects it
|
||||
// deviceUuid: WLId,
|
||||
// code: 'watercontact_state',
|
||||
// );
|
||||
// print('response======${response}');
|
||||
// recordGroups = response;
|
||||
// Process response here
|
||||
var response = await DevicesAPI.getReportLogs(
|
||||
startTime: startTime.toString(),
|
||||
endTime: endTime.toString(),
|
||||
deviceUuid: WLId,
|
||||
code: 'watercontact_state',
|
||||
);
|
||||
recordGroups = response;
|
||||
emit(UpdateState(waterSensor: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['message'];
|
||||
// Handle error
|
||||
emit(WaterLeakFailedState(errorMessage: errorMessage));
|
||||
|
||||
print('Error fetching logs: ${errorMessage}');
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ abstract class WaterLeakEvent extends Equatable {
|
||||
class WaterLeakLoading extends WaterLeakEvent {}
|
||||
|
||||
class WaterLeakSwitch extends WaterLeakEvent {
|
||||
final bool switchD;
|
||||
final String switchD;
|
||||
final String deviceId;
|
||||
final String productId;
|
||||
const WaterLeakSwitch({required this.switchD, this.deviceId = '', this.productId = ''});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
|
||||
class WaterLeakModel {
|
||||
bool waterContactState;
|
||||
String waterContactState;
|
||||
int batteryPercentage;
|
||||
|
||||
WaterLeakModel({
|
||||
@ -10,7 +10,7 @@ class WaterLeakModel {
|
||||
});
|
||||
|
||||
factory WaterLeakModel.fromJson(List<StatusModel> jsonList) {
|
||||
late bool _waterContactState;
|
||||
late String _waterContactState;
|
||||
late int _batteryPercentage;
|
||||
|
||||
for (int i = 0; i < jsonList.length; i++) {
|
||||
|
@ -8,6 +8,7 @@ import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_sta
|
||||
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_large.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class NotificationSettingsPage extends StatelessWidget {
|
||||
@ -32,6 +33,8 @@ class NotificationSettingsPage extends StatelessWidget {
|
||||
: Column(
|
||||
children: [
|
||||
DefaultContainer(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10, right: 10),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@ -41,9 +44,10 @@ class NotificationSettingsPage extends StatelessWidget {
|
||||
height: 50,
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const BodyLarge(
|
||||
leading: const BodyMedium(
|
||||
text: 'Low Battery Alarm',
|
||||
fontWeight: FontWeight.normal,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 15,
|
||||
),
|
||||
trailing: Transform.scale(
|
||||
scale: .8,
|
||||
@ -66,7 +70,8 @@ class NotificationSettingsPage extends StatelessWidget {
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const BodyLarge(
|
||||
text: 'Water Leakage Alarm',
|
||||
fontWeight: FontWeight.normal,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 15,
|
||||
),
|
||||
trailing: Transform.scale(
|
||||
scale: .8,
|
||||
@ -84,6 +89,7 @@ class NotificationSettingsPage extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_event.dart';
|
||||
@ -8,20 +9,28 @@ import 'package:syncrow_app/features/devices/model/device_report_model.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_small.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
class WaterLeakRecordsScreen extends StatefulWidget {
|
||||
final String WLId;
|
||||
const WaterLeakRecordsScreen({super.key, required this.WLId});
|
||||
|
||||
@override
|
||||
State<WaterLeakRecordsScreen> createState() => _WaterLeakRecordsScreenState();
|
||||
}
|
||||
|
||||
class _WaterLeakRecordsScreenState extends State<WaterLeakRecordsScreen> {
|
||||
int _selectedIndex = 0; // Track the selected tab index
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultScaffold(
|
||||
title: 'Records',
|
||||
child: BlocProvider(
|
||||
create: (context) =>
|
||||
WaterLeakBloc(WLId: WLId ?? '')..add(const ReportLogsInitial()),
|
||||
WaterLeakBloc(WLId: widget.WLId)..add(const ReportLogsInitial()),
|
||||
child: BlocBuilder<WaterLeakBloc, WaterLeakState>(
|
||||
builder: (context, state) {
|
||||
final waterSensorBloc = BlocProvider.of<WaterLeakBloc>(context);
|
||||
@ -33,16 +42,12 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
);
|
||||
} else if (state is UpdateState) {
|
||||
// Group records by formatted date
|
||||
|
||||
// Iterate over the data list in DeviceReport
|
||||
for (var record in waterSensorBloc.recordGroups.data!) {
|
||||
final DateTime eventDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(record.eventTime!);
|
||||
final String formattedDate =
|
||||
DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime);
|
||||
|
||||
// Group by formatted date
|
||||
if (groupedRecords.containsKey(formattedDate)) {
|
||||
groupedRecords[formattedDate]!.add(record);
|
||||
} else {
|
||||
@ -50,8 +55,8 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DefaultTabController(
|
||||
// Wrap with DefaultTabController
|
||||
length: 2,
|
||||
child: Column(
|
||||
children: [
|
||||
@ -65,18 +70,11 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
),
|
||||
child: TabBar(
|
||||
onTap: (value) {
|
||||
// if (value == 0) {
|
||||
// if (oneTouchBloc.createSchedule == true) {
|
||||
// // oneTouchBloc.toggleCreateSchedule();
|
||||
// oneTouchBloc
|
||||
// .add(const ToggleCreateScheduleEvent(index: 0));
|
||||
// }
|
||||
// oneTouchBloc.add(const ToggleSelectedEvent(index: 0));
|
||||
// } else {
|
||||
// oneTouchBloc.add(const ToggleSelectedEvent(index: 1));
|
||||
// }
|
||||
setState(() {
|
||||
_selectedIndex = value; // Update selected index
|
||||
});
|
||||
},
|
||||
indicatorColor: Colors.white, // Customize the indicator
|
||||
indicatorColor: Colors.white,
|
||||
dividerHeight: 0,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
indicator: const ShapeDecoration(
|
||||
@ -92,7 +90,9 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
child: BodySmall(
|
||||
text: 'Record',
|
||||
style: context.bodySmall.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
color: _selectedIndex == 0
|
||||
? Colors.white
|
||||
: ColorsManager.blackColor,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
@ -105,7 +105,9 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
child: Text(
|
||||
'Automation Record',
|
||||
style: context.bodySmall.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
color: _selectedIndex == 1
|
||||
? Colors.white
|
||||
: ColorsManager.blackColor,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
@ -117,12 +119,11 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
physics:
|
||||
const NeverScrollableScrollPhysics(), // Disable swiping
|
||||
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
children: [
|
||||
// Build the ListView with grouped data
|
||||
ListView.builder(
|
||||
groupedRecords.isEmpty
|
||||
? const Center(child: Text('No data available.'))
|
||||
: ListView.builder(
|
||||
itemCount: groupedRecords.length,
|
||||
itemBuilder: (context, index) {
|
||||
final String date =
|
||||
@ -131,9 +132,9 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
groupedRecords[date]!;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Date header
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
@ -145,7 +146,6 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
// List of records for the specific date
|
||||
DefaultContainer(
|
||||
child: Column(
|
||||
children: [
|
||||
@ -154,9 +154,11 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
.entries
|
||||
.map((entry) {
|
||||
final int idx = entry.key;
|
||||
final DeviceEvent record = entry.value;
|
||||
final DeviceEvent record =
|
||||
entry.value;
|
||||
final DateTime eventDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime
|
||||
.fromMillisecondsSinceEpoch(
|
||||
record.eventTime!);
|
||||
final String formattedTime =
|
||||
DateFormat('HH:mm:ss')
|
||||
@ -164,33 +166,34 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
ListTile(
|
||||
leading: SvgPicture.asset(
|
||||
record.value == 'true'
|
||||
? Icons.radio_button_checked
|
||||
: Icons
|
||||
.radio_button_unchecked,
|
||||
color: record.value == 'true'
|
||||
? Colors.blue
|
||||
: Colors.grey,
|
||||
? Assets
|
||||
.leakDetectedIcon
|
||||
: Assets
|
||||
.leakNormalIcon,
|
||||
height: 25,
|
||||
width: 25,
|
||||
),
|
||||
title: Text(
|
||||
record.value == 'true'
|
||||
? "Opened"
|
||||
: "Closed",
|
||||
? "Normal"
|
||||
: "Leak Detected",
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
subtitle: Text('$formattedTime'),
|
||||
subtitle:
|
||||
Text('$formattedTime'),
|
||||
),
|
||||
),
|
||||
// Only add Divider if it's not the last item
|
||||
if (idx != recordsForDate.length - 1)
|
||||
if (idx !=
|
||||
recordsForDate.length - 1)
|
||||
const Divider(
|
||||
color: ColorsManager.graysColor,
|
||||
color: ColorsManager
|
||||
.graysColor,
|
||||
),
|
||||
],
|
||||
);
|
||||
@ -205,14 +208,14 @@ class WaterLeakRecordsScreen extends StatelessWidget {
|
||||
Container(
|
||||
height: 10,
|
||||
width: 20,
|
||||
)
|
||||
]))
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
// return const Center(child: Text('No data available.'));
|
||||
// },
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -29,13 +29,14 @@ class WaterLeakScreen extends StatelessWidget {
|
||||
child: BlocBuilder<WaterLeakBloc, WaterLeakState>(
|
||||
builder: (context, state) {
|
||||
final waterLeakBloc = BlocProvider.of<WaterLeakBloc>(context);
|
||||
WaterLeakModel model =
|
||||
WaterLeakModel(batteryPercentage: 0, waterContactState: false);
|
||||
WaterLeakModel model = WaterLeakModel(
|
||||
batteryPercentage: 0, waterContactState: 'normal');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.waterSensor;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.waterSensor;
|
||||
}
|
||||
print(model.batteryPercentage);
|
||||
return state is WaterLeakLoadingState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
@ -97,7 +98,7 @@ class WaterLeakScreen extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
model.waterContactState
|
||||
model.waterContactState == 'normal'
|
||||
? Assets.normalWaterLeak
|
||||
: Assets.detectedWaterLeak,
|
||||
fit: BoxFit.fill,
|
||||
@ -116,7 +117,8 @@ class WaterLeakScreen extends StatelessWidget {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
WaterLeakRecordsScreen(WLId: device!.uuid!)),
|
||||
WaterLeakRecordsScreen(
|
||||
WLId: device!.uuid!)),
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
@ -138,7 +140,6 @@ class WaterLeakScreen extends StatelessWidget {
|
||||
child: FittedBox(
|
||||
child: BodySmall(
|
||||
text: 'Records',
|
||||
// doorLockButtons.keys.elementAt(index),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@ -155,7 +156,8 @@ class WaterLeakScreen extends StatelessWidget {
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => NotificationSettingsPage()),
|
||||
builder: (context) =>
|
||||
NotificationSettingsPage()),
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
|
@ -1076,4 +1076,7 @@ class Assets {
|
||||
"assets/icons/detected_water_leak.svg";
|
||||
|
||||
static const String waterLeakIcon = "assets/icons/waterleak_icon.svg";
|
||||
static const String leakDetectedIcon = "assets/icons/leak_detected.svg";
|
||||
static const String leakNormalIcon = "assets/icons/leak_normal_icon.svg";
|
||||
//leakNormalIcon
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ class DevicesAPI {
|
||||
.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
print(json);
|
||||
return json;
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user