schedule for one gang and two gang and three gange

This commit is contained in:
mohammad
2024-09-18 12:59:28 +03:00
parent ddaf36797d
commit 42b5ff105f
24 changed files with 1872 additions and 631 deletions
@@ -20,7 +20,9 @@ class OneGangScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => OneGangBloc(oneGangId : device?.uuid ?? '')
create: (context) => OneGangBloc(
switchCode: 'switch_1',
oneGangId : device?.uuid ?? '')
..add(const InitialEvent(groupScreen:false)),
child: BlocBuilder<OneGangBloc, OneGangState>(
builder: (context, state) {
@@ -104,8 +106,9 @@ class OneGangScreen extends StatelessWidget {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => OneGangTimerScreen(
device: device,
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen(
switchCode:'switch_1' ,
device: device!,
deviceCode: 'countdown_1',
)));
},
@@ -7,7 +7,10 @@ import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_bloc.da
import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_event.dart';
import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/create_schedule.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/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';
@@ -15,10 +18,186 @@ 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';
class OneGangTimerScreen extends StatelessWidget {
final DeviceModel? device;
final String? deviceCode;
const OneGangTimerScreen({super.key,this.device,this.deviceCode});
// class OneGangTimerScreen extends StatelessWidget {
// final DeviceModel? device;
// final String? deviceCode;
// const OneGangTimerScreen({super.key,this.device,this.deviceCode});
//
// @override
// Widget build(BuildContext context) {
// return AnnotatedRegion(
// value: SystemUiOverlayStyle(
// statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
// statusBarIconBrightness: Brightness.light,
// ),
// child: Scaffold(
// backgroundColor: ColorsManager.backgroundColor,
// extendBodyBehindAppBar: true,
// extendBody: true,
// appBar: AppBar(
// backgroundColor: Colors.transparent,
// centerTitle: true,
// title: const BodyLarge(
// text: 'Schedule',
// fontColor: ColorsManager.primaryColor,
// fontWeight: FontsManager.bold,
// ),
// ),
// body: SafeArea(
// child: BlocProvider(
// create: (context) => OneGangBloc(
// switchCode: 'switch_1',
// oneGangId: device!.uuid ?? '')..
// ..add(GetCounterEvent(deviceCode: deviceCode!)),
// child: BlocBuilder<OneGangBloc, OneGangState>(
// builder: (context, state) {
// Duration duration = Duration.zero;
// int countNum = 0;
// int tabNum = 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;
// }
//
// if (state is ChangeSlidingSegmentState) {
// tabNum = state.value;
// }
// return PopScope(
// canPop: false,
// onPopInvoked: (didPop) {
// if (!didPop) {
// BlocProvider.of<OneGangBloc>(context).add(OnClose());
// Navigator.pop(context);
// }
// },
// child: Container(
// width: MediaQuery.sizeOf(context).width,
// height: MediaQuery.sizeOf(context).height,
// padding: const EdgeInsets.all(24),
// decoration: const BoxDecoration(
// image: DecorationImage(
// image: AssetImage(
// Assets.assetsImagesBackground,
// ),
// fit: BoxFit.cover,
// opacity: 0.4,
// ),
// ),
// child: state is LoadingInitialState || state is LoadingNewSate
// ? const Center(
// child: DefaultContainer(
// width: 50, height: 50, child: CircularProgressIndicator()),
// )
// : Column(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Container(
// width: MediaQuery.sizeOf(context).width,
// decoration: const ShapeDecoration(
// color: ColorsManager.slidingBlueColor,
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.all(Radius.circular(20)),
// ),
// ),
// child: CupertinoSlidingSegmentedControl<int>(
// thumbColor: ColorsManager.slidingBlueColor,
// onValueChanged: (value) {
// BlocProvider.of<OneGangBloc>(context)
// .add(ChangeSlidingSegment(value: value ?? 0));
// },
// groupValue:
// state is ChangeSlidingSegmentState ? state.value : 0,
// backgroundColor: Colors.white,
// children: <int, Widget>{
// 0: Container(
// padding: const EdgeInsets.symmetric(vertical: 10),
// child: BodySmall(
// text: 'Countdown',
// style: context.bodySmall.copyWith(
// color: ColorsManager.blackColor,
// fontSize: 12,
// fontWeight: FontWeight.w400,
// ),
// ),
// ),
// 1: Container(
// padding: const EdgeInsets.symmetric(vertical: 10),
// child: Text(
// 'Schedule',
// style: context.bodySmall.copyWith(
// color: ColorsManager.blackColor,
// fontSize: 12,
// fontWeight: FontWeight.w400,
// ),
// ),
// ),
// },
// ),
// ),
// if (tabNum == 0)
// countNum > 0
// ? BodyLarge(
// text: _formatDuration(countNum),
// fontColor: ColorsManager.slidingBlueColor,
// fontSize: 40,
// )
// : CupertinoTimerPicker(
// mode: CupertinoTimerPickerMode.hm,
// onTimerDurationChanged: (Duration newDuration) {
// duration = newDuration;
// },
// ),
// if (tabNum == 0)
// GestureDetector(
// onTap: () {
// if (state is LoadingNewSate) {
// return;
// }
// if (countNum > 0) {
// BlocProvider.of<OneGangBloc>(context).add(
// SetCounterValue(
// deviceCode: deviceCode!,
// duration: Duration.zero));
// } else if (duration != Duration.zero) {
// BlocProvider.of<OneGangBloc>(context).add(
// SetCounterValue(
// deviceCode: deviceCode!, duration: duration));
// }
// },
// child: SvgPicture.asset(
// countNum > 0 ? Assets.pauseIcon : Assets.playIcon))
// ],
// )));
// },
// ),
// ),
// ),
// ),
// );
// }
// 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';
// }
// }
class TimerScheduleScreen extends StatelessWidget {
final DeviceModel device;
final String deviceCode;
final String switchCode;
const TimerScheduleScreen(
{required this.device,
required this.deviceCode,
required this.switchCode,
super.key});
@override
Widget build(BuildContext context) {
@@ -27,90 +206,102 @@ class OneGangTimerScreen extends StatelessWidget {
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
statusBarIconBrightness: Brightness.light,
),
child: Scaffold(
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Schedule',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
),
body: SafeArea(
child: BlocProvider(
create: (context) => OneGangBloc(oneGangId: device!.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode!)),
child: BlocBuilder<OneGangBloc, OneGangState>(
builder: (context, state) {
Duration duration = Duration.zero;
int countNum = 0;
int tabNum = 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;
}
if (state is ChangeSlidingSegmentState) {
tabNum = state.value;
}
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (!didPop) {
BlocProvider.of<OneGangBloc>(context).add(OnClose());
Navigator.pop(context);
}
},
child: Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
padding: const EdgeInsets.all(24),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
Assets.assetsImagesBackground,
),
fit: BoxFit.cover,
opacity: 0.4,
),
child: BlocProvider(
create: (context) =>
OneGangBloc(switchCode: switchCode, oneGangId: device.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode))
..add(GetScheduleEvent()),
child: BlocBuilder<OneGangBloc, OneGangState>(
builder: (context, state) {
final oneGangBloc = BlocProvider.of<OneGangBloc>(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) {
oneGangBloc.add(OnClose());
Navigator.pop(context);
}
},
child: DefaultTabController(
length: 2,
child: DefaultScaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Schedule',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
child: state is LoadingInitialState || state is LoadingNewSate
? const Center(
child: DefaultContainer(
width: 50, height: 50, child: CircularProgressIndicator()),
)
: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.sizeOf(context).width,
decoration: const ShapeDecoration(
actions: [
oneGangBloc.createSchedule == true ?
TextButton(
onPressed: () {
oneGangBloc.add(ThreeGangSave());
},
child: const Text('Save')
) :
oneGangBloc.selectedTabIndex==1? IconButton(
onPressed: () {
oneGangBloc.toggleCreateSchedule();
},
icon: const Icon(Icons.add),
):SizedBox(),
],
),
child:
state is LoadingInitialState?
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(
onTap: (value) {
if(value==0){
if(oneGangBloc.createSchedule == true){
oneGangBloc.toggleCreateSchedule();
}
oneGangBloc.toggleSelectedIndex(0);
}else{
oneGangBloc.toggleSelectedIndex(1);
}
},
indicatorColor: Colors.white, // Customize the indicator
dividerHeight: 0,
// indicatorWeight: MediaQuery.of(context).size.width,
// indicatorSize: ,
indicatorSize: TabBarIndicatorSize.tab,
indicator: const ShapeDecoration(
color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
),
child: CupertinoSlidingSegmentedControl<int>(
thumbColor: ColorsManager.slidingBlueColor,
onValueChanged: (value) {
BlocProvider.of<OneGangBloc>(context)
.add(ChangeSlidingSegment(value: value ?? 0));
},
groupValue:
state is ChangeSlidingSegmentState ? state.value : 0,
backgroundColor: Colors.white,
children: <int, Widget>{
0: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
tabs: [
Tab(
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: BodySmall(
text: 'Countdown',
style: context.bodySmall.copyWith(
@@ -120,7 +311,9 @@ class OneGangTimerScreen extends StatelessWidget {
),
),
),
1: Container(
),
Tab(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
'Schedule',
@@ -131,50 +324,106 @@ class OneGangTimerScreen extends StatelessWidget {
),
),
),
},
),
),
],
),
if (tabNum == 0)
countNum > 0
? BodyLarge(
text: _formatDuration(countNum),
fontColor: ColorsManager.slidingBlueColor,
fontSize: 40,
)
: CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm,
onTimerDurationChanged: (Duration newDuration) {
duration = newDuration;
},
),
if (tabNum == 0)
GestureDetector(
onTap: () {
if (state is LoadingNewSate) {
return;
}
if (countNum > 0) {
BlocProvider.of<OneGangBloc>(context).add(
SetCounterValue(
deviceCode: deviceCode!,
duration: Duration.zero));
} else if (duration != Duration.zero) {
BlocProvider.of<OneGangBloc>(context).add(
SetCounterValue(
deviceCode: deviceCode!, duration: duration));
}
},
child: SvgPicture.asset(
countNum > 0 ? Assets.pauseIcon : Assets.playIcon))
],
)));
},
),
),
),
Expanded(
child: TabBarView(
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) {
oneGangBloc.add(SetCounterValue(
deviceCode: deviceCode,
duration: Duration.zero));
} else if (duration != Duration.zero) {
oneGangBloc.add(SetCounterValue(
deviceCode: deviceCode,
duration: duration));
}
},
child: SvgPicture.asset(countNum > 0
? Assets.pauseIcon
: Assets.playIcon)),
],
),
),
),
Column(
mainAxisAlignment:oneGangBloc.listSchedule.isNotEmpty?
MainAxisAlignment.start:MainAxisAlignment.center,
children: [
SizedBox(
child: oneGangBloc.createSchedule == true ?
CreateSchedule(
onToggleChanged: (bool isOn) {
oneGangBloc.toggleSchedule = isOn;
},
onDateTimeChanged: (DateTime dateTime) {
oneGangBloc.selectedTime=dateTime;
},
days: oneGangBloc.days,
selectDays: (List<String> selectedDays) {
oneGangBloc.selectedDays = selectedDays;
},
)
:
Padding(
padding: const EdgeInsets.only(top: 10),
child: ScheduleListView(
listSchedule: oneGangBloc.listSchedule, // Pass the schedule list here
onDismissed: (scheduleId) {
oneGangBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId);
oneGangBloc.add(DeleteScheduleEvent(id: scheduleId));
},
onToggleSchedule: (scheduleId, isEnabled) {
oneGangBloc.add(ToggleScheduleEvent(
id: scheduleId,
toggle: isEnabled,
));
},
),
),
),
],
),
],
),
),
],
),
))
);
},
),
),
);
}
String _formatDuration(int seconds) {
final hours = (seconds ~/ 3600).toString().padLeft(2, '0');
final minutes = ((seconds % 3600) ~/ 60).toString().padLeft(2, '0');
@@ -63,7 +63,8 @@ class ScheduleScreen extends StatelessWidget {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TimerScreen(
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen(
switchCode :"switch_1",
device: device,
deviceCode: 'countdown_1',
)));
@@ -99,10 +100,11 @@ class ScheduleScreen extends StatelessWidget {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TimerScreen(
device: device,
deviceCode: 'countdown_2',
)));
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen(
switchCode :"switch_2",
device: device,
deviceCode: 'countdown_2',
)));
},
child: Container(
padding:
@@ -135,8 +137,9 @@ class ScheduleScreen extends StatelessWidget {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TimerScreen(
device: device,
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen(
switchCode :"switch_3",
device: device,
deviceCode: 'countdown_3',
)));
},
@@ -22,7 +22,9 @@ class ThreeGangScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => ThreeGangBloc(threeGangId: device?.uuid ?? '')
create: (context) => ThreeGangBloc(
switchCode: '',
threeGangId: device?.uuid ?? '')
..add(InitialEvent(groupScreen: device != null ? false : true)),
child: BlocBuilder<ThreeGangBloc, ThreeGangState>(
builder: (context, state) {
@@ -7,7 +7,10 @@ import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_blo
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/create_schedule.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/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';
@@ -15,10 +18,254 @@ 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';
class TimerScreen extends StatelessWidget {
// class TimerScreen extends StatelessWidget {
// final DeviceModel device;
// final String deviceCode;
// final String switchCode;
// const TimerScreen(
// {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) => ThreeGangBloc(
// switchCode: switchCode, threeGangId: device.uuid ?? '')..add(GetScheduleEvent())
// ..add(GetCounterEvent(deviceCode: deviceCode)),
// child: BlocBuilder<ThreeGangBloc, ThreeGangState>(
// builder: (context, state) {
// final threeGangBloc = BlocProvider.of<ThreeGangBloc>(context);
//
// Duration duration = Duration.zero;
// int countNum = 0;
// int tabNum = 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;
// }
//
// if (state is ChangeSlidingSegmentState) {
// tabNum = state.value;
// }
// return Scaffold(
// backgroundColor: ColorsManager.backgroundColor,
// extendBodyBehindAppBar: true,
// extendBody: true,
// appBar: AppBar(
// backgroundColor: Colors.transparent,
// centerTitle: true,
// title: const BodyLarge(
// text: 'Schedule',
// fontColor: ColorsManager.primaryColor,
// fontWeight: FontsManager.bold,
// ),
// actions: [
// if (tabNum == 1)
// threeGangBloc.createSchedule == true
// ? TextButton(onPressed: () {
// threeGangBloc.add(ThreeGangSave() );
// }, child: const Text('Save'))
// : IconButton(
// onPressed: () {
// threeGangBloc.toggleCreateSchedule();
// },
// icon: const Icon(Icons.add),
// ),
// ],
// ),
// body: SafeArea(
// child:PopScope(
// canPop: false,
// onPopInvoked: (didPop) {
// if (!didPop) {
// BlocProvider.of<ThreeGangBloc>(context).add(OnClose());
// Navigator.pop(context);
// }
// },
// child: Container(
// width: MediaQuery.sizeOf(context).width,
// padding: const EdgeInsets.all(24),
// decoration: const BoxDecoration(
// image: DecorationImage(
// image: AssetImage(
// Assets.assetsImagesBackground,
// ),
// fit: BoxFit.cover,
// opacity: 0.4,
// ),
// ),
// child: state is LoadingInitialState ||
// state is LoadingNewSate
// ? const Center(
// child: DefaultContainer(
// width: 50,
// height: 50,
// child: CircularProgressIndicator()),
// )
// : Column(
// children: [
// Container(
// width: MediaQuery.sizeOf(context).width,
// decoration: const ShapeDecoration(
// color: ColorsManager.slidingBlueColor,
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.all(
// Radius.circular(20)),
// ),
// ),
// child:
// CupertinoSlidingSegmentedControl<int>(
// thumbColor:
// ColorsManager.slidingBlueColor,
// onValueChanged: (value) {
// BlocProvider.of<ThreeGangBloc>(context)
// .add(ChangeSlidingSegment(
// value: value ?? 0));
// },
// groupValue:
// state is ChangeSlidingSegmentState
// ? state.value
// : 0,
// backgroundColor: Colors.white,
// children: <int, Widget>{
// 0: Container(
// padding: const EdgeInsets.symmetric(
// vertical: 10),
// child: BodySmall(
// text: 'Countdown',
// style: context.bodySmall.copyWith(
// color: ColorsManager.blackColor,
// fontSize: 12,
// fontWeight: FontWeight.w400,
// ),
// ),
// ),
// 1: Container(
// padding: const EdgeInsets.symmetric(
// vertical: 10),
// child: Text(
// 'Schedule',
// style: context.bodySmall.copyWith(
// color: ColorsManager.blackColor,
// fontSize: 12,
// fontWeight: FontWeight.w400,
// ),
// ),
// ),
// },
// ),
// ),
// if (tabNum == 0)
// countNum > 0
// ? BodyLarge(
// text: _formatDuration(countNum),
// fontColor:
// ColorsManager.slidingBlueColor,
// fontSize: 40,
// )
// : CupertinoTimerPicker(
// mode: CupertinoTimerPickerMode.hm,
// onTimerDurationChanged:
// (Duration newDuration) {
// duration = newDuration;
// },
// ),
// if (tabNum == 0)
// GestureDetector(
// onTap: () {
// if (state is LoadingNewSate) {
// return;
// }
// if (countNum > 0) {
// BlocProvider.of<ThreeGangBloc>(
// context)
// .add(SetCounterValue(
// deviceCode: deviceCode,
// duration: Duration.zero));
// } else if (duration !=
// Duration.zero) {
// BlocProvider.of<ThreeGangBloc>(
// context)
// .add(SetCounterValue(
// deviceCode: deviceCode,
// duration: duration));
// }
// },
// child: SvgPicture.asset(countNum > 0
// ? Assets.pauseIcon
// : Assets.playIcon)),
// if (tabNum == 1)
// SizedBox(
// child: threeGangBloc.createSchedule == true
// ? CreateSchedule(
// onToggleChanged: (bool isOn) {
// threeGangBloc.toggleSchedule = isOn;
// },
// onDateTimeChanged: (DateTime dateTime) {
// threeGangBloc.selectedTime = dateTime;
// },
// days: threeGangBloc.days,
// selectDays: (List<String>selectedDays) {
// threeGangBloc.selectedDays = selectedDays;
// },
// ) : SizedBox(
// height: MediaQuery.of(context).size.height/1.9,
// child: ScheduleListView(
// listSchedule: threeGangBloc.listSchedule, // Pass the schedule list here
// onDismissed: (scheduleId) {
// threeGangBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId);
// threeGangBloc.add(DeleteScheduleEvent(id: scheduleId));
// },
// onToggleSchedule: (scheduleId, isEnabled) {
// threeGangBloc.add(ToggleScheduleEvent(
// id: scheduleId,
// toggle: isEnabled,
// ));
// },
// ),
// ))
// ],
// )))
// ),
// );
// },
// ),
// ),
// );
// }
//
// 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';
// }
// }
class TimerScheduleScreen extends StatelessWidget {
final DeviceModel device;
final String deviceCode;
const TimerScreen({required this.device, required this.deviceCode, super.key});
final String switchCode;
const TimerScheduleScreen(
{required this.device,
required this.deviceCode,
required this.switchCode,
super.key});
@override
Widget build(BuildContext context) {
@@ -27,150 +274,219 @@ class TimerScreen extends StatelessWidget {
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
statusBarIconBrightness: Brightness.light,
),
child: Scaffold(
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Schedule',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
),
body: SafeArea(
child: BlocProvider(
create: (context) => ThreeGangBloc(threeGangId: device.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode)),
child: BlocBuilder<ThreeGangBloc, ThreeGangState>(
builder: (context, state) {
Duration duration = Duration.zero;
int countNum = 0;
int tabNum = 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;
}
if (state is ChangeSlidingSegmentState) {
tabNum = state.value;
}
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (!didPop) {
BlocProvider.of<ThreeGangBloc>(context).add(OnClose());
Navigator.pop(context);
}
},
child: Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
padding: const EdgeInsets.all(24),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
Assets.assetsImagesBackground,
),
fit: BoxFit.cover,
opacity: 0.4,
),
child: BlocProvider(
create: (context) =>
ThreeGangBloc(switchCode: switchCode, threeGangId: device.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode))
..add(GetScheduleEvent()),
child: BlocBuilder<ThreeGangBloc, ThreeGangState>(
builder: (context, state) {
final threeGangBloc = BlocProvider.of<ThreeGangBloc>(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) {
threeGangBloc.add(OnClose());
Navigator.pop(context);
}
},
child: DefaultTabController(
length: 2,
child: DefaultScaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Schedule',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
child: state is LoadingInitialState || state is LoadingNewSate
? const Center(
child: DefaultContainer(
width: 50, height: 50, child: CircularProgressIndicator()),
)
: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.sizeOf(context).width,
decoration: const ShapeDecoration(
color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
actions: [
threeGangBloc.createSchedule == true ?
TextButton(
onPressed: () {
threeGangBloc.add(ThreeGangSave());
},
child: const Text('Save')
) :
threeGangBloc.selectedTabIndex==1? IconButton(
onPressed: () {
threeGangBloc.toggleCreateSchedule();
},
icon: const Icon(Icons.add),
):SizedBox(),
],
),
child:
state is LoadingInitialState?
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(
onTap: (value) {
if(value==0){
if(threeGangBloc.createSchedule == true){
threeGangBloc.toggleCreateSchedule();
}
threeGangBloc.toggleSelectedIndex(0);
}else{
threeGangBloc.toggleSelectedIndex(1);
}
},
indicatorColor: Colors.white, // Customize the indicator
dividerHeight: 0,
// indicatorWeight: MediaQuery.of(context).size.width,
// indicatorSize: ,
indicatorSize: TabBarIndicatorSize.tab,
indicator: const ShapeDecoration(
color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
),
tabs: [
Tab(
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: BodySmall(
text: 'Countdown',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
child: CupertinoSlidingSegmentedControl<int>(
thumbColor: ColorsManager.slidingBlueColor,
onValueChanged: (value) {
BlocProvider.of<ThreeGangBloc>(context)
.add(ChangeSlidingSegment(value: value ?? 0));
},
groupValue:
state is ChangeSlidingSegmentState ? state.value : 0,
backgroundColor: Colors.white,
children: <int, Widget>{
0: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: BodySmall(
text: 'Countdown',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
),
1: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
'Schedule',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
),
},
),
),
Tab(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
'Schedule',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
),
if (tabNum == 0)
countNum > 0
? BodyLarge(
text: _formatDuration(countNum),
fontColor: ColorsManager.slidingBlueColor,
fontSize: 40,
)
: CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm,
onTimerDurationChanged: (Duration newDuration) {
duration = newDuration;
},
),
if (tabNum == 0)
GestureDetector(
onTap: () {
if (state is LoadingNewSate) {
return;
}
if (countNum > 0) {
BlocProvider.of<ThreeGangBloc>(context).add(
SetCounterValue(
),
],
),
),
Expanded(
child: TabBarView(
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) {
threeGangBloc.add(SetCounterValue(
deviceCode: deviceCode,
duration: Duration.zero));
} else if (duration != Duration.zero) {
BlocProvider.of<ThreeGangBloc>(context).add(
SetCounterValue(
deviceCode: deviceCode, duration: duration));
}
} else if (duration != Duration.zero) {
threeGangBloc.add(SetCounterValue(
deviceCode: deviceCode,
duration: duration));
}
},
child: SvgPicture.asset(countNum > 0
? Assets.pauseIcon
: Assets.playIcon)),
],
),
),
),
Column(
mainAxisAlignment:threeGangBloc.listSchedule.isNotEmpty?
MainAxisAlignment.start:MainAxisAlignment.center,
children: [
SizedBox(
child: threeGangBloc.createSchedule == true ?
CreateSchedule(
onToggleChanged: (bool isOn) {
threeGangBloc.toggleSchedule = isOn;
},
child: SvgPicture.asset(
countNum > 0 ? Assets.pauseIcon : Assets.playIcon))
],
)));
},
),
),
onDateTimeChanged: (DateTime dateTime) {
threeGangBloc.selectedTime=dateTime;
},
days: threeGangBloc.days,
selectDays: (List<String> selectedDays) {
threeGangBloc.selectedDays = selectedDays;
},
)
:
Padding(
padding: const EdgeInsets.only(top: 10),
child: ScheduleListView(
listSchedule: threeGangBloc.listSchedule, // Pass the schedule list here
onDismissed: (scheduleId) {
threeGangBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId);
threeGangBloc.add(DeleteScheduleEvent(id: scheduleId));
},
onToggleSchedule: (scheduleId, isEnabled) {
threeGangBloc.add(ToggleScheduleEvent(
id: scheduleId,
toggle: isEnabled,
));
},
),
),
),
],
),
],
),
),
],
),
))
);
},
),
),
);
@@ -15,14 +15,16 @@ import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class TwoGangScreen extends StatelessWidget {
const TwoGangScreen({super.key, this.device});
const TwoGangScreen({super.key, this.device, this.switchCode});
final DeviceModel? device;
final String? switchCode;
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => TwoGangBloc(twoGangId: device?.uuid ?? '')
create: (context) => TwoGangBloc(
switchCode: switchCode??'',
twoGangId: device?.uuid ?? '')
..add(InitialEvent(groupScreen: device != null ? false : true)),
child: BlocBuilder<TwoGangBloc, TwoGangState>(
builder: (context, state) {
@@ -35,7 +37,6 @@ class TwoGangScreen extends StatelessWidget {
List<GroupTwoGangModel> groupTwoGangModel = [];
bool allSwitchesOn = false;
if (state is LoadingNewSate) {
twoGangModel = state.twoGangModel;
} else if (state is UpdateState) {
@@ -46,9 +47,7 @@ class TwoGangScreen extends StatelessWidget {
}
return state is LoadingInitialState
? const Center(
child:
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
)
child: DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),)
: device == null
? TwoGangList(
twoGangList: groupTwoGangModel,
@@ -63,9 +63,10 @@ class TwoGangScheduleScreen extends StatelessWidget {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TwoTimerScreen(
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen(
device: device,
deviceCode: 'countdown_1',
switchCode:'switch_1' ,
)));
},
child: Container(
@@ -75,7 +76,7 @@ class TwoGangScheduleScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
BodySmall(
text: "Bedside Light",
text: "Cove Light",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
fontSize: 15,
@@ -99,9 +100,10 @@ class TwoGangScheduleScreen extends StatelessWidget {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TwoTimerScreen(
pageBuilder: (context, animation1, animation2) => TimerScheduleScreen(
device: device,
deviceCode: 'countdown_2',
switchCode:'switch_2' ,
)));
},
child: Container(
@@ -111,7 +113,7 @@ class TwoGangScheduleScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
BodySmall(
text: "Ceiling Light",
text: "Chandelier",
style: context.bodyMedium.copyWith(
color: ColorsManager.textPrimaryColor,
fontSize: 15,
@@ -7,10 +7,9 @@ import 'package:syncrow_app/features/devices/bloc/two_gang_bloc/two_gang_bloc.da
import 'package:syncrow_app/features/devices/bloc/two_gang_bloc/two_gang_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/create_schedule.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/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_medium.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';
@@ -18,11 +17,15 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
import 'package:syncrow_app/features/devices/bloc/two_gang_bloc/two_gang_event.dart';
class TwoTimerScreen extends StatelessWidget {
class TimerScheduleScreen extends StatelessWidget {
final DeviceModel device;
final String deviceCode;
const TwoTimerScreen(
{required this.device, required this.deviceCode, super.key});
final String switchCode;
const TimerScheduleScreen(
{required this.device,
required this.deviceCode,
required this.switchCode,
super.key});
@override
Widget build(BuildContext context) {
@@ -32,15 +35,15 @@ class TwoTimerScreen extends StatelessWidget {
statusBarIconBrightness: Brightness.light,
),
child: BlocProvider(
create: (context) => TwoGangBloc(twoGangId: device.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode)),
create: (context) =>
TwoGangBloc(switchCode: switchCode, twoGangId: device.uuid ?? '')
..add(GetCounterEvent(deviceCode: deviceCode))
..add(GetScheduleEvent()),
child: BlocBuilder<TwoGangBloc, TwoGangState>(
builder: (context, state) {
final twoGangBloc = BlocProvider.of<TwoGangBloc>(context);
Duration duration = Duration.zero;
int countNum = 0;
int tabNum = 0;
if (state is UpdateTimerState) {
countNum = state.seconds;
} else if (state is TimerRunInProgress) {
@@ -49,228 +52,197 @@ class TwoTimerScreen extends StatelessWidget {
countNum = 0;
} else if (state is LoadingNewSate) {
countNum = 0;
} else if (state is ChangeSlidingSegmentState) {
tabNum = state.value;
}
return Scaffold(
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Schedule',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
actions: [
if (tabNum == 1)
twoGangBloc.createSchedule == true
? TextButton(onPressed: () {}, child: const Text('Save'))
: IconButton(
return PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (!didPop) {
twoGangBloc.add(OnClose());
Navigator.pop(context);
}
},
child: DefaultTabController(
length: 2,
child: DefaultScaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
title: const BodyLarge(
text: 'Schedule',
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
actions: [
twoGangBloc.createSchedule == true ?
TextButton(
onPressed: () {
twoGangBloc.add(TwoGangSave());
},
child: const Text('Save')
) :
twoGangBloc.selectedTabIndex==1? IconButton(
onPressed: () {
twoGangBloc.toggleCreateSchedule();
},
icon: const Icon(Icons.add),
),
],
),
body: SafeArea(
child: PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (!didPop) {
BlocProvider.of<TwoGangBloc>(context).add(OnClose());
Navigator.pop(context);
}
},
child: Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
padding: const EdgeInsets.all(24),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(Assets.assetsImagesBackground),
fit: BoxFit.cover,
opacity: 0.4,
):SizedBox(),
],
),
),
child: state is LoadingInitialState ||
state is LoadingNewSate
? const Center(
child: DefaultContainer(
width: 50,
height: 50,
child: CircularProgressIndicator(),
child:
state is LoadingInitialState?
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)),
),
),
)
: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.sizeOf(context).width,
decoration: const ShapeDecoration(
color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
),
child: CupertinoSlidingSegmentedControl<int>(
thumbColor: ColorsManager.slidingBlueColor,
onValueChanged: (value) {
BlocProvider.of<TwoGangBloc>(context).add(
ChangeSlidingSegment(
value: value ?? 0));
},
groupValue: state is ChangeSlidingSegmentState
? state.value
: 0,
backgroundColor: Colors.white,
children: <int, Widget>{
0: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: BodySmall(
text: 'Countdown',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
),
1: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: Text(
'Schedule',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
),
},
child: TabBar(
onTap: (value) {
print(value);
if(value==0){
if(twoGangBloc.createSchedule == true){
twoGangBloc.toggleCreateSchedule();
}
twoGangBloc.toggleSelectedIndex(0);
}else{
twoGangBloc.toggleSelectedIndex(1);
}
},
indicatorColor: Colors.white, // Customize the indicator
dividerHeight: 0,
indicatorSize: TabBarIndicatorSize.tab,
indicator: const ShapeDecoration(
color: ColorsManager.slidingBlueColor,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20)),
),
),
if (tabNum == 0)
countNum > 0
? BodyLarge(
text: _formatDuration(countNum),
fontColor:
ColorsManager.slidingBlueColor,
fontSize: 40,
)
: CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm,
onTimerDurationChanged:
(Duration newDuration) {
duration = newDuration;
},
tabs: [
Tab(
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10),
child: BodySmall(
text: 'Countdown',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
if (tabNum == 0)
GestureDetector(
onTap: () {
if (state is LoadingNewSate) {
return;
}
if (countNum > 0) {
BlocProvider.of<TwoGangBloc>(context)
.add(SetCounterValue(
deviceCode: deviceCode,
duration: Duration.zero));
} else if (duration != Duration.zero) {
BlocProvider.of<TwoGangBloc>(context)
.add(SetCounterValue(
deviceCode: deviceCode,
duration: duration));
}
},
child: SvgPicture.asset(countNum > 0
? Assets.pauseIcon
: Assets.playIcon)),
if (tabNum == 1)
SizedBox(
height:
MediaQuery.of(context).size.height / 2,
child: twoGangBloc.createSchedule == true
? CreateSchedule(
onToggleChanged: (bool isOn) {
print(
'Toggle is now: ${isOn ? "ON" : "OFF"}');
},
onDateTimeChanged:
(DateTime dateTime) {
print('Selected Time: $dateTime');
},
days: twoGangBloc.days,
selectDays:
(List<String> selectedDays) {
twoGangBloc.selectedDays =
selectedDays;
print(
'Selected Days: ${twoGangBloc.selectedDays}');
},
)
: Center(
child: twoGangBloc.listSchedule.isNotEmpty?
Container(
height: MediaQuery.of(context).size.height / 2,
child: ListView.builder(
itemCount: twoGangBloc.listSchedule.length,
itemBuilder: (context, index) {
return
Dismissible(
key: Key( twoGangBloc.listSchedule[index].id),
child: InkWell(
onTap: () {},
child:
DefaultContainer(
padding: EdgeInsets.all(20),
height: MediaQuery.of(context).size.height / 8,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(twoGangBloc.listSchedule[index].time),
Text(twoGangBloc.listSchedule[index].days.toString()),
Text(twoGangBloc.listSchedule[index].enable.toString())
],
),
),
Expanded(child:ListTile(
contentPadding: EdgeInsets.zero,
leading: const BodyMedium(
text: '',
fontWeight: FontWeight.normal,
),
trailing: Transform.scale(
scale: .8,
child: CupertinoSwitch(
value: true,
onChanged: (value) {
// smartDoorBloc.add(ToggleRepeatEvent());
},
applyTheme: true,
)),
),)
],
))));
},),
):
EmptySchedule()),
)
],
),
),
),
Tab(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
'Schedule',
style: context.bodySmall.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
),
),
],
),
),
),
),
),
Expanded(
child: TabBarView(
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) {
twoGangBloc.add(SetCounterValue(
deviceCode: deviceCode,
duration: Duration.zero));
} else if (duration != Duration.zero) {
twoGangBloc.add(SetCounterValue(
deviceCode: deviceCode,
duration: duration));
}
},
child: SvgPicture.asset(countNum > 0
? Assets.pauseIcon
: Assets.playIcon)),
],
),
),
),
Column(
mainAxisAlignment:twoGangBloc.listSchedule.isNotEmpty?
MainAxisAlignment.start:MainAxisAlignment.center,
children: [
SizedBox(
child: twoGangBloc.createSchedule == true ?
CreateSchedule(
onToggleChanged: (bool isOn) {
twoGangBloc.toggleSchedule = isOn;
},
onDateTimeChanged: (DateTime dateTime) {
twoGangBloc.selectedTime=dateTime;
},
days: twoGangBloc.days,
selectDays: (List<String> selectedDays) {
twoGangBloc.selectedDays = selectedDays;
},
)
:
Padding(
padding: const EdgeInsets.only(top: 10),
child: ScheduleListView(
listSchedule: twoGangBloc.listSchedule, // Pass the schedule list here
onDismissed: (scheduleId) {
twoGangBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId);
twoGangBloc.add(DeleteScheduleEvent(id: scheduleId));
},
onToggleSchedule: (scheduleId, isEnabled) {
twoGangBloc.add(ToggleScheduleEvent(
id: scheduleId,
toggle: isEnabled,
));
},
),
),
),
],
),
],
),
),
],
),
))
);
},
),