feat:更新UI颜色
This commit is contained in:
@@ -4,40 +4,40 @@ import 'package:food_hub_app/utils/index.dart';
|
|||||||
|
|
||||||
Future<Recipe> queryRecipeByIdApi(int id) {
|
Future<Recipe> queryRecipeByIdApi(int id) {
|
||||||
return HttpUtil().get<Recipe>(
|
return HttpUtil().get<Recipe>(
|
||||||
"/food/recipe/$id",
|
"/food-service/food/recipe/$id",
|
||||||
converter: (data) => Recipe.fromJson(data),
|
converter: (data) => Recipe.fromJson(data),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addRecipeApi(Recipe recipe) {
|
Future<bool> addRecipeApi(Recipe recipe) {
|
||||||
return HttpUtil().post<bool>("/food/food/recipe", data: recipe);
|
return HttpUtil().post<bool>("/food-service/food/food/recipe", data: recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> updateRecipeApi(int id, Recipe recipe) {
|
Future<bool> updateRecipeApi(int id, Recipe recipe) {
|
||||||
return HttpUtil().put<bool>("/food/food/recipe/$id", data: recipe);
|
return HttpUtil().put<bool>("/food-service/food/food/recipe/$id", data: recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deleteRecipeApi(int id) {
|
Future<bool> deleteRecipeApi(int id) {
|
||||||
return HttpUtil().delete<bool>("/food/food/recipe/$id");
|
return HttpUtil().delete<bool>("/food-service/food/food/recipe/$id");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Recipe>> queryRecipeByUserApi(int id) {
|
Future<List<Recipe>> queryRecipeByUserApi(int id) {
|
||||||
return HttpUtil().get<List<Recipe>>(
|
return HttpUtil().get<List<Recipe>>(
|
||||||
"/food/recipe/user/$id",
|
"/food-service/food/recipe/user/$id",
|
||||||
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Recipe>> queryRecipeUserFavouriteApi() {
|
Future<List<Recipe>> queryRecipeUserFavouriteApi() {
|
||||||
return HttpUtil().get<List<Recipe>>(
|
return HttpUtil().get<List<Recipe>>(
|
||||||
"/food/recipe/user/favourite",
|
"/food-service/food/recipe/user/favourite",
|
||||||
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Recipe>> queryRecipeApi(RecipeQuery recipeQuery) {
|
Future<List<Recipe>> queryRecipeApi(RecipeQuery recipeQuery) {
|
||||||
return HttpUtil().get<List<Recipe>>(
|
return HttpUtil().get<List<Recipe>>(
|
||||||
"/food/recipe",
|
"/food-service/food/recipe",
|
||||||
queryParameters: recipeQuery.toJson(),
|
queryParameters: recipeQuery.toJson(),
|
||||||
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import 'package:food_hub_app/utils/http_util.dart';
|
|||||||
|
|
||||||
Future<Session> loginApi(String username, String password) {
|
Future<Session> loginApi(String username, String password) {
|
||||||
return HttpUtil().post<Session>(
|
return HttpUtil().post<Session>(
|
||||||
"/session",
|
"/food-service/session",
|
||||||
queryParameters: {"username": username, "password": password},
|
queryParameters: {"username": username, "password": password},
|
||||||
converter: (data) => Session.fromJson(data),
|
converter: (data) => Session.fromJson(data),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ class HttpUtil {
|
|||||||
factory HttpUtil() => _instance;
|
factory HttpUtil() => _instance;
|
||||||
|
|
||||||
late Dio _dio;
|
late Dio _dio;
|
||||||
String baseUrl = "http://172.29.101.108:8100/";
|
bool isMock = true;
|
||||||
|
String baseUrl = "http://192.168.1.3:8100";
|
||||||
|
|
||||||
// 请求头配置
|
// 请求头配置
|
||||||
Map<String, dynamic> headers = {
|
Map<String, dynamic> headers = {
|
||||||
@@ -80,6 +81,10 @@ class HttpUtil {
|
|||||||
T Function(dynamic data)? converter,
|
T Function(dynamic data)? converter,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
|
if (isMock) {
|
||||||
|
path = path.replaceFirst('/food-service', '');
|
||||||
|
}
|
||||||
|
|
||||||
Response response = await _dio.request(
|
Response response = await _dio.request(
|
||||||
path,
|
path,
|
||||||
data: data,
|
data: data,
|
||||||
|
|||||||
@@ -81,34 +81,11 @@ class _LoginPage extends State<LoginPage> {
|
|||||||
backgroundColor: Colors.grey[100],
|
backgroundColor: Colors.grey[100],
|
||||||
body: Form(
|
body: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
// autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// 可滚动的主要内容区域
|
// 可滚动的主要内容区域
|
||||||
Expanded(
|
Expanded(child: buildLoginForm()),
|
||||||
child: ListView(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: kToolbarHeight),
|
|
||||||
buildTitle(),
|
|
||||||
const SizedBox(height: 60),
|
|
||||||
buildUsernameTextField(),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
buildPasswordTextField(context),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
buildRememberPasswordCheckbox(context), // 记住密码(左对齐)
|
|
||||||
buildForgetPasswordText(context),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(height: 20), // 调整与登录按钮的间距
|
|
||||||
buildLoginButton(context),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// 固定在底部的其他登录选项区域
|
// 固定在底部的其他登录选项区域
|
||||||
Padding(
|
Padding(
|
||||||
@@ -137,6 +114,31 @@ class _LoginPage extends State<LoginPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget buildLoginForm() {
|
||||||
|
return ListView(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: kToolbarHeight),
|
||||||
|
buildTitle(),
|
||||||
|
const SizedBox(height: 60),
|
||||||
|
buildUsernameTextField(),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
buildPasswordTextField(context),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
buildRememberPasswordCheckbox(context), // 记住密码(左对齐)
|
||||||
|
buildForgetPasswordText(context),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 20), // 调整与登录按钮的间距
|
||||||
|
buildLoginButton(context),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildUsernameTextField() {
|
Widget buildUsernameTextField() {
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
// import 'package:fluttertoast/fluttertoast.dart';
|
|
||||||
|
|
||||||
Widget formLabelText({required String labelText, bool isRequired = false}) {
|
Widget formLabelText({required String labelText, bool isRequired = false}) {
|
||||||
return Text.rich(
|
return Text.rich(
|
||||||
@@ -28,6 +27,7 @@ InputDecoration formInputDecoration({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 确认按钮样式
|
||||||
ButtonStyle primaryButtonStyle() {
|
ButtonStyle primaryButtonStyle() {
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
backgroundColor: WidgetStateProperty.all(Colors.green),
|
backgroundColor: WidgetStateProperty.all(Colors.green),
|
||||||
@@ -37,6 +37,7 @@ ButtonStyle primaryButtonStyle() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 取消按钮样式
|
||||||
ButtonStyle cancelButtonStyle() {
|
ButtonStyle cancelButtonStyle() {
|
||||||
return ButtonStyle(
|
return ButtonStyle(
|
||||||
backgroundColor: WidgetStateProperty.all(Colors.grey),
|
backgroundColor: WidgetStateProperty.all(Colors.grey),
|
||||||
@@ -50,6 +51,22 @@ Text buttonText({required String text}) {
|
|||||||
return Text(text, style: TextStyle(color: Colors.white));
|
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) {
|
void showSuccessToast(String message) {
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
msg: message,
|
msg: message,
|
||||||
@@ -62,6 +79,7 @@ void showSuccessToast(String message) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 错误消息
|
||||||
void showErrorToast(String message) {
|
void showErrorToast(String message) {
|
||||||
Fluttertoast.showToast(
|
Fluttertoast.showToast(
|
||||||
msg: message,
|
msg: message,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:food_hub_app/models/recipe.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 {
|
class RecipeCard extends StatelessWidget {
|
||||||
final Recipe recipe;
|
final Recipe recipe;
|
||||||
@@ -21,30 +23,25 @@ class RecipeCard extends StatelessWidget {
|
|||||||
height: 200,
|
height: 200,
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
errorBuilder:
|
errorBuilder: (context, error, stackTrace) => errorImageContainer(200),
|
||||||
(context, error, stackTrace) => Container(
|
|
||||||
height: 200,
|
|
||||||
color: Colors.grey[200],
|
|
||||||
child: const Icon(Icons.food_bank, color: Colors.grey),
|
|
||||||
),
|
),
|
||||||
),
|
Divider(
|
||||||
const Divider(
|
|
||||||
height: 1,
|
height: 1,
|
||||||
thickness: 1,
|
thickness: 1,
|
||||||
color: Colors.green,
|
color: Theme.of(context).primaryColor,
|
||||||
indent: 0,
|
indent: 0,
|
||||||
endIndent: 0,
|
endIndent: 0,
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
child: _buildRecipeContent(),
|
child: _buildRecipeContent(context),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildRecipeContent() {
|
Widget _buildRecipeContent(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -54,39 +51,29 @@ class RecipeCard extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
recipe.name,
|
recipe.name,
|
||||||
style: const TextStyle(
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
maxLines: 1, // 限制单行,避免挤压按钮
|
maxLines: 1, // 限制单行,避免挤压按钮
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
TDButton(
|
||||||
icon: const Icon(Icons.edit, size: 14),
|
icon: Icons.edit,
|
||||||
color: Colors.white,
|
size: TDButtonSize.small,
|
||||||
style: ButtonStyle(
|
type: TDButtonType.fill,
|
||||||
backgroundColor: WidgetStateProperty.all(
|
shape: TDButtonShape.circle,
|
||||||
Colors.green,
|
theme: TDButtonTheme.primary,
|
||||||
|
onTap: () => {},
|
||||||
),
|
),
|
||||||
shape: WidgetStateProperty.all(CircleBorder()),
|
SizedBox(width: 10),
|
||||||
minimumSize: WidgetStateProperty.all(Size(20, 20)),
|
TDButton(
|
||||||
),
|
icon: Icons.book,
|
||||||
onPressed: () {},
|
size: TDButtonSize.small,
|
||||||
),
|
type: TDButtonType.fill,
|
||||||
IconButton(
|
shape: TDButtonShape.circle,
|
||||||
icon: const Icon(Icons.book, size: 14),
|
theme: TDButtonTheme.primary,
|
||||||
color: Colors.white,
|
onTap: () => {},
|
||||||
style: ButtonStyle(
|
|
||||||
backgroundColor: WidgetStateProperty.all(
|
|
||||||
Colors.green,
|
|
||||||
),
|
|
||||||
shape: WidgetStateProperty.all(CircleBorder()),
|
|
||||||
minimumSize: WidgetStateProperty.all(Size(20, 20)),
|
|
||||||
),
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -102,7 +89,7 @@ class RecipeCard extends StatelessWidget {
|
|||||||
_buildIconText(
|
_buildIconText(
|
||||||
icon: Icons.food_bank,
|
icon: Icons.food_bank,
|
||||||
text: recipe.category,
|
text: recipe.category,
|
||||||
color: Colors.green,
|
color: Theme.of(context).primaryColor,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
_buildIconText(
|
_buildIconText(
|
||||||
|
|||||||
Reference in New Issue
Block a user