127 lines
3.6 KiB
Dart
127 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// 通用输入框样式
|
|
InputDecoration buildInputDecoration({
|
|
required BuildContext context,
|
|
required String hintText,
|
|
IconData? prefixIcon,
|
|
}) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return InputDecoration(
|
|
hintText: hintText,
|
|
hintStyle: TextStyle(color: colors.onSurface.withAlpha(100)),
|
|
filled: true,
|
|
fillColor: colors.surface,
|
|
border: OutlineInputBorder(
|
|
borderSide: const BorderSide(color: Color(0xFFE5E7EB)),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: colors.primary, width: 2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
errorBorder: OutlineInputBorder(
|
|
borderSide: const BorderSide(color: Colors.red, width: 2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 15, vertical: 14),
|
|
errorStyle: const TextStyle(fontSize: 12, height: 1, color: Colors.red),
|
|
prefixIcon:
|
|
prefixIcon != null
|
|
? Icon(prefixIcon, size: 20, color: Color(0xFF86909C))
|
|
: null,
|
|
prefixIconConstraints: const BoxConstraints(minWidth: 40),
|
|
isDense: true,
|
|
);
|
|
}
|
|
|
|
Widget buildFormLabel({
|
|
required BuildContext context,
|
|
required String text,
|
|
required bool isRequired,
|
|
}) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return RichText(
|
|
text: TextSpan(
|
|
text: text,
|
|
style: TextStyle(
|
|
color: colors.onSurface,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
fontFamily: 'CustomFont',
|
|
height: 1.2,
|
|
),
|
|
children: [
|
|
if (isRequired)
|
|
const TextSpan(
|
|
text: ' *',
|
|
style: TextStyle(color: Colors.red, fontSize: 16),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 表单底部按钮组组件
|
|
Widget buildFormButtonGroup({
|
|
required BuildContext context,
|
|
required bool isShowDelete,
|
|
required VoidCallback onConfirm,
|
|
required VoidCallback onDelete,
|
|
}) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(child: _buildCancelButton(context)),
|
|
if (isShowDelete) ...[
|
|
SizedBox(width: 16),
|
|
Expanded(child: _buildDeleteButton(context, onDelete)),
|
|
],
|
|
SizedBox(width: 16),
|
|
Expanded(child: _buildSubmitButton(context, onConfirm)),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// 取消按钮
|
|
Widget _buildCancelButton(BuildContext context) {
|
|
return ElevatedButton(
|
|
onPressed: () => Navigator.pop(context), // 直接使用传入的context返回
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
foregroundColor: const Color(0xFF4E5969),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
|
elevation: 0,
|
|
),
|
|
child: const Text('取消'),
|
|
);
|
|
}
|
|
|
|
/// 提交按钮
|
|
Widget _buildSubmitButton(BuildContext context, VoidCallback onConfirm) {
|
|
return ElevatedButton(
|
|
onPressed: () => onConfirm(),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
|
elevation: 0,
|
|
),
|
|
child: const Text('提交', style: TextStyle(color: Colors.white)),
|
|
);
|
|
}
|
|
|
|
/// 删除按钮
|
|
Widget _buildDeleteButton(BuildContext context, VoidCallback onDelete) {
|
|
return ElevatedButton(
|
|
onPressed: () => onDelete(),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.red,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
|
elevation: 0,
|
|
),
|
|
child: const Text('删除', style: TextStyle(color: Colors.white)),
|
|
);
|
|
}
|