Files
syncrow-app/lib/features/devices/view/widgets/ACs/CustomHalfHourTimerPicker.dart
T
2025-01-08 17:17:52 +03:00

53 lines
1.5 KiB
Dart

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)
),
),
);
}
}