feat:更新UI颜色

This commit is contained in:
2025-07-17 23:03:33 +08:00
parent eec0e9f7d3
commit 05fdbf9462
6 changed files with 86 additions and 74 deletions

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:fluttertoast/fluttertoast.dart';
Widget formLabelText({required String labelText, bool isRequired = false}) {
return Text.rich(
@@ -28,6 +27,7 @@ InputDecoration formInputDecoration({
);
}
/// 确认按钮样式
ButtonStyle primaryButtonStyle() {
return ButtonStyle(
backgroundColor: WidgetStateProperty.all(Colors.green),
@@ -37,6 +37,7 @@ ButtonStyle primaryButtonStyle() {
);
}
/// 取消按钮样式
ButtonStyle cancelButtonStyle() {
return ButtonStyle(
backgroundColor: WidgetStateProperty.all(Colors.grey),
@@ -50,6 +51,22 @@ Text buttonText({required String text}) {
return Text(text, style: TextStyle(color: Colors.white));
}
Widget errorImageContainer(double height) {
return Container(
height: height,
color: Colors.grey[200],
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error, color: Colors.red),
const SizedBox(width: 5),
const Text("加载失败", style: TextStyle(color: Colors.red)),
],
),
);
}
/// 成功消息
void showSuccessToast(String message) {
Fluttertoast.showToast(
msg: message,
@@ -62,6 +79,7 @@ void showSuccessToast(String message) {
);
}
/// 错误消息
void showErrorToast(String message) {
Fluttertoast.showToast(
msg: message,

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:food_hub_app/models/recipe.dart';
import 'package:food_hub_app/widgets/common/index.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
class RecipeCard extends StatelessWidget {
final Recipe recipe;
@@ -21,30 +23,25 @@ class RecipeCard extends StatelessWidget {
height: 200,
width: double.infinity,
fit: BoxFit.contain,
errorBuilder:
(context, error, stackTrace) => Container(
height: 200,
color: Colors.grey[200],
child: const Icon(Icons.food_bank, color: Colors.grey),
),
errorBuilder: (context, error, stackTrace) => errorImageContainer(200),
),
const Divider(
Divider(
height: 1,
thickness: 1,
color: Colors.green,
color: Theme.of(context).primaryColor,
indent: 0,
endIndent: 0,
),
Padding(
padding: const EdgeInsets.all(10),
child: _buildRecipeContent(),
child: _buildRecipeContent(context),
),
],
),
);
}
Widget _buildRecipeContent() {
Widget _buildRecipeContent(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -54,39 +51,29 @@ class RecipeCard extends StatelessWidget {
Expanded(
child: Text(
recipe.name,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
maxLines: 1, // 限制单行,避免挤压按钮
overflow: TextOverflow.ellipsis,
),
),
Row(
children: [
IconButton(
icon: const Icon(Icons.edit, size: 14),
color: Colors.white,
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
Colors.green,
),
shape: WidgetStateProperty.all(CircleBorder()),
minimumSize: WidgetStateProperty.all(Size(20, 20)),
),
onPressed: () {},
TDButton(
icon: Icons.edit,
size: TDButtonSize.small,
type: TDButtonType.fill,
shape: TDButtonShape.circle,
theme: TDButtonTheme.primary,
onTap: () => {},
),
IconButton(
icon: const Icon(Icons.book, size: 14),
color: Colors.white,
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
Colors.green,
),
shape: WidgetStateProperty.all(CircleBorder()),
minimumSize: WidgetStateProperty.all(Size(20, 20)),
),
onPressed: () {},
SizedBox(width: 10),
TDButton(
icon: Icons.book,
size: TDButtonSize.small,
type: TDButtonType.fill,
shape: TDButtonShape.circle,
theme: TDButtonTheme.primary,
onTap: () => {},
),
],
),
@@ -102,7 +89,7 @@ class RecipeCard extends StatelessWidget {
_buildIconText(
icon: Icons.food_bank,
text: recipe.category,
color: Colors.green,
color: Theme.of(context).primaryColor,
),
const SizedBox(width: 12),
_buildIconText(
@@ -156,4 +143,4 @@ class RecipeCard extends StatelessWidget {
],
);
}
}
}