feat:增加睡眠记录
This commit is contained in:
69
lib/widget/time_picker.dart
Normal file
69
lib/widget/time_picker.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:fitnote/widget/record/common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TimePicker extends StatelessWidget {
|
||||
final TimeOfDay initialTime;
|
||||
final ValueChanged<TimeOfDay> onTimeSelected;
|
||||
final String? label;
|
||||
|
||||
const TimePicker({
|
||||
super.key,
|
||||
required this.initialTime,
|
||||
required this.onTimeSelected,
|
||||
this.label,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double width = 150;
|
||||
final double height = 36;
|
||||
|
||||
return Container(
|
||||
width: width,
|
||||
height: height,
|
||||
decoration: buildBoxDecoration(context),
|
||||
child: InkWell(
|
||||
onTap: () => _showTimePicker(context),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.access_time, size: 20, color: Colors.grey[600]),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
label ?? _formatTime(initialTime),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(Icons.arrow_drop_down, size: 20, color: Colors.grey[500]),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showTimePicker(BuildContext context) async {
|
||||
final TimeOfDay? picked = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: initialTime,
|
||||
initialEntryMode: TimePickerEntryMode.dialOnly,
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
onTimeSelected(picked);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatTime(TimeOfDay time) {
|
||||
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user