water heater and timer and schedule ui and api ,

Circulate ui and Inching ui
This commit is contained in:
mohammad
2024-09-20 11:50:39 +03:00
parent 26833cf215
commit f0feb4021f
22 changed files with 1830 additions and 15 deletions
@@ -14,11 +14,11 @@ import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface
import 'package:syncrow_app/features/devices/view/widgets/one_gang/one_gang_Interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/one_gang/one_gang_screen.dart';
import 'package:syncrow_app/features/devices/view/widgets/two_gang/two_gang_Interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/two_gang/two_gang_screen.dart';
import 'package:syncrow_app/features/devices/view/widgets/wall_sensor/wall_sensor_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/water_heater/water_heater_page.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
@@ -148,6 +148,14 @@ void showDeviceInterface(DeviceModel device, BuildContext context) {
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
ThreeGangInterface(gangSwitch: device)));
case DeviceType.WH:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
WaterHeaterPage(device: device)));
break;
default:
}
@@ -0,0 +1,69 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import '../../../../../utils/resource_manager/color_manager.dart';
class InchingWidget extends StatefulWidget {
const InchingWidget({super.key,this.onDateTimeChanged});
final Function(DateTime)? onDateTimeChanged;
@override
State<InchingWidget> createState() => _InchingWidgetState();
}
class _InchingWidgetState extends State<InchingWidget> {
@override
Widget build(BuildContext context) {
bool isOn = true; // Boolean state for the ON/OFF toggle
return Column(
children: [
DefaultContainer(
child: Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Inching', // Change text based on state
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
CircleAvatar(
backgroundColor: isOn
? ColorsManager.secondaryColor.withOpacity(0.6)
: Colors.red.withOpacity(0.6), // Change background color based on state
child: const Icon(
Icons.power_settings_new,
color: ColorsManager.onPrimaryColor, // Change icon color
),
),
],
),
SizedBox(height: 10,),
Text('Once enabled this feature, each time the device is turned on, it will automatically turn of after a period time as pre-set.'),
],
),
),
),
SizedBox(
height: 110,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.time,
initialDateTime: DateTime.now(),
onDateTimeChanged: (selectedTime) {
}, ),
),
],
);
}
}
@@ -0,0 +1,125 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/model/schedule_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/empty_schedule.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/generated/assets.dart';
class CirculateListView extends StatelessWidget {
final List<ScheduleModel> listSchedule;
final Function(String) onDismissed;
final Function(String, bool) onToggleSchedule;
const CirculateListView({
super.key,
required this.listSchedule,
required this.onDismissed,
required this.onToggleSchedule,
});
@override
Widget build(BuildContext context) {
return Center(
child: listSchedule.isNotEmpty
? SizedBox(
child: ListView.builder(
shrinkWrap: true,
itemCount: listSchedule.length,
itemBuilder: (context, index) {
return Dismissible(
key: Key(listSchedule[index].scheduleId),
background: Container(
padding: const EdgeInsets.only(right: 10),
alignment: AlignmentDirectional.centerEnd,
decoration: const ShapeDecoration(
color: Color(0xFFFF0000),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
),
child: Padding(
padding: const EdgeInsets.only(bottom: 10, right: 10),
child: SvgPicture.asset(
Assets.assetsDeleteIcon,
width: 20,
height: 22,
),
),
),
direction: DismissDirection.endToStart,
onDismissed: (direction) {
onDismissed(listSchedule[index].scheduleId);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Schedule removed')),
);
},
child: InkWell(
onTap: () {
},
child: DefaultContainer(
padding: const EdgeInsets.all(20),
height: MediaQuery.of(context).size.height / 6.4,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BodyLarge(
text: '12:30 AM - 01:30 PM',
// text: listSchedule[index].time,
fontWeight: FontWeight.w500,
fontColor: Colors.black,
fontSize: 22,
),
Text(listSchedule[index].days.join(' ')),
// Text('Function ${listSchedule[index].function.value ? "ON" : "OFF"}'),
Text('Start Duration: 0h 10m End Duration: 0h 15m'),
],
),
),
Expanded(
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: const BodyMedium(
text: '',
fontWeight: FontWeight.normal,
),
trailing: Transform.scale(
scale: .8,
child: CupertinoSwitch(
value: listSchedule[index].enable,
onChanged: (value) {
onToggleSchedule(
listSchedule[index].scheduleId,
value,
);
},
applyTheme: true,
),
),
),
),
],
),
),
),
);
},
),
)
: const EmptySchedule()
);
}
}
@@ -0,0 +1,168 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class CirculateWidget extends StatelessWidget {
final bool isStartEndTime;
final DateTime startTime;
final DateTime endTime;
final List<Map<String, String>> days;
final List<String> selectedDays;
// Callback functions to handle user interactions
final Function(bool) onToggleStartEndTime;
final Function(DateTime, bool) onTimeChanged;
final Function(String) onDaySelected;
const CirculateWidget({
Key? key,
required this.isStartEndTime,
required this.startTime,
required this.endTime,
required this.days,
required this.selectedDays,
required this.onToggleStartEndTime,
required this.onTimeChanged,
required this.onDaySelected,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
child: Column(
children: <Widget>[
// Start/End time toggle buttons
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () {
onToggleStartEndTime(true); // Toggle to Start Time
},
child: BodyMedium(
text: 'Start',
fontColor: !isStartEndTime ? Colors.black : Colors.blue,
fontSize: 18,
),
),
InkWell(
onTap: () {
onToggleStartEndTime(false); // Toggle to End Time
},
child: BodyMedium(
text: 'End',
fontColor: isStartEndTime ? Colors.black : Colors.blue,
fontSize: 18,
),
),
],
),
),
const Divider(
color: ColorsManager.graysColor,
),
// Time picker based on start/end toggle
SizedBox(
height: 110,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.time,
initialDateTime: isStartEndTime ? startTime : endTime,
onDateTimeChanged: (selectedTime) {
onTimeChanged(selectedTime, isStartEndTime); // Notify parent of time change
},
),
),
const Divider(
color: ColorsManager.graysColor,
),
const SizedBox(height: 20),
Text('Select days to use Smart Mode'),
const SizedBox(height: 20),
// Days selection as horizontal list
SizedBox(
height: MediaQuery.of(context).size.height * 0.10,
child: ListView(
scrollDirection: Axis.horizontal,
children: days.map((day) {
bool isSelected = selectedDays.contains(day['key']);
return Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
onDaySelected(day['key']!); // Notify parent of day selection
},
child: Container(
width: 70,
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
border: Border.all(
color: isSelected ? Colors.black : ColorsManager.grayColor,
),
color: Colors.transparent,
borderRadius: BorderRadius.circular(55),
),
child: Center(
child: Text(
day['day']!,
style: TextStyle(
fontSize: 18,
color: isSelected ? Colors.black : ColorsManager.grayColor,
),
),
),
),
),
);
}).toList(),
),
),
const SizedBox(height: 20),
const DefaultContainer(child:
Column(
children: [
Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Start Duration'),
Row(
children: [
Text('0h 0m'),
Icon(Icons.arrow_forward_ios_sharp,color:ColorsManager.graysColor,)
],
),
],),
),
Divider(color: ColorsManager.graysColor,),
Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('End Duration'),
Row(
children: [
Text('0h 0m'),
Icon(Icons.arrow_forward_ios_sharp,color:ColorsManager.graysColor,)
],
),
],),
),
],
)
)
],
),
);
}
}
@@ -0,0 +1,188 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_event.dart';
import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/water_heater.dart';
import 'package:syncrow_app/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.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/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import '../../../../../generated/assets.dart';
class WaterHeaterPage extends StatelessWidget {
final DeviceModel? device;
const WaterHeaterPage({super.key, this.device});
@override
Widget build(BuildContext context) {
bool value = false;
return DefaultScaffold(
child: BlocProvider(
create: (context) =>
WaterHeaterBloc(switchCode: 'switch_1', whId: device?.uuid ?? '')
..add(const WaterHeaterInitial()),
child: BlocBuilder<WaterHeaterBloc, WaterHeaterState>(
builder: (context, state) {
final waterHeaterBloc = BlocProvider.of<WaterHeaterBloc>(context);
WHModel whModel = WHModel(firstCountDown: 0, firstSwitch: false);
if (state is LoadingNewSate) {
whModel = state.whModel;
} else if (state is UpdateState) {
whModel = state.whModel;
}
return state is WHLoadingState
? const Center(
child: DefaultContainer(
width: 50,
height: 50,
child: CircularProgressIndicator()),
)
: RefreshIndicator(
onRefresh: () async {
waterHeaterBloc.add(WaterHeaterInitial(
// groupScreen: device != null ? false : true
));
},
child: Center(
child: ListView(
shrinkWrap: true,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
overlayColor: MaterialStateProperty.all(
Colors.transparent),
onTap: () {
waterHeaterBloc.add(
WaterHeaterSwitch(
whSwitch:whModel.firstSwitch
),);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
// color: Colors.white.withOpacity(0.1),
borderRadius:
BorderRadius.circular(890),
boxShadow: [
BoxShadow(
color:
Colors.white.withOpacity(0.1),
blurRadius: 24,
offset: const Offset(-5, -5),
blurStyle: BlurStyle.outer,
),
BoxShadow(
color:
Colors.black.withOpacity(0.11),
blurRadius: 25,
offset: const Offset(5, 5),
blurStyle: BlurStyle.outer,
),
BoxShadow(
color:
Colors.black.withOpacity(0.13),
blurRadius: 30,
offset: const Offset(5, 5),
blurStyle: BlurStyle.inner,
),
],
),
child: SvgPicture.asset(
whModel.firstSwitch
? Assets.waterHeaterOn
: Assets.waterHeaterOff,
fit: BoxFit.fill,
),
),
],
),
),
const SizedBox(height: 80),
SizedBox(
child: Column(
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(100),
),
child: GestureDetector(
onTap: () {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
WHTimerScheduleScreen(
switchCode: 'switch_1', device: device!, deviceCode: 'countdown_1',
)));
},
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius:
BorderRadius.circular(100),
),
),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.circular(100),
),
child: Center(
child: Icon(
Icons.access_time,
color: ColorsManager
.primaryColorWithOpacity,
size: 25,
),
),
),
],
),
),
),
const SizedBox(height: 10),
BodySmall(
text: "Timer",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
),
),
],
),
)
],
),
],
),
),
);
},
),
),
);
}
}
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_app/generated/assets.dart';
class WaterHeaterSwitchIcon extends StatelessWidget {
const WaterHeaterSwitchIcon({super.key, required this.value, required this.action});
final bool value;
final Function action;
@override
Widget build(BuildContext context) {
return InkWell(
overlayColor: MaterialStateProperty.all(Colors.transparent),
onTap: () {
action();
},
child: ClipRRect(
borderRadius: BorderRadius.circular(190.0),
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurStyle: BlurStyle.inner,
color: Colors.black.withOpacity(0.1),
spreadRadius: 9,
blurRadius: 2,
offset: const Offset(3, 1),
),
],
),
child: SvgPicture.asset(
value ? Assets.waterHeaterOn : Assets.waterHeaterOff,
fit: BoxFit.fill,
),
),
),
);
}
}
@@ -0,0 +1,411 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/water_heater_bloc/water_heater_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/water_heater/Inching_widget.dart';
import 'package:syncrow_app/features/devices/view/widgets/water_heater/circulate_list_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/water_heater/circulate_widget.dart';
import 'package:syncrow_app/features/shared_widgets/create_schedule.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
import 'package:syncrow_app/features/shared_widgets/schedule_list.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.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';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
import '../../../bloc/water_heater_bloc/water_heater_event.dart';
class WHTimerScheduleScreen extends StatelessWidget {
final DeviceModel device;
final String deviceCode;
final String switchCode;
const WHTimerScheduleScreen(
{required this.device,
required this.deviceCode,
required this.switchCode,
super.key});
@override
Widget build(BuildContext context) {
return AnnotatedRegion(
value: SystemUiOverlayStyle(
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
statusBarIconBrightness: Brightness.light,
),
child: BlocProvider(
create: (context) =>
WaterHeaterBloc(switchCode: switchCode, whId: device.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode))
..add(GetScheduleEvent()),
child: BlocBuilder<WaterHeaterBloc, WaterHeaterState>(
builder: (context, state) {
final waterHeaterBloc = BlocProvider.of<WaterHeaterBloc>(context);
Duration duration = Duration.zero;
int countNum = 0;
if (state is UpdateTimerState) {
countNum = state.seconds;
} else if (state is TimerRunInProgress) {
countNum = state.remainingTime;
} else if (state is TimerRunComplete) {
countNum = 0;
} else if (state is LoadingNewSate) {
countNum = 0;
}
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (!didPop) {
waterHeaterBloc.add(OnClose());
Navigator.pop(context);
}
},
child: DefaultTabController(
length: 4,
child: DefaultScaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Schedule',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
actions: [
waterHeaterBloc.createSchedule == true
&& waterHeaterBloc.selectedTabIndex == 1 ? TextButton(
onPressed: () {
waterHeaterBloc.add(ScheduleSave());
},
child: const Text('Save'))
: waterHeaterBloc.selectedTabIndex == 1
? IconButton(
onPressed: () {
waterHeaterBloc.toggleCreateSchedule();
},
icon: const Icon(Icons.add),
)
: const SizedBox(),
waterHeaterBloc.createCirculate == true
&&waterHeaterBloc.selectedTabIndex==2 ? TextButton(
onPressed: () {
waterHeaterBloc.add(ScheduleSave());
},
child: const Text('Save'))
: waterHeaterBloc.selectedTabIndex == 2
? IconButton(
onPressed: () {
waterHeaterBloc.toggleCreateCirculate();
},
icon: const Icon(Icons.add),
)
: const SizedBox(),
],
),
child: state is WHLoadingState
? const Center(child: CircularProgressIndicator())
: Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
decoration: const ShapeDecoration(
color: ColorsManager.onPrimaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(30)),
),
),
child: TabBar(
indicatorPadding: EdgeInsets.zero,
padding: EdgeInsets.zero,
labelPadding: EdgeInsets.zero,
onTap: (value) {
if (value == 0) {
if (waterHeaterBloc.createSchedule == true) {
waterHeaterBloc.toggleCreateSchedule();
}
waterHeaterBloc.toggleSelectedIndex(value);
} else if (value == 2) {
if (waterHeaterBloc.createCirculate == true) {
waterHeaterBloc.toggleCreateCirculate();
}
waterHeaterBloc.toggleSelectedIndex(value);
} else {
waterHeaterBloc.toggleSelectedIndex(value);
}
},
indicatorColor: Colors.white,
dividerHeight: 0,
indicatorSize: TabBarIndicatorSize.tab,
indicator: const ShapeDecoration(
color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(20)),
),
),
isScrollable: false,
labelColor: Colors.white, // Text color when selected
unselectedLabelColor: ColorsManager.blackColor, // Text color when not selected
tabs: [
Tab(
icon: SvgPicture.asset(
Assets.scheduleTimeIcon,
color: waterHeaterBloc.selectedTabIndex == 0
? Colors.white
: ColorsManager.blackColor, // Change icon color based on selectedIndex
),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: BodySmall(
text: 'Countdown',
style: context.bodySmall.copyWith(
color: waterHeaterBloc.selectedTabIndex == 0
? Colors.white
: ColorsManager
.blackColor, // Text color based on selectedTabIndex
fontSize: 8,
fontWeight: FontWeight.w400,
),
),
),
),
Tab(
icon: SvgPicture.asset(
Assets.scheduleCelenderIcon,
color: waterHeaterBloc.selectedTabIndex == 1
? Colors.white
: ColorsManager.blackColor,
),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: Text(
'Schedule',
style: context.bodySmall.copyWith(
color: waterHeaterBloc.selectedTabIndex == 1
? Colors.white
: ColorsManager.blackColor,
fontSize: 8,
fontWeight: FontWeight.w400,
),
),
),
),
Tab(
icon: SvgPicture.asset(
Assets.scheduleCirculateIcon,
color: waterHeaterBloc.selectedTabIndex == 2
? Colors.white
: ColorsManager.blackColor,
),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: Text(
'Circulate',
style: context.bodySmall.copyWith(
color: waterHeaterBloc
.selectedTabIndex ==
2
? Colors.white
: ColorsManager.blackColor,
fontSize: 8,
fontWeight: FontWeight.w400,
),
),
),
),
Tab(
icon: SvgPicture.asset(
Assets.scheduleInchingIcon,
color: waterHeaterBloc
.selectedTabIndex ==
3
? Colors.white
: ColorsManager.blackColor,
),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: Text(
'Inching',
style: context.bodySmall.copyWith(
color: waterHeaterBloc
.selectedTabIndex ==
3
? Colors.white
: ColorsManager.blackColor,
fontSize: 8,
fontWeight: FontWeight.w400,
),
),
),
),
],
)),
Expanded(
child: TabBarView(
physics:
const NeverScrollableScrollPhysics(), // Disable swiping
children: [
Center(
child: Container(
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
countNum > 0
? BodyLarge(
text: _formatDuration(
countNum),
fontColor: ColorsManager
.slidingBlueColor,
fontSize: 40,
)
: CupertinoTimerPicker(
mode:
CupertinoTimerPickerMode
.hm,
onTimerDurationChanged:
(Duration
newDuration) {
duration = newDuration;
},
),
GestureDetector(
onTap: () {
if (state
is LoadingNewSate) {
return;
}
if (countNum > 0) {
waterHeaterBloc.add(
SetCounterValue(
deviceCode:
deviceCode,
duration: Duration
.zero));
} else if (duration !=
Duration.zero) {
waterHeaterBloc.add(
SetCounterValue(
deviceCode:
deviceCode,
duration:
duration));
}
},
child: SvgPicture.asset(
countNum > 0
? Assets.pauseIcon
: Assets.playIcon)),
],
),
),
),
Column(
mainAxisAlignment: waterHeaterBloc
.listSchedule.isNotEmpty
? MainAxisAlignment.start
: MainAxisAlignment.center,
children: [
SizedBox(
child: waterHeaterBloc.createSchedule == true
? CreateSchedule(
onToggleChanged: (bool isOn) {
waterHeaterBloc.toggleSchedule = isOn;
},
onDateTimeChanged: (DateTime dateTime) {
waterHeaterBloc.selectedTime = dateTime;
},
days: waterHeaterBloc.days,
selectDays: (List<String>
selectedDays) {
waterHeaterBloc
.selectedDays =
selectedDays;
},
)
: Padding(
padding: const EdgeInsets.only(top: 10),
child: ScheduleListView(
listSchedule: waterHeaterBloc.listSchedule, // Pass the schedule list here
onDismissed:
(scheduleId) {
waterHeaterBloc.listSchedule.removeWhere(
(schedule) => schedule.scheduleId == scheduleId);
waterHeaterBloc.add(
DeleteScheduleEvent(id: scheduleId));
},
onToggleSchedule: (scheduleId, isEnabled) {
waterHeaterBloc.add(ToggleScheduleEvent(
id: scheduleId, toggle: isEnabled,
));
},
),
),
),
],
),
Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
waterHeaterBloc.createCirculate == true
?
CirculateWidget(
isStartEndTime: true,
startTime: DateTime.now(),
endTime: DateTime.now(),
days: waterHeaterBloc.days,
selectedDays: [],
onToggleStartEndTime: (c) {},
onTimeChanged: (x, f) {},
onDaySelected: (p0) {},
):CirculateListView(
listSchedule: waterHeaterBloc.listSchedule, // Pass the schedule list here
onDismissed: (scheduleId) {
waterHeaterBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId);
waterHeaterBloc.add(DeleteScheduleEvent(id: scheduleId));
},
onToggleSchedule: (scheduleId, isEnabled) {
waterHeaterBloc.add(ToggleScheduleEvent(
id: scheduleId, toggle: isEnabled,
));
},
)
],
),
),
Column(children: [
SizedBox(height: 20),
Container(child: InchingWidget(),),],)
],
),
),
],
),
)));
},
),
),
);
}
String _formatDuration(int seconds) {
final hours = (seconds ~/ 3600).toString().padLeft(2, '0');
final minutes = ((seconds % 3600) ~/ 60).toString().padLeft(2, '0');
final secs = (seconds % 60).toString().padLeft(2, '0');
return '$hours:$minutes:$secs';
}
}