mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 11:27:54 +00:00
count_down_ac
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CustomHalfHourPicker extends StatefulWidget {
|
||||
final Function(double) onValueChanged;
|
||||
|
||||
const CustomHalfHourPicker({Key? key, required this.onValueChanged})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_CustomHalfHourPickerState createState() => _CustomHalfHourPickerState();
|
||||
}
|
||||
|
||||
class _CustomHalfHourPickerState extends State<CustomHalfHourPicker> {
|
||||
double selectedValue = 0.0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 200,
|
||||
child: ListWheelScrollView.useDelegate(
|
||||
itemExtent: 50,
|
||||
perspective: 0.005,
|
||||
physics: const FixedExtentScrollPhysics(),
|
||||
overAndUnderCenterOpacity: 0.3,
|
||||
onSelectedItemChanged: (index) {
|
||||
setState(() {
|
||||
selectedValue =
|
||||
index * 0.5; // Convert index to half-hour increments
|
||||
widget.onValueChanged(selectedValue);
|
||||
});
|
||||
},
|
||||
childDelegate: ListWheelChildBuilderDelegate(
|
||||
builder: (context, index) {
|
||||
if (index < 0 || index > 48)
|
||||
return null; // Limit to 24.0 (48 * 0.5)
|
||||
return Center(
|
||||
child: Text(
|
||||
(index * 0.5)
|
||||
.toStringAsFixed(1), // Display value as 0.0, 0.5, etc.
|
||||
style: const TextStyle(
|
||||
fontSize: 25,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w800),
|
||||
),
|
||||
);
|
||||
},
|
||||
childCount: 49, // 0.0 to 24.0 (inclusive)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ class AcInterface extends StatelessWidget {
|
||||
},
|
||||
builder: (context, state) {
|
||||
AcStatusModel statusModel = AcStatusModel(
|
||||
countdown1: 0,
|
||||
uuid: ac.uuid ?? '',
|
||||
acSwitch: true,
|
||||
modeString: 'hot',
|
||||
|
||||
@@ -7,11 +7,13 @@ import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_timer_page.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
|
||||
class AcInterfaceControls extends StatelessWidget {
|
||||
const AcInterfaceControls({super.key, required this.deviceModel, required this.deviceStatus});
|
||||
const AcInterfaceControls(
|
||||
{super.key, required this.deviceModel, required this.deviceStatus});
|
||||
|
||||
final DeviceModel deviceModel;
|
||||
final AcStatusModel deviceStatus;
|
||||
@@ -20,8 +22,9 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
String lockIconName =
|
||||
deviceStatus.childLock ? Assets.assetsIconsLock : Assets.assetsIconsUnLock;
|
||||
String lockIconName = deviceStatus.childLock
|
||||
? Assets.assetsIconsLock
|
||||
: Assets.assetsIconsUnLock;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@@ -34,11 +37,22 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
children: [
|
||||
Flexible(
|
||||
child: GestureDetector(
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation1, animation2) =>
|
||||
AcTimerPage(
|
||||
device: deviceModel,
|
||||
deviceCode: deviceModel.type!,
|
||||
switchCode: '',
|
||||
)));
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: SvgPicture.asset(Assets.assetsIconsAutomatedClock),
|
||||
child:
|
||||
SvgPicture.asset(Assets.assetsIconsAutomatedClock),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
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/svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/CustomHalfHourTimerPicker.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||
|
||||
class AcTimerPage extends StatelessWidget {
|
||||
final DeviceModel device;
|
||||
final String deviceCode;
|
||||
final String switchCode;
|
||||
const AcTimerPage(
|
||||
{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) => ACsBloc(acId: device.uuid ?? ''),
|
||||
child: BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
final oneGangBloc = BlocProvider.of<ACsBloc>(context);
|
||||
Duration duration = Duration.zero;
|
||||
int selectedValue = 0;
|
||||
|
||||
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: 'Countdown',
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
fontWeight: FontsManager.bold,
|
||||
),
|
||||
),
|
||||
child: state is AcsLoadingState
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
decoration: const ShapeDecoration(
|
||||
color: ColorsManager.onPrimaryColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(30)),
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Container(
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
countNum > 0
|
||||
? BodyLarge(
|
||||
text: formatDuration(countNum),
|
||||
fontColor: ColorsManager
|
||||
.slidingBlueColor,
|
||||
fontSize: 40,
|
||||
)
|
||||
: Container(
|
||||
child: CustomHalfHourPicker(
|
||||
onValueChanged: (value) {
|
||||
selectedValue =
|
||||
(value * 10).toInt();
|
||||
if (selectedValue == 5) {
|
||||
duration = const Duration(
|
||||
minutes:
|
||||
30); // 0.5 translates to 30 minutes
|
||||
countNum =
|
||||
duration.inSeconds;
|
||||
} else {
|
||||
duration = Duration(
|
||||
minutes: selectedValue *
|
||||
6); // Each step represents 6 minutes
|
||||
countNum =
|
||||
duration.inSeconds;
|
||||
}
|
||||
print(
|
||||
"Selected Value: $selectedValue, Duration: $duration");
|
||||
},
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (state is LoadingNewSate) {
|
||||
return;
|
||||
}
|
||||
if (countNum > 0) {
|
||||
oneGangBloc.add(SetCounterValue(
|
||||
seconds: countNum,
|
||||
deviceCode:
|
||||
'countdown_time',
|
||||
duration: selectedValue));
|
||||
} else if (duration !=
|
||||
Duration.zero) {
|
||||
oneGangBloc.add(SetCounterValue(
|
||||
seconds: 0,
|
||||
deviceCode:
|
||||
'countdown_time',
|
||||
duration: selectedValue));
|
||||
}
|
||||
},
|
||||
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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user