feat:更新主题色适配
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_common/utils/toast_util.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:food_hub_app/apis/session.dart';
|
||||
import 'package:food_hub_app/models/session.dart';
|
||||
import 'package:food_hub_app/widgets/common/form.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:form_builder_validators/form_builder_validators.dart';
|
||||
|
||||
@@ -85,7 +86,6 @@ class _LoginPage extends State<LoginPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey[100],
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
@@ -145,7 +145,8 @@ class _LoginPage extends State<LoginPage> {
|
||||
name: 'username',
|
||||
initialValue: _username,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: formInputDecoration(
|
||||
decoration: buildInputDecoration(
|
||||
context: context,
|
||||
hintText: "请输入账号",
|
||||
prefixIcon: Icons.person,
|
||||
),
|
||||
@@ -169,22 +170,18 @@ class _LoginPage extends State<LoginPage> {
|
||||
obscureText: _isObscure,
|
||||
onSaved: (v) => _password = v!,
|
||||
validator: FormBuilderValidators.required(),
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: Icon(Icons.lock),
|
||||
decoration: buildInputDecoration(
|
||||
context: context,
|
||||
hintText: "请输入密码",
|
||||
hintStyle: TextStyle(color: Colors.grey),
|
||||
border: OutlineInputBorder(),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
prefixIcon: Icons.lock,
|
||||
).copyWith(
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.remove_red_eye, color: _eyeColor),
|
||||
onPressed: () {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
setState(() {
|
||||
_isObscure = !_isObscure;
|
||||
_eyeColor =
|
||||
(_isObscure
|
||||
? Colors.grey
|
||||
: Theme.of(context).iconTheme.color)!;
|
||||
_eyeColor = (_isObscure ? Colors.grey : colors.surface);
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
@@ -52,7 +52,11 @@ class _MomentFormPageState extends State<MomentFormPage> {
|
||||
provider.momentFormItem.content = value!;
|
||||
});
|
||||
},
|
||||
decoration: buildInputDecoration(context: context, hintText: '请输入朋友圈内容'),
|
||||
decoration: buildInputDecoration(
|
||||
context: context,
|
||||
hintText: '请输入朋友圈内容',
|
||||
prefixIcon: Icons.article,
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入朋友圈内容';
|
||||
@@ -90,7 +94,10 @@ class _MomentFormPageState extends State<MomentFormPage> {
|
||||
}
|
||||
// 上传按钮(最后一个)
|
||||
else {
|
||||
return buildImageUploadButton(onTap: () => _pickImages(provider));
|
||||
return buildImageUploadButton(
|
||||
context: context,
|
||||
onTap: () => _pickImages(provider),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -104,19 +111,21 @@ class _MomentFormPageState extends State<MomentFormPage> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
buildFormLabel('朋友圈内容', required: true),
|
||||
buildFormLabel(context: context, text: '朋友圈内容', isRequired: true),
|
||||
const SizedBox(height: 8),
|
||||
_buildContentField(provider),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
buildFormLabel('上传图片', required: true),
|
||||
buildFormLabel(context: context, text: '上传图片', isRequired: true),
|
||||
const SizedBox(height: 8),
|
||||
_buildImageField(provider),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
|
||||
buildFormButtonGroup(
|
||||
context: context,
|
||||
isShowDelete: provider.isEditing,
|
||||
onConfirm: () => _submitForm(provider),
|
||||
onDelete: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/utils/minio_utils.dart';
|
||||
import 'package:flutter_common/utils/toast_util.dart';
|
||||
import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:flutter_common/widget/dialog_widget.dart';
|
||||
import 'package:flutter_common/widget/loading_widget.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:food_hub_app/apis/recipe.dart';
|
||||
import 'package:food_hub_app/config/app_config.dart';
|
||||
@@ -40,32 +42,32 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildFormBuilder() {
|
||||
final provider = context.watch<FoodProvider>();
|
||||
|
||||
Widget _buildFormBuilder(FoodProvider provider) {
|
||||
return FormBuilder(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
buildFormLabel('菜谱名称', required: true),
|
||||
buildFormLabel(context: context, text: '菜谱名称', isRequired: true),
|
||||
const SizedBox(height: 8),
|
||||
_buildRecipeField(provider),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
buildFormLabel('完成时间', required: true),
|
||||
buildFormLabel(context: context, text: '完成时间', isRequired: true),
|
||||
const SizedBox(height: 8),
|
||||
_buildDateField(provider),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
buildFormLabel('上传图片', required: true),
|
||||
buildFormLabel(context: context, text: '上传图片', isRequired: true),
|
||||
const SizedBox(height: 8),
|
||||
_buildImageField(provider),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
buildFormButtonGroup(
|
||||
context: context,
|
||||
isShowDelete: provider.isEditing,
|
||||
onConfirm: () => _submitForm(provider),
|
||||
onDelete: () => _deleteForm(provider),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -87,7 +89,7 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
},
|
||||
|
||||
onSelected: (String value) {
|
||||
provider.recordFormItem.name = value;
|
||||
provider.updateRecordFormItem(name: value);
|
||||
},
|
||||
|
||||
optionsViewBuilder: (
|
||||
@@ -114,6 +116,7 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
elevation: 2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: 200,
|
||||
maxWidth: MediaQuery.of(context).size.width - 58,
|
||||
@@ -146,7 +149,7 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
|
||||
void onClearRecipeName() {
|
||||
controller.clear();
|
||||
provider.recordFormItem.name = '';
|
||||
provider.updateRecordFormItem(name: '');
|
||||
}
|
||||
|
||||
Widget? buildSuffixIcon() {
|
||||
@@ -166,16 +169,12 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
focusNode: focusNode,
|
||||
enabled: !provider.isEditing,
|
||||
onChanged: (value) {
|
||||
provider.recordFormItem.name = value ?? '';
|
||||
provider.updateRecordFormItem(name: value ?? '');
|
||||
},
|
||||
decoration: buildInputDecoration(
|
||||
context: context,
|
||||
hintText: '请输入菜谱名称',
|
||||
prefixIcon: const Icon(
|
||||
Icons.restaurant_menu,
|
||||
size: 20,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
prefixIcon: Icons.restaurant_menu,
|
||||
).copyWith(suffixIcon: buildSuffixIcon()),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
@@ -196,11 +195,7 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
decoration: buildInputDecoration(
|
||||
context: context,
|
||||
hintText: '请选择完成时间',
|
||||
prefixIcon: const Icon(
|
||||
Icons.calendar_month,
|
||||
size: 20,
|
||||
color: Color(0xFF86909C),
|
||||
),
|
||||
prefixIcon: Icons.calendar_month,
|
||||
),
|
||||
onTap: () => _onSelectDate(provider),
|
||||
validator: (value) {
|
||||
@@ -224,7 +219,7 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
if (picked != null) {
|
||||
final String date = DateFormat('yyyy-MM-dd').format(picked);
|
||||
_formKey.currentState?.fields[_dateField]?.didChange(date);
|
||||
provider.recordFormItem.date = date;
|
||||
provider.updateRecordFormItem(date: date);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +228,10 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (provider.recordFormItem.imageUrl.isEmpty)
|
||||
buildImageUploadButton(onTap: () => _pickImage(provider))
|
||||
buildImageUploadButton(
|
||||
context: context,
|
||||
onTap: () => _pickImage(provider),
|
||||
)
|
||||
else
|
||||
ImagePreview(
|
||||
imageUrls: [provider.recordFormItem.imageUrl],
|
||||
@@ -254,22 +252,21 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
|
||||
if (result != null) {
|
||||
PlatformFile file = result.files.first;
|
||||
LoadingDialog.show(context, message: '上传中');
|
||||
|
||||
final fileName = await MinIOHelper().uploadFile(
|
||||
bucketName: AppConfig.bucketName,
|
||||
file: file,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
provider.recordFormItem.imageUrl = fileName;
|
||||
});
|
||||
|
||||
LoadingDialog.hide(context);
|
||||
provider.updateRecordFormItem(imageUrl: fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/// 移除图片
|
||||
void _removeImage(FoodProvider provider) {
|
||||
setState(() {
|
||||
provider.recordFormItem.imageUrl = '';
|
||||
});
|
||||
provider.updateRecordFormItem(imageUrl: '');
|
||||
}
|
||||
|
||||
/// 提交表单
|
||||
@@ -280,9 +277,43 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
return;
|
||||
}
|
||||
|
||||
await provider.handleRecord();
|
||||
await provider.onRecordTabChange();
|
||||
Navigator.pop(context);
|
||||
LoadingDialog.show(context, message: '提交中');
|
||||
final result = await provider.handleRecord();
|
||||
if (result == true) {
|
||||
await provider.onRecordTabChange();
|
||||
LoadingDialog.hide(context);
|
||||
|
||||
if (provider.isEditing) {
|
||||
showSuccessTip(context, '更新记录成功');
|
||||
} else {
|
||||
showSuccessTip(context, '新增记录成功');
|
||||
}
|
||||
|
||||
Future.delayed(Duration(milliseconds: 1500), () {
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _deleteForm(FoodProvider provider) async {
|
||||
final result = await showConfirmDialog(context, '确认删除该记录?');
|
||||
if (result == true) {
|
||||
LoadingDialog.show(context, message: '删除中');
|
||||
final isDelete = await provider.deleteRecord();
|
||||
if (isDelete) {
|
||||
await provider.onRecordTabChange();
|
||||
LoadingDialog.hide(context);
|
||||
showSuccessTip(context, '删除记录成功');
|
||||
|
||||
Future.delayed(Duration(milliseconds: 1500), () {
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +336,7 @@ class _RecordFormPageState extends State<RecordFormPage> {
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: CommonCard(child: _buildFormBuilder()),
|
||||
child: CommonCard(child: _buildFormBuilder(provider)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user