bug fixes 2

This commit is contained in:
mohammad
2024-09-23 14:37:07 +03:00
parent 62e80c89a2
commit 429009aefa
11 changed files with 863 additions and 661 deletions

View File

@ -8,7 +8,6 @@ import 'package:syncrow_app/features/auth/model/user_model.dart';
import 'package:syncrow_app/navigation/navigation_service.dart'; import 'package:syncrow_app/navigation/navigation_service.dart';
import 'package:syncrow_app/navigation/routing_constants.dart'; import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/services/api/authentication_api.dart'; import 'package:syncrow_app/services/api/authentication_api.dart';
import 'package:syncrow_app/services/api/profile_api.dart';
import 'package:syncrow_app/utils/helpers/shared_preferences_helper.dart'; import 'package:syncrow_app/utils/helpers/shared_preferences_helper.dart';
import 'package:syncrow_app/utils/helpers/snack_bar.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart';
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart'; import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';

View File

@ -16,7 +16,7 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
DoorSensorBloc({ DoorSensorBloc({
required this.DSId, required this.DSId,
}) : super(const DoorSensorState()) { }) : super(const DoorSensorState()) {
on<DoorSensorInitial>(_fetchWaterHeaterStatus); on<DoorSensorInitial>(_fetchStatus);
on<ReportLogsInitial>(fetchLogsForLastMonth); on<ReportLogsInitial>(fetchLogsForLastMonth);
on<ToggleLowBatteryEvent>(_toggleLowBattery); on<ToggleLowBatteryEvent>(_toggleLowBattery);
on<ToggleClosingReminderEvent>(_toggleClosingReminder); on<ToggleClosingReminderEvent>(_toggleClosingReminder);
@ -26,9 +26,11 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
bool lowBattery = false; bool lowBattery = false;
bool closingReminder = false; bool closingReminder = false;
bool doorAlarm = false; bool doorAlarm = false;
DoorSensorModel deviceStatus = DoorSensorModel(doorContactState: false, batteryPercentage: 0); DoorSensorModel deviceStatus =
DoorSensorModel(doorContactState: false, batteryPercentage: 0);
void _fetchWaterHeaterStatus(DoorSensorInitial event, Emitter<DoorSensorState> emit) async { void _fetchStatus(
DoorSensorInitial event, Emitter<DoorSensorState> emit) async {
emit(DoorSensorLoadingState()); emit(DoorSensorLoadingState());
try { try {
var response = await DevicesAPI.getDeviceStatus(DSId); var response = await DevicesAPI.getDeviceStatus(DSId);
@ -49,7 +51,8 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
} }
// Toggle functions for each switch // Toggle functions for each switch
void _toggleLowBattery(ToggleLowBatteryEvent event, Emitter<DoorSensorState> emit) async { void _toggleLowBattery(
ToggleLowBatteryEvent event, Emitter<DoorSensorState> emit) async {
emit(LoadingNewSate(doorSensor: deviceStatus)); emit(LoadingNewSate(doorSensor: deviceStatus));
try { try {
lowBattery = event.isLowBatteryEnabled; lowBattery = event.isLowBatteryEnabled;
@ -90,7 +93,8 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
} }
} }
void _toggleDoorAlarm(ToggleDoorAlarmEvent event, Emitter<DoorSensorState> emit) async { void _toggleDoorAlarm(
ToggleDoorAlarmEvent event, Emitter<DoorSensorState> emit) async {
emit(LoadingNewSate(doorSensor: deviceStatus)); emit(LoadingNewSate(doorSensor: deviceStatus));
try { try {
doorAlarm = event.isDoorAlarmEnabled; doorAlarm = event.isDoorAlarmEnabled;
@ -110,9 +114,11 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
} }
} }
DeviceReport recordGroups = DeviceReport(startTime: '0', endTime: '0', data: []); DeviceReport recordGroups =
DeviceReport(startTime: '0', endTime: '0', data: []);
Future<void> fetchLogsForLastMonth(ReportLogsInitial event, Emitter<DoorSensorState> emit) async { Future<void> fetchLogsForLastMonth(
ReportLogsInitial event, Emitter<DoorSensorState> emit) async {
// Get the current date and time // Get the current date and time
DateTime now = DateTime.now(); DateTime now = DateTime.now();
@ -123,15 +129,18 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
int startTime = lastMonth.millisecondsSinceEpoch; int startTime = lastMonth.millisecondsSinceEpoch;
int endTime = now.millisecondsSinceEpoch; int endTime = now.millisecondsSinceEpoch;
try { try {
emit(DoorSensorLoadingState());
var response = await DevicesAPI.getReportLogs( var response = await DevicesAPI.getReportLogs(
startTime: startTime.toString(), // Convert to String if the API expects it startTime:
startTime.toString(), // Convert to String if the API expects it
endTime: endTime.toString(), // Convert to String if the API expects it endTime: endTime.toString(), // Convert to String if the API expects it
deviceUuid: DSId, deviceUuid: DSId,
code: 'doorcontact_state', code: 'doorcontact_state',
); );
print('response======${response}');
recordGroups = response; recordGroups = response;
// Process response here // Process response here
print(response); emit(UpdateState(doorSensor: deviceStatus));
} on DioException catch (e) { } on DioException catch (e) {
final errorData = e.response!.data; final errorData = e.response!.data;
String errorMessage = errorData['message']; String errorMessage = errorData['message'];
@ -142,14 +151,16 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
_listenToChanges() { _listenToChanges() {
try { try {
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$DSId'); DatabaseReference ref =
FirebaseDatabase.instance.ref('device-status/$DSId');
Stream<DatabaseEvent> stream = ref.onValue; Stream<DatabaseEvent> stream = ref.onValue;
stream.listen((DatabaseEvent event) async { stream.listen((DatabaseEvent event) async {
if (_timer != null) { if (_timer != null) {
await Future.delayed(const Duration(seconds: 2)); await Future.delayed(const Duration(seconds: 2));
} }
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>; Map<dynamic, dynamic> usersMap =
event.snapshot.value as Map<dynamic, dynamic>;
List<StatusModel> statusList = []; List<StatusModel> statusList = [];
usersMap['status'].forEach((element) { usersMap['status'].forEach((element) {

View File

@ -1,7 +1,7 @@
class DeviceReport { class DeviceReport {
final String? deviceUuid; final dynamic deviceUuid;
final String? startTime; final dynamic startTime;
final String? endTime; final dynamic endTime;
final List<DeviceEvent>? data; final List<DeviceEvent>? data;
DeviceReport({ DeviceReport({

View File

@ -4,27 +4,10 @@ import 'package:intl/intl.dart';
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_event.dart'; import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_event.dart';
import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_state.dart'; import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_state.dart';
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_container.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
// // class DoorRecordsScreen extends StatelessWidget {
// final String DSId;
// const DoorRecordsScreen({super.key, required this.DSId});
// @override
// Widget build(BuildContext context) {
// return DefaultScaffold(
// title: 'Records',
// child: BlocProvider(
// create: (context) =>
// DoorSensorBloc(DSId: DSId)..add(const ReportLogsInitial()),
// child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
// builder: (context, state) {
// final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);
// return SizedBox(
// child: ListView.builder(
// itemCount: doorSensorBloc.recordGroups!.data!.length,
// itemBuilder: (context, index) {
// final recordGroup = doorSensorBloc.recordGroups!.data![index];
class DoorRecordsScreen extends StatelessWidget { class DoorRecordsScreen extends StatelessWidget {
final String DSId; final String DSId;
@ -35,36 +18,43 @@ class DoorRecordsScreen extends StatelessWidget {
return DefaultScaffold( return DefaultScaffold(
title: 'Records', title: 'Records',
child: BlocProvider( child: BlocProvider(
create: (context) => DoorSensorBloc(DSId: DSId)..add(const ReportLogsInitial()), create: (context) =>
DoorSensorBloc(DSId: DSId)..add(const ReportLogsInitial()),
child: BlocBuilder<DoorSensorBloc, DoorSensorState>( child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
builder: (context, state) { builder: (context, state) {
final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);
if (state is DoorSensorLoadingState) { if (state is DoorSensorLoadingState) {
return const Center(child: CircularProgressIndicator()); return const Center(
} child: DefaultContainer(
width: 50, height: 50, child: CircularProgressIndicator()),
if (state is DoorSensorFailedState) {
return Center(
child: Text('Failed to load data: ${state.errorMessage}'),
); );
} } else if (state is UpdateState) {
// Group records by formatted date
final Map<String, List<DeviceEvent>> groupedRecords = {};
if (state is UpdateState) { // Iterate over the data list in DeviceReport
final recordGroups = context.read<DoorSensorBloc>().recordGroups; for (var record in doorSensorBloc.recordGroups.data!) {
if (recordGroups.data == null || recordGroups.data!.isEmpty) {
return const Center(child: Text('No records available.'));
}
return ListView.builder(
itemCount: recordGroups.data!.length,
itemBuilder: (context, index) {
final record = recordGroups.data![index];
// Convert eventTime to a human-readable format
final DateTime eventDateTime = final DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(record.eventTime!); DateTime.fromMillisecondsSinceEpoch(record.eventTime!);
final String formattedDate = DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime); final String formattedDate =
final String formattedTime = DateFormat('HH:mm:ss').format(eventDateTime); DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime);
// Group by formatted date
if (groupedRecords.containsKey(formattedDate)) {
groupedRecords[formattedDate]!.add(record);
} else {
groupedRecords[formattedDate] = [record];
}
}
// Build the ListView with grouped data
return ListView.builder(
itemCount: groupedRecords.length,
itemBuilder: (context, index) {
final String date = groupedRecords.keys.elementAt(index);
final List<DeviceEvent> recordsForDate =
groupedRecords[date]!;
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -73,30 +63,57 @@ class DoorRecordsScreen extends StatelessWidget {
Padding( Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Text( child: Text(
formattedDate, date,
style: const TextStyle( style: const TextStyle(
fontSize: 18, color: ColorsManager.grayColor,
fontWeight: FontWeight.bold, fontSize: 13,
fontWeight: FontWeight.w700,
), ),
), ),
), ),
// Display the event details in DefaultContainer // List of records for the specific date
DefaultContainer( DefaultContainer(
child: Column(
children: [
...recordsForDate.map((record) {
final DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(
record.eventTime!);
final String formattedTime =
DateFormat('HH:mm:ss').format(eventDateTime);
return Column(
children: [
Container(
child: ListTile( child: ListTile(
leading: Icon( leading: Icon(
record.value == 'true' record.value == 'true'
? Icons.radio_button_checked ? Icons.radio_button_checked
: Icons.radio_button_unchecked, : Icons.radio_button_unchecked,
color: record.value == 'true' ? Colors.blue : Colors.grey, color: record.value == 'true'
? Colors.blue
: Colors.grey,
), ),
title: Text( title: Text(
'Status: ${record.value}', record.value == 'true'
? "Opened"
: "Closed",
style: const TextStyle( style: const TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 18, fontSize: 18,
), ),
), ),
subtitle: Text('Time: $formattedTime'), subtitle: Text('$formattedTime'),
),
),
const Divider(
color: ColorsManager.graysColor,
)
],
);
}).toList(),
],
), ),
), ),
], ],
@ -104,7 +121,6 @@ class DoorRecordsScreen extends StatelessWidget {
}, },
); );
} }
return const Center(child: Text('No data available.')); return const Center(child: Text('No data available.'));
}, },
), ),

View File

@ -63,17 +63,20 @@ class ScheduleScreen extends StatelessWidget {
Navigator.push( Navigator.push(
context, context,
PageRouteBuilder( PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen( pageBuilder:
switchCode :"switch_1", (context, animation1, animation2) =>
TimerScheduleScreen(
switchCode: "switch_1",
device: device, device: device,
deviceCode: 'countdown_1', deviceCode: 'countdown_1',
))); )));
}, },
child: Container( child: Container(
padding: padding: const EdgeInsets.only(
const EdgeInsets.only(left: 25, right: 15, top: 20, bottom: 20), left: 25, right: 15, top: 20, bottom: 20),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
BodySmall( BodySmall(
text: "Bedside Light", text: "Bedside Light",
@ -100,17 +103,20 @@ class ScheduleScreen extends StatelessWidget {
Navigator.push( Navigator.push(
context, context,
PageRouteBuilder( PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen( pageBuilder:
switchCode :"switch_2", (context, animation1, animation2) =>
TimerScheduleScreen(
switchCode: "switch_2",
device: device, device: device,
deviceCode: 'countdown_2', deviceCode: 'countdown_2',
))); )));
}, },
child: Container( child: Container(
padding: padding: const EdgeInsets.only(
const EdgeInsets.only(left: 25, right: 15, top: 20, bottom: 20), left: 25, right: 15, top: 20, bottom: 20),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
BodySmall( BodySmall(
text: "Ceiling Light", text: "Ceiling Light",
@ -137,17 +143,20 @@ class ScheduleScreen extends StatelessWidget {
Navigator.push( Navigator.push(
context, context,
PageRouteBuilder( PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen( pageBuilder:
switchCode :"switch_3", (context, animation1, animation2) =>
TimerScheduleScreen(
switchCode: "switch_3",
device: device, device: device,
deviceCode: 'countdown_3', deviceCode: 'countdown_3',
))); )));
}, },
child: Container( child: Container(
padding: padding: const EdgeInsets.only(
const EdgeInsets.only(left: 25, right: 15, top: 20, bottom: 20), left: 25, right: 15, top: 20, bottom: 20),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
BodySmall( BodySmall(
text: "Spotlight", text: "Spotlight",

View File

@ -22,7 +22,10 @@ class TimerScheduleScreen extends StatelessWidget {
final String deviceCode; final String deviceCode;
final String switchCode; final String switchCode;
const TimerScheduleScreen( const TimerScheduleScreen(
{required this.device, required this.deviceCode, required this.switchCode, super.key}); {required this.device,
required this.deviceCode,
required this.switchCode,
super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -32,7 +35,8 @@ class TimerScheduleScreen extends StatelessWidget {
statusBarIconBrightness: Brightness.light, statusBarIconBrightness: Brightness.light,
), ),
child: BlocProvider( child: BlocProvider(
create: (context) => ThreeGangBloc(switchCode: switchCode, threeGangId: device.uuid ?? '') create: (context) => ThreeGangBloc(
switchCode: switchCode, threeGangId: device.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode)) ..add(GetCounterEvent(deviceCode: deviceCode))
..add(GetScheduleEvent()), ..add(GetScheduleEvent()),
child: BlocBuilder<ThreeGangBloc, ThreeGangState>( child: BlocBuilder<ThreeGangBloc, ThreeGangState>(
@ -94,13 +98,15 @@ class TimerScheduleScreen extends StatelessWidget {
decoration: const ShapeDecoration( decoration: const ShapeDecoration(
color: ColorsManager.onPrimaryColor, color: ColorsManager.onPrimaryColor,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(30)), borderRadius:
BorderRadius.all(Radius.circular(30)),
), ),
), ),
child: TabBar( child: TabBar(
onTap: (value) { onTap: (value) {
if (value == 0) { if (value == 0) {
if (threeGangBloc.createSchedule == true) { if (threeGangBloc.createSchedule ==
true) {
threeGangBloc.toggleCreateSchedule(); threeGangBloc.toggleCreateSchedule();
} }
threeGangBloc.toggleSelectedIndex(0); threeGangBloc.toggleSelectedIndex(0);
@ -108,19 +114,21 @@ class TimerScheduleScreen extends StatelessWidget {
threeGangBloc.toggleSelectedIndex(1); threeGangBloc.toggleSelectedIndex(1);
} }
}, },
indicatorColor: Colors.white, // Customize the indicator indicatorColor: Colors.white,
dividerHeight: 0, dividerHeight: 0,
indicatorSize: TabBarIndicatorSize.tab, indicatorSize: TabBarIndicatorSize.tab,
indicator: const ShapeDecoration( indicator: const ShapeDecoration(
color: ColorsManager.slidingBlueColor, color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)), borderRadius: BorderRadius.all(
Radius.circular(20)),
), ),
), ),
tabs: [ tabs: [
Tab( Tab(
child: Container( child: Container(
padding: const EdgeInsets.symmetric(vertical: 10), padding: const EdgeInsets.symmetric(
vertical: 10),
child: BodySmall( child: BodySmall(
text: 'Countdown', text: 'Countdown',
style: context.bodySmall.copyWith( style: context.bodySmall.copyWith(
@ -133,7 +141,8 @@ class TimerScheduleScreen extends StatelessWidget {
), ),
Tab( Tab(
child: Container( child: Container(
padding: const EdgeInsets.symmetric(vertical: 10), padding: const EdgeInsets.symmetric(
vertical: 10),
child: Text( child: Text(
'Schedule', 'Schedule',
style: context.bodySmall.copyWith( style: context.bodySmall.copyWith(
@ -153,85 +162,119 @@ class TimerScheduleScreen extends StatelessWidget {
Center( Center(
child: Container( child: Container(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment:
MainAxisAlignment.center,
children: [ children: [
countNum > 0 countNum > 0
? BodyLarge( ? BodyLarge(
text: _formatDuration(countNum), text: _formatDuration(
fontColor: ColorsManager.slidingBlueColor, countNum),
fontColor: ColorsManager
.slidingBlueColor,
fontSize: 40, fontSize: 40,
) )
: CupertinoTimerPicker( : CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm, mode:
CupertinoTimerPickerMode
.hm,
onTimerDurationChanged: onTimerDurationChanged:
(Duration newDuration) { (Duration
newDuration) {
duration = newDuration; duration = newDuration;
}, },
), ),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (state is LoadingNewSate) { if (state
is LoadingNewSate) {
return; return;
} }
if (countNum > 0) { if (countNum > 0) {
threeGangBloc.add(SetCounterValue( threeGangBloc.add(
deviceCode: deviceCode, SetCounterValue(
duration: Duration.zero)); deviceCode:
} else if (duration != Duration.zero) { deviceCode,
threeGangBloc.add(SetCounterValue( duration: Duration
deviceCode: deviceCode, .zero));
duration: duration)); } else if (duration !=
Duration.zero) {
threeGangBloc.add(
SetCounterValue(
deviceCode:
deviceCode,
duration:
duration));
} }
}, },
child: SvgPicture.asset(countNum > 0 child: SvgPicture.asset(
countNum > 0
? Assets.pauseIcon ? Assets.pauseIcon
: Assets.playIcon)), : Assets.playIcon)),
], ],
), ),
), ),
), ),
Column(
mainAxisAlignment: threeGangBloc.listSchedule.isNotEmpty
? MainAxisAlignment.start
: MainAxisAlignment.center,
children: [
SizedBox( SizedBox(
child: threeGangBloc.createSchedule == true child: threeGangBloc.createSchedule ==
true
? CreateSchedule( ? CreateSchedule(
onToggleChanged: (bool isOn) { onToggleChanged: (bool isOn) {
threeGangBloc.toggleSchedule = isOn; threeGangBloc.toggleSchedule =
isOn;
}, },
onDateTimeChanged: (DateTime dateTime) { onDateTimeChanged:
threeGangBloc.selectedTime = dateTime; (DateTime dateTime) {
threeGangBloc.selectedTime =
dateTime;
}, },
days: threeGangBloc.days, days: threeGangBloc.days,
selectDays: (List<String> selectedDays) { selectDays: (List<String>
threeGangBloc.selectedDays = selectedDays; selectedDays) {
threeGangBloc.selectedDays =
selectedDays;
}, },
) )
: Padding( : Padding(
padding: const EdgeInsets.only(top: 10), padding: const EdgeInsets.only(
top: 10),
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Expanded(
child: ScheduleListView( child: ScheduleListView(
listSchedule: threeGangBloc listSchedule: threeGangBloc
.listSchedule, // Pass the schedule list here .listSchedule, // Pass the schedule list here
onDismissed: (scheduleId) { onDismissed:
threeGangBloc.listSchedule.removeWhere( (scheduleId) {
threeGangBloc
.listSchedule
.removeWhere(
(schedule) => (schedule) =>
schedule.scheduleId == scheduleId); schedule
.scheduleId ==
scheduleId);
threeGangBloc.add( threeGangBloc.add(
DeleteScheduleEvent(id: scheduleId)); DeleteScheduleEvent(
id: scheduleId));
}, },
onToggleSchedule: (scheduleId, isEnabled) { onToggleSchedule:
threeGangBloc.add(ToggleScheduleEvent( (scheduleId,
isEnabled) {
threeGangBloc.add(
ToggleScheduleEvent(
id: scheduleId, id: scheduleId,
toggle: isEnabled, toggle: isEnabled,
)); ));
}, },
), ),
), ),
),
], ],
), ),
),
),
], ],
), ),
), ),

View File

@ -73,55 +73,57 @@ class TimerScheduleScreen extends StatelessWidget {
fontWeight: FontsManager.bold, fontWeight: FontsManager.bold,
), ),
actions: [ actions: [
twoGangBloc.createSchedule == true ? twoGangBloc.createSchedule == true
TextButton( ? TextButton(
onPressed: () { onPressed: () {
twoGangBloc.add(TwoGangSave()); twoGangBloc.add(TwoGangSave());
}, },
child: const Text('Save') child: const Text('Save'))
) : : twoGangBloc.selectedTabIndex == 1
twoGangBloc.selectedTabIndex==1? IconButton( ? IconButton(
onPressed: () { onPressed: () {
twoGangBloc.toggleCreateSchedule(); twoGangBloc.toggleCreateSchedule();
}, },
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
):SizedBox(), )
: SizedBox(),
], ],
), ),
child: child: state is LoadingInitialState
state is LoadingInitialState? ? const Center(child: CircularProgressIndicator())
const Center(child: CircularProgressIndicator()): : Column(
Column(
children: [ children: [
Container( Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
decoration: const ShapeDecoration( decoration: const ShapeDecoration(
color: ColorsManager.onPrimaryColor, color: ColorsManager.onPrimaryColor,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(30)), borderRadius:
BorderRadius.all(Radius.circular(30)),
), ),
), ),
child: TabBar( child: TabBar(
onTap: (value) { onTap: (value) {
print(value); print(value);
if(value==0){ if (value == 0) {
if(twoGangBloc.createSchedule == true){ if (twoGangBloc.createSchedule ==
true) {
twoGangBloc.toggleCreateSchedule(); twoGangBloc.toggleCreateSchedule();
} }
twoGangBloc.toggleSelectedIndex(0); twoGangBloc.toggleSelectedIndex(0);
} else {
}else{
twoGangBloc.toggleSelectedIndex(1); twoGangBloc.toggleSelectedIndex(1);
} }
}, },
indicatorColor: Colors.white, // Customize the indicator indicatorColor:
Colors.white, // Customize the indicator
dividerHeight: 0, dividerHeight: 0,
indicatorSize: TabBarIndicatorSize.tab, indicatorSize: TabBarIndicatorSize.tab,
indicator: const ShapeDecoration( indicator: const ShapeDecoration(
color: ColorsManager.slidingBlueColor, color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: borderRadius: BorderRadius.all(
BorderRadius.all(Radius.circular(20)), Radius.circular(20)),
), ),
), ),
tabs: [ tabs: [
@ -141,7 +143,8 @@ class TimerScheduleScreen extends StatelessWidget {
), ),
Tab( Tab(
child: Container( child: Container(
padding: const EdgeInsets.symmetric(vertical: 10), padding: const EdgeInsets.symmetric(
vertical: 10),
child: Text( child: Text(
'Schedule', 'Schedule',
style: context.bodySmall.copyWith( style: context.bodySmall.copyWith(
@ -161,89 +164,113 @@ class TimerScheduleScreen extends StatelessWidget {
Center( Center(
child: Container( child: Container(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment:
MainAxisAlignment.center,
children: [ children: [
countNum > 0 countNum > 0
? BodyLarge( ? BodyLarge(
text: _formatDuration(countNum), text: _formatDuration(
fontColor: countNum),
ColorsManager.slidingBlueColor, fontColor: ColorsManager
.slidingBlueColor,
fontSize: 40, fontSize: 40,
) )
: CupertinoTimerPicker( : CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm, mode:
CupertinoTimerPickerMode
.hm,
onTimerDurationChanged: onTimerDurationChanged:
(Duration newDuration) { (Duration
newDuration) {
duration = newDuration; duration = newDuration;
}, },
), ),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (state is LoadingNewSate) { if (state
is LoadingNewSate) {
return; return;
} }
if (countNum > 0) { if (countNum > 0) {
twoGangBloc.add(SetCounterValue( twoGangBloc.add(
deviceCode: deviceCode, SetCounterValue(
duration: Duration.zero)); deviceCode:
} else if (duration != Duration.zero) { deviceCode,
twoGangBloc.add(SetCounterValue( duration: Duration
deviceCode: deviceCode, .zero));
duration: duration)); } else if (duration !=
Duration.zero) {
twoGangBloc.add(
SetCounterValue(
deviceCode:
deviceCode,
duration:
duration));
} }
}, },
child: SvgPicture.asset(countNum > 0 child: SvgPicture.asset(
countNum > 0
? Assets.pauseIcon ? Assets.pauseIcon
: Assets.playIcon)), : Assets.playIcon)),
], ],
), ),
), ),
), ),
Column(
mainAxisAlignment:twoGangBloc.listSchedule.isNotEmpty?
MainAxisAlignment.start:MainAxisAlignment.center,
children: [
SizedBox( SizedBox(
child: twoGangBloc.createSchedule == true ? child: twoGangBloc.createSchedule ==
CreateSchedule( true
? CreateSchedule(
onToggleChanged: (bool isOn) { onToggleChanged: (bool isOn) {
twoGangBloc.toggleSchedule = isOn; twoGangBloc.toggleSchedule =
isOn;
}, },
onDateTimeChanged: (DateTime dateTime) { onDateTimeChanged:
twoGangBloc.selectedTime=dateTime; (DateTime dateTime) {
twoGangBloc.selectedTime =
dateTime;
}, },
days: twoGangBloc.days, days: twoGangBloc.days,
selectDays: (List<String> selectedDays) { selectDays: (List<String>
twoGangBloc.selectedDays = selectedDays; selectedDays) {
twoGangBloc.selectedDays =
selectedDays;
}, },
) )
: : Padding(
Padding( padding: const EdgeInsets.only(
padding: const EdgeInsets.only(top: 10), top: 10),
child: Column(
children: [
Expanded(
child: ScheduleListView( child: ScheduleListView(
listSchedule: twoGangBloc.listSchedule, // Pass the schedule list here listSchedule: twoGangBloc.listSchedule, // Pass the schedule list here
onDismissed: (scheduleId) { onDismissed:(scheduleId) {
twoGangBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId); twoGangBloc .listSchedule
twoGangBloc.add(DeleteScheduleEvent(id: scheduleId)); .removeWhere( (schedule) => schedule .scheduleId == scheduleId);
twoGangBloc.add(
DeleteScheduleEvent( id: scheduleId));
}, },
onToggleSchedule: (scheduleId, isEnabled) { onToggleSchedule:
twoGangBloc.add(ToggleScheduleEvent( (scheduleId,
isEnabled) {
twoGangBloc.add(
ToggleScheduleEvent(
id: scheduleId, id: scheduleId,
toggle: isEnabled, toggle: isEnabled,
)); ));
}, },
), ),
), ),
),
], ],
), ),
),
),
], ],
), ),
), ),
], ],
), ),
)) )));
);
}, },
), ),
), ),

View File

@ -1,8 +1,3 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
@ -13,7 +8,6 @@ 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/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/generated/assets.dart';
class CirculateListView extends StatelessWidget { class CirculateListView extends StatelessWidget {
final List<ScheduleModel> listSchedule; final List<ScheduleModel> listSchedule;
final Function(String) onDismissed; final Function(String) onDismissed;
@ -56,7 +50,6 @@ class CirculateListView extends StatelessWidget {
), ),
direction: DismissDirection.endToStart, direction: DismissDirection.endToStart,
onDismissed: (direction) { onDismissed: (direction) {
onDismissed(listSchedule[index].scheduleId); onDismissed(listSchedule[index].scheduleId);
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@ -64,28 +57,32 @@ class CirculateListView extends StatelessWidget {
); );
}, },
child: InkWell( child: InkWell(
onTap: () { onTap: () {},
},
child: DefaultContainer( child: DefaultContainer(
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
height: MediaQuery.of(context).size.height / 6.4, height: MediaQuery.of(context).size.height / 6.5,
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
flex: 2,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [ children: [
BodyLarge( BodyLarge(
text: '12:30 AM - 01:30 PM', text: '12:30 AM - 01:30 PM',
// text: listSchedule[index].time, // text: listSchedule[index].time,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontColor: Colors.black, fontColor: Colors.black,
fontSize: 22, fontSize: 18,
),
],
), ),
Text(listSchedule[index].days.join(' ')), Text(listSchedule[index].days.join(' ')),
// Text('Function ${listSchedule[index].function.value ? "ON" : "OFF"}'), // Text('Function ${listSchedule[index].function.value ? "ON" : "OFF"}'),
Text('Start Duration: 0h 10m End Duration: 0h 15m'), Text(
'Start Duration: 0h 10m End Duration: 0h 15m'),
], ],
), ),
), ),
@ -119,7 +116,6 @@ class CirculateListView extends StatelessWidget {
}, },
), ),
) )
: const EmptySchedule() : const EmptySchedule());
);
} }
} }

View File

@ -76,12 +76,14 @@ class WHTimerScheduleScreen extends StatelessWidget {
fontWeight: FontsManager.bold, fontWeight: FontsManager.bold,
), ),
actions: [ actions: [
waterHeaterBloc.createSchedule == true && waterHeaterBloc.selectedTabIndex == 1 ? waterHeaterBloc.createSchedule == true &&
TextButton( waterHeaterBloc.selectedTabIndex == 1
? TextButton(
onPressed: () { onPressed: () {
waterHeaterBloc.add(ScheduleSave()); waterHeaterBloc.add(ScheduleSave());
}, },
child: const Text('Save')) : waterHeaterBloc.selectedTabIndex == 1 child: const Text('Save'))
: waterHeaterBloc.selectedTabIndex == 1
? IconButton( ? IconButton(
onPressed: () { onPressed: () {
waterHeaterBloc.toggleCreateSchedule(); waterHeaterBloc.toggleCreateSchedule();
@ -89,8 +91,9 @@ class WHTimerScheduleScreen extends StatelessWidget {
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
) )
: const SizedBox(), : const SizedBox(),
waterHeaterBloc.createCirculate == true &&waterHeaterBloc.selectedTabIndex==2 ? waterHeaterBloc.createCirculate == true &&
TextButton( waterHeaterBloc.selectedTabIndex == 2
? TextButton(
onPressed: () { onPressed: () {
waterHeaterBloc.add(ScheduleSave()); waterHeaterBloc.add(ScheduleSave());
}, },
@ -124,20 +127,29 @@ class WHTimerScheduleScreen extends StatelessWidget {
labelPadding: EdgeInsets.zero, labelPadding: EdgeInsets.zero,
onTap: (value) { onTap: (value) {
if (value == 0) { if (value == 0) {
if (waterHeaterBloc.createSchedule == true) { if (waterHeaterBloc.createSchedule ==
waterHeaterBloc.toggleCreateSchedule(); true) {
waterHeaterBloc
.toggleCreateSchedule();
} }
waterHeaterBloc.toggleSelectedIndex(value); waterHeaterBloc
.toggleSelectedIndex(value);
} else if (value == 2) { } else if (value == 2) {
if (waterHeaterBloc.createCirculate == true) { if (waterHeaterBloc.createCirculate ==
waterHeaterBloc.toggleCreateCirculate(); true) {
waterHeaterBloc
.toggleCreateCirculate();
} }
waterHeaterBloc.toggleSelectedIndex(value); waterHeaterBloc
.toggleSelectedIndex(value);
} else { } else {
if (waterHeaterBloc.createSchedule == true) { if (waterHeaterBloc.createSchedule ==
waterHeaterBloc.toggleCreateSchedule(); true) {
waterHeaterBloc
.toggleCreateSchedule();
} }
waterHeaterBloc.toggleSelectedIndex(value); waterHeaterBloc
.toggleSelectedIndex(value);
} }
}, },
indicatorColor: Colors.white, indicatorColor: Colors.white,
@ -151,96 +163,128 @@ class WHTimerScheduleScreen extends StatelessWidget {
), ),
), ),
isScrollable: false, isScrollable: false,
labelColor: Colors.white, // Text color when selected labelColor: Colors
unselectedLabelColor: ColorsManager.blackColor, // Text color when not selected .white, // Text color when selected
unselectedLabelColor: ColorsManager
.blackColor, // Text color when not selected
tabs: [ tabs: [
Tab( Tab(
icon: SvgPicture.asset( icon: Padding(
padding: const EdgeInsets.only(
top: 10.0),
child: SvgPicture.asset(
Assets.scheduleTimeIcon, Assets.scheduleTimeIcon,
color: waterHeaterBloc.selectedTabIndex == 0 color: waterHeaterBloc
.selectedTabIndex ==
0
? Colors.white ? Colors.white
: ColorsManager.blackColor, // Change icon color based on selectedIndex : ColorsManager
.blackColor, // Change icon color based on selectedIndex
),
), ),
child: Container( child: Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 10), vertical: 5),
child: BodySmall( child: BodySmall(
text: 'Countdown', text: 'Countdown',
style: context.bodySmall.copyWith( style: context.bodySmall.copyWith(
color: waterHeaterBloc.selectedTabIndex == 0 color: waterHeaterBloc
.selectedTabIndex ==
0
? Colors.white ? Colors.white
: ColorsManager : ColorsManager
.blackColor, // Text color based on selectedTabIndex .blackColor, // Text color based on selectedTabIndex
fontSize: 8, fontSize: 10,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
), ),
), ),
Tab( Tab(
icon: SvgPicture.asset( icon: Padding(
padding:
const EdgeInsets.only(top: 10),
child: SvgPicture.asset(
Assets.scheduleCelenderIcon, Assets.scheduleCelenderIcon,
color: waterHeaterBloc.selectedTabIndex == 1 color: waterHeaterBloc
.selectedTabIndex ==
1
? Colors.white ? Colors.white
: ColorsManager.blackColor, : ColorsManager.blackColor,
), ),
),
child: Container( child: Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 10), vertical: 5),
child: Text( child: Text(
'Schedule', 'Schedule',
style: context.bodySmall.copyWith( style: context.bodySmall.copyWith(
color: waterHeaterBloc.selectedTabIndex == 1 color: waterHeaterBloc
.selectedTabIndex ==
1
? Colors.white ? Colors.white
: ColorsManager.blackColor, : ColorsManager.blackColor,
fontSize: 8, fontSize: 12,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
), ),
), ),
Tab( Tab(
icon: SvgPicture.asset( icon: Padding(
padding:
const EdgeInsets.only(top: 10),
child: SvgPicture.asset(
Assets.scheduleCirculateIcon, Assets.scheduleCirculateIcon,
color: waterHeaterBloc.selectedTabIndex == 2 color: waterHeaterBloc
.selectedTabIndex ==
2
? Colors.white ? Colors.white
: ColorsManager.blackColor, : ColorsManager.blackColor,
), ),
),
child: Container( child: Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 10), vertical: 5),
child: Text( child: Text(
'Circulate', 'Circulate',
style: context.bodySmall.copyWith( style: context.bodySmall.copyWith(
color: waterHeaterBloc color: waterHeaterBloc
.selectedTabIndex == 2 .selectedTabIndex ==
2
? Colors.white ? Colors.white
: ColorsManager.blackColor, : ColorsManager.blackColor,
fontSize: 8, fontSize: 12,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
), ),
), ),
Tab( Tab(
icon: SvgPicture.asset( icon: Padding(
padding:
const EdgeInsets.only(top: 10),
child: SvgPicture.asset(
Assets.scheduleInchingIcon, Assets.scheduleInchingIcon,
color: waterHeaterBloc color: waterHeaterBloc
.selectedTabIndex == 3 .selectedTabIndex ==
3
? Colors.white ? Colors.white
: ColorsManager.blackColor, : ColorsManager.blackColor,
), ),
),
child: Container( child: Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 10), vertical: 5),
child: Text( child: Text(
'Inching', 'Inching',
style: context.bodySmall.copyWith( style: context.bodySmall.copyWith(
color: waterHeaterBloc color: waterHeaterBloc
.selectedTabIndex == 3 .selectedTabIndex ==
3
? Colors.white ? Colors.white
: ColorsManager.blackColor, : ColorsManager.blackColor,
fontSize: 8, fontSize: 12,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
@ -308,93 +352,132 @@ class WHTimerScheduleScreen extends StatelessWidget {
), ),
), ),
), ),
Column(
mainAxisAlignment: waterHeaterBloc
.listSchedule.isNotEmpty
? MainAxisAlignment.start
: MainAxisAlignment.center,
children: [
SizedBox( SizedBox(
child: waterHeaterBloc.createSchedule == true child: waterHeaterBloc.createSchedule ==
true
? CreateSchedule( ? CreateSchedule(
onToggleChanged: (bool isOn) { onToggleChanged: (bool isOn) {
waterHeaterBloc.toggleSchedule = isOn; waterHeaterBloc
.toggleSchedule = isOn;
}, },
onDateTimeChanged: (DateTime dateTime) { onDateTimeChanged:
waterHeaterBloc.selectedTime = dateTime; (DateTime dateTime) {
waterHeaterBloc.selectedTime =
dateTime;
}, },
days: waterHeaterBloc.days, days: waterHeaterBloc.days,
selectDays: (List<String> selectDays: (List<String>
selectedDays) { selectedDays) {
waterHeaterBloc waterHeaterBloc.selectedDays =
.selectedDays =
selectedDays; selectedDays;
}, },
) )
: Padding( : Padding(
padding: const EdgeInsets.only(top: 10), padding: const EdgeInsets.only(
top: 10),
child: Column(
children: [
Expanded(
child: ScheduleListView( child: ScheduleListView(
listSchedule: waterHeaterBloc.listSchedule, // Pass the schedule list here listSchedule:
waterHeaterBloc
.listSchedule, // Pass the schedule list here
onDismissed: onDismissed:
(scheduleId) { (scheduleId) {
waterHeaterBloc.listSchedule.removeWhere( waterHeaterBloc
(schedule) => schedule.scheduleId == scheduleId); .listSchedule
.removeWhere(
(schedule) =>
schedule
.scheduleId ==
scheduleId);
waterHeaterBloc.add( waterHeaterBloc.add(
DeleteScheduleEvent(id: scheduleId)); DeleteScheduleEvent(
id: scheduleId));
}, },
onToggleSchedule: (scheduleId, isEnabled) { onToggleSchedule:
(scheduleId,
waterHeaterBloc.add(ToggleScheduleEvent( isEnabled) {
id: scheduleId, toggle: isEnabled, waterHeaterBloc.add(
ToggleScheduleEvent(
id: scheduleId,
toggle: isEnabled,
)); ));
}, },
), ),
), ),
),
], ],
), ),
),
),
Center( Center(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment:
mainAxisAlignment: MainAxisAlignment.center, CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [ children: [
waterHeaterBloc.createCirculate == true waterHeaterBloc.createCirculate ==
? true
CirculateWidget( ? CirculateWidget(
endDuration: () { endDuration: () {
waterHeaterBloc.add(SelectTimeEvent(context: context, isEffective: false)); waterHeaterBloc.add(
SelectTimeEvent(
context: context,
isEffective:
false));
}, },
startDuration: () { startDuration: () {
waterHeaterBloc.add(SelectTimeEvent(context: context, isEffective: false)); waterHeaterBloc.add(
SelectTimeEvent(
context: context,
isEffective:
false));
}, },
isStartEndTime: true, isStartEndTime: true,
startTime: DateTime.now(), startTime: DateTime.now(),
endTime: DateTime.now(), endTime: DateTime.now(),
days: waterHeaterBloc.days, days: waterHeaterBloc.days,
selectedDays: [], selectedDays: [],
onToggleStartEndTime: (c) {}, onToggleStartEndTime:
onTimeChanged: (x, f) { (c) {},
}, onTimeChanged: (x, f) {},
onDaySelected: (p0) {}, onDaySelected: (p0) {},
):CirculateListView( )
listSchedule: waterHeaterBloc.listSchedule, // Pass the schedule list here : CirculateListView(
listSchedule: [], // Pass the schedule list here
onDismissed: (scheduleId) { onDismissed: (scheduleId) {
waterHeaterBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId); waterHeaterBloc
waterHeaterBloc.add(DeleteScheduleEvent(id: scheduleId)); .listSchedule
.removeWhere((schedule) =>
schedule
.scheduleId ==
scheduleId);
waterHeaterBloc.add(
DeleteScheduleEvent(
id: scheduleId));
}, },
onToggleSchedule: (scheduleId, isEnabled) { onToggleSchedule:
waterHeaterBloc.add(ToggleScheduleEvent( (scheduleId,
id: scheduleId, toggle: isEnabled, isEnabled) {
waterHeaterBloc.add(
ToggleScheduleEvent(
id: scheduleId,
toggle: isEnabled,
)); ));
}, },
) )
], ],
), ),
), ),
Column(children: [ Column(
children: [
SizedBox(height: 20), SizedBox(height: 20),
Container(child: InchingWidget(),),],) Container(
child: InchingWidget(),
),
],
)
], ],
), ),
), ),

View File

@ -21,8 +21,7 @@ class ScheduleListView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return listSchedule.isNotEmpty
child: listSchedule.isNotEmpty
? SizedBox( ? SizedBox(
child: ListView.builder( child: ListView.builder(
shrinkWrap: true, shrinkWrap: true,
@ -109,6 +108,11 @@ class ScheduleListView extends StatelessWidget {
}, },
), ),
) )
: const EmptySchedule()); : const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(child: EmptySchedule()),
],
);
} }
} }

View File

@ -72,7 +72,8 @@ class DevicesAPI {
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async { static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.deviceFunctionsStatus.replaceAll('{deviceUuid}', deviceId), path: ApiEndpoints.deviceFunctionsStatus
.replaceAll('{deviceUuid}', deviceId),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json; return json;
@ -82,7 +83,9 @@ class DevicesAPI {
} }
static Future<Map<String, dynamic>> renamePass( static Future<Map<String, dynamic>> renamePass(
{required String name, required String doorLockUuid, required String passwordId}) async { {required String name,
required String doorLockUuid,
required String passwordId}) async {
final response = await _httpService.put( final response = await _httpService.put(
path: ApiEndpoints.renamePassword path: ApiEndpoints.renamePassword
.replaceAll('{doorLockUuid}', doorLockUuid) .replaceAll('{doorLockUuid}', doorLockUuid)
@ -107,7 +110,8 @@ class DevicesAPI {
return response; return response;
} }
static Future<List<DeviceModel>> getDeviceByGroupName(String unitId, String groupName) async { static Future<List<DeviceModel>> getDeviceByGroupName(
String unitId, String groupName) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.devicesByGroupName path: ApiEndpoints.devicesByGroupName
.replaceAll('{unitUuid}', unitId) .replaceAll('{unitUuid}', unitId)
@ -146,7 +150,8 @@ class DevicesAPI {
return response; return response;
} }
static Future<List<DeviceModel>> getDevicesByGatewayId(String gatewayId) async { static Future<List<DeviceModel>> getDevicesByGatewayId(
String gatewayId) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId), path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
showServerMessage: false, showServerMessage: false,
@ -168,7 +173,8 @@ class DevicesAPI {
String deviceId, String deviceId,
) async { ) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.getTemporaryPassword.replaceAll('{doorLockUuid}', deviceId), path: ApiEndpoints.getTemporaryPassword
.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json; return json;
@ -179,7 +185,8 @@ class DevicesAPI {
static Future getOneTimePasswords(String deviceId) async { static Future getOneTimePasswords(String deviceId) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.getOneTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId), path: ApiEndpoints.getOneTimeTemporaryPassword
.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json; return json;
@ -190,7 +197,8 @@ class DevicesAPI {
static Future getTimeLimitPasswords(String deviceId) async { static Future getTimeLimitPasswords(String deviceId) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.getMultipleTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId), path: ApiEndpoints.getMultipleTimeTemporaryPassword
.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json; return json;
@ -215,10 +223,12 @@ class DevicesAPI {
"invalidTime": invalidTime, "invalidTime": invalidTime,
}; };
if (scheduleList != null) { if (scheduleList != null) {
body["scheduleList"] = scheduleList.map((schedule) => schedule.toJson()).toList(); body["scheduleList"] =
scheduleList.map((schedule) => schedule.toJson()).toList();
} }
final response = await _httpService.post( final response = await _httpService.post(
path: ApiEndpoints.addTemporaryPassword.replaceAll('{doorLockUuid}', deviceId), path: ApiEndpoints.addTemporaryPassword
.replaceAll('{doorLockUuid}', deviceId),
body: body, body: body,
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) => json, expectedResponseModel: (json) => json,
@ -229,7 +239,8 @@ class DevicesAPI {
static Future generateOneTimePassword({deviceId}) async { static Future generateOneTimePassword({deviceId}) async {
try { try {
final response = await _httpService.post( final response = await _httpService.post(
path: ApiEndpoints.addOneTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId), path: ApiEndpoints.addOneTimeTemporaryPassword
.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json; return json;
@ -241,10 +252,12 @@ class DevicesAPI {
} }
} }
static Future generateMultiTimePassword({deviceId, effectiveTime, invalidTime}) async { static Future generateMultiTimePassword(
{deviceId, effectiveTime, invalidTime}) async {
try { try {
final response = await _httpService.post( final response = await _httpService.post(
path: ApiEndpoints.addMultipleTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId), path: ApiEndpoints.addMultipleTimeTemporaryPassword
.replaceAll('{doorLockUuid}', deviceId),
showServerMessage: true, showServerMessage: true,
body: {"effectiveTime": effectiveTime, "invalidTime": invalidTime}, body: {"effectiveTime": effectiveTime, "invalidTime": invalidTime},
expectedResponseModel: (json) { expectedResponseModel: (json) {
@ -361,6 +374,7 @@ class DevicesAPI {
.replaceAll('{startTime}', startTime) .replaceAll('{startTime}', startTime)
.replaceAll('{endTime}', endTime), .replaceAll('{endTime}', endTime),
expectedResponseModel: (json) { expectedResponseModel: (json) {
print('json-=-=-=-=-=-=-=${json}');
return DeviceReport.fromJson(json); return DeviceReport.fromJson(json);
}, },
); );