feat:增加日程模块
This commit is contained in:
106
lib/widgets/common.dart
Normal file
106
lib/widgets/common.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:omni_datetime_picker/omni_datetime_picker.dart';
|
||||
|
||||
Widget buildFormItem({
|
||||
required String label,
|
||||
required Widget child,
|
||||
bool required = false,
|
||||
}) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 80,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (required)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: 4),
|
||||
child: Text(
|
||||
'*',
|
||||
style: TextStyle(color: Colors.red, fontSize: 16),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const Text(':', style: TextStyle(fontSize: 14)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 右侧表单控件
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 显示日期/日期时间的按钮组件
|
||||
Widget buildOmniDateButton({
|
||||
required BuildContext context,
|
||||
required DateTime? selectedDate,
|
||||
required String placeholder,
|
||||
required OmniDateTimePickerType type,
|
||||
required ValueChanged<DateTime?> onChanged,
|
||||
}) {
|
||||
String displayText = '$placeholder';
|
||||
|
||||
if (selectedDate != null) {
|
||||
switch (type) {
|
||||
case OmniDateTimePickerType.date:
|
||||
displayText = DateFormat('yyyy-MM-dd').format(selectedDate);
|
||||
break;
|
||||
case OmniDateTimePickerType.time:
|
||||
displayText = DateFormat('HH:mm:ss').format(selectedDate);
|
||||
break;
|
||||
case OmniDateTimePickerType.dateAndTime:
|
||||
displayText = DateFormat('yyyy-MM-dd HH:mm:ss').format(selectedDate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Button(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(FluentIcons.calendar, size: 16),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
displayText,
|
||||
style: TextStyle(
|
||||
color: selectedDate == null ? Colors.grey[130] : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: () async {
|
||||
final DateTime? picked = await showOmniDateTimePicker(
|
||||
context: context,
|
||||
initialDate: selectedDate ?? DateTime.now(),
|
||||
firstDate: DateTime(
|
||||
DateTime.now().year,
|
||||
DateTime.now().month,
|
||||
DateTime.now().day,
|
||||
),
|
||||
lastDate: DateTime.now().add(Duration(days: 365 * 2)),
|
||||
is24HourMode: true,
|
||||
isShowSeconds: false,
|
||||
type: type,
|
||||
barrierColor: Colors.grey,
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
onChanged(picked);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user