feat:更新记录UI布局
This commit is contained in:
@@ -4,43 +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-service/food/recipe/$id",
|
"/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-service/food/food/recipe", data: recipe);
|
return HttpUtil().post<bool>("/food/food/recipe", data: recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> updateRecipeApi(int id, Recipe recipe) {
|
Future<bool> updateRecipeApi(int id, Recipe recipe) {
|
||||||
return HttpUtil().put<bool>(
|
return HttpUtil().put<bool>("/food/food/recipe/$id", data: recipe);
|
||||||
"/food-service/food/food/recipe/$id",
|
|
||||||
data: recipe,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deleteRecipeApi(int id) {
|
Future<bool> deleteRecipeApi(int id) {
|
||||||
return HttpUtil().delete<bool>("/food-service/food/food/recipe/$id");
|
return HttpUtil().delete<bool>("/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-service/food/recipe/user/$id",
|
"/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-service/food/recipe/user/favourite",
|
"/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-service/food/recipe",
|
"/food/recipe",
|
||||||
queryParameters: recipeQuery.toJson(),
|
queryParameters: recipeQuery.toJson(),
|
||||||
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
converter: (data) => convertListResponse<Recipe>(data, Recipe.fromJson),
|
||||||
);
|
);
|
||||||
@@ -48,61 +45,56 @@ Future<List<Recipe>> queryRecipeApi(RecipeQuery recipeQuery) {
|
|||||||
|
|
||||||
Future<List<String>> queryFoodNameListApi() {
|
Future<List<String>> queryFoodNameListApi() {
|
||||||
return HttpUtil().get<List<String>>(
|
return HttpUtil().get<List<String>>(
|
||||||
"/food-service/food/recipe/name",
|
"/food/recipe/name",
|
||||||
converter:
|
converter:
|
||||||
(data) => convertListResponse<String>(data, (json) => json.toString()),
|
(data) => convertListResponse<String>(data, (json) => json.toString()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addRecordApi(Record record) {
|
Future<bool> addRecordApi(Record record) {
|
||||||
return HttpUtil().post<bool>("/food-service/food/record", data: record);
|
return HttpUtil().post<bool>("/food/record", data: record);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> updateRecordApi(int id, Record record) {
|
Future<bool> updateRecordApi(int id, Record record) {
|
||||||
return HttpUtil().put<bool>("/food-service/food/record/$id", data: record);
|
return HttpUtil().put<bool>("/food/record/$id", data: record);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deleteRecordApi(int id) {
|
Future<bool> deleteRecordApi(int id) {
|
||||||
return HttpUtil().delete<bool>("/food-service/food/record/$id");
|
return HttpUtil().delete<bool>("/food/record/$id");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addRecipeCommentApi(int id, String content) {
|
Future<bool> addRecipeCommentApi(int id, String content) {
|
||||||
return HttpUtil().post<bool>(
|
return HttpUtil().post<bool>("/food/recipe/$id/comment", data: content);
|
||||||
"/food-service/food/recipe/$id/comment",
|
|
||||||
data: content,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addRecipeLikeApi(int id) {
|
Future<bool> addRecipeLikeApi(int id) {
|
||||||
return HttpUtil().post<bool>("/food-service/food/recipe/$id/like");
|
return HttpUtil().post<bool>("/food/recipe/$id/like");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deleteRecipeLikeApi(int id) {
|
Future<bool> deleteRecipeLikeApi(int id) {
|
||||||
return HttpUtil().delete<bool>("/food-service/food/recipe/$id/like");
|
return HttpUtil().delete<bool>("/food/recipe/$id/like");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addRecipeFavouriteApi(int id) {
|
Future<bool> addRecipeFavouriteApi(int id) {
|
||||||
return HttpUtil().post<bool>("/food-service/food/recipe/$id/favourite");
|
return HttpUtil().post<bool>("/food/recipe/$id/favourite");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deleteRecipeFavouriteApi(int id) {
|
Future<bool> deleteRecipeFavouriteApi(int id) {
|
||||||
return HttpUtil().delete<bool>("/food-service/food/recipe/$id/like");
|
return HttpUtil().delete<bool>("/food/recipe/$id/like");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Record>> queryRecordApi(String startDate, String endDate) {
|
Future<List<Record>> queryRecordApi(String startDate, String endDate) {
|
||||||
return HttpUtil().get<List<Record>>(
|
return HttpUtil().get<List<Record>>(
|
||||||
"/food-service/food/record",
|
"/food/record",
|
||||||
queryParameters: {
|
queryParameters: {"startDate": startDate, "endDate": endDate},
|
||||||
"startDate": startDate,
|
|
||||||
"endDate": endDate
|
|
||||||
},
|
|
||||||
converter: (data) => convertListResponse<Record>(data, Record.fromJson),
|
converter: (data) => convertListResponse<Record>(data, Record.fromJson),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<String>> queryCategoryApi() {
|
Future<List<String>> queryCategoryApi() {
|
||||||
return HttpUtil().get<List<String>>(
|
return HttpUtil().get<List<String>>(
|
||||||
"/food-service/food/category",
|
"/food/category",
|
||||||
converter: (data) => convertListResponse<String>(data, (json) => json.toString()),
|
converter:
|
||||||
|
(data) => convertListResponse<String>(data, (json) => json.toString()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>(
|
||||||
"/food-service/session",
|
"/session",
|
||||||
queryParameters: {"username": username, "password": password},
|
queryParameters: {"username": username, "password": password},
|
||||||
converter: (data) => Session.fromJson(data),
|
converter: (data) => Session.fromJson(data),
|
||||||
);
|
);
|
||||||
|
|||||||
7
lib/config/app_config.dart
Normal file
7
lib/config/app_config.dart
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/// 应用信息
|
||||||
|
class AppConfig {
|
||||||
|
// 网络配置
|
||||||
|
// http://192.168.1.3:8100
|
||||||
|
// http://14.103.235.151:81/food-service
|
||||||
|
static const String baseApiUrl = "http://14.103.235.151:81/food-service";
|
||||||
|
}
|
||||||
@@ -2,32 +2,15 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class NavBar extends StatelessWidget {
|
class NavBar extends StatelessWidget {
|
||||||
final int currentIndex;
|
final int currentIndex;
|
||||||
|
final List<BottomNavigationBarItem> navItems;
|
||||||
final Function(int) onTap;
|
final Function(int) onTap;
|
||||||
|
|
||||||
static const List<BottomNavigationBarItem> navItems = [
|
const NavBar({
|
||||||
BottomNavigationBarItem(
|
super.key,
|
||||||
icon: Icon(Icons.home_outlined),
|
required this.currentIndex,
|
||||||
activeIcon: Icon(Icons.home),
|
required this.onTap,
|
||||||
label: "记录",
|
required this.navItems,
|
||||||
),
|
});
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(Icons.pie_chart_outline),
|
|
||||||
activeIcon: Icon(Icons.pie_chart),
|
|
||||||
label: "统计",
|
|
||||||
),
|
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(Icons.group_outlined),
|
|
||||||
activeIcon: Icon(Icons.group),
|
|
||||||
label: "朋友圈",
|
|
||||||
),
|
|
||||||
BottomNavigationBarItem(
|
|
||||||
icon: Icon(Icons.account_circle_outlined),
|
|
||||||
activeIcon: Icon(Icons.account_circle),
|
|
||||||
label: "我的",
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
const NavBar({super.key, required this.currentIndex, required this.onTap});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|||||||
16
lib/models/layout.dart
Normal file
16
lib/models/layout.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// 导航栏
|
||||||
|
class NavItem {
|
||||||
|
final String label;
|
||||||
|
final IconData icon;
|
||||||
|
final IconData activeIcon;
|
||||||
|
final Widget page;
|
||||||
|
|
||||||
|
const NavItem({
|
||||||
|
required this.label,
|
||||||
|
required this.icon,
|
||||||
|
required this.activeIcon,
|
||||||
|
required this.page,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:food_hub_app/config/app_config.dart';
|
||||||
import 'package:food_hub_app/utils/sp_util.dart';
|
import 'package:food_hub_app/utils/sp_util.dart';
|
||||||
import 'package:food_hub_app/widgets/common/index.dart';
|
import 'package:food_hub_app/widgets/common/index.dart';
|
||||||
|
|
||||||
@@ -11,7 +11,6 @@ class HttpUtil {
|
|||||||
factory HttpUtil() => _instance;
|
factory HttpUtil() => _instance;
|
||||||
|
|
||||||
late Dio _dio;
|
late Dio _dio;
|
||||||
String baseUrl = kDebugMode ? "http://172.29.101.108:8100" : "http://14.103.235.151:81";
|
|
||||||
|
|
||||||
// 请求头配置
|
// 请求头配置
|
||||||
Map<String, dynamic> headers = {
|
Map<String, dynamic> headers = {
|
||||||
@@ -25,7 +24,7 @@ class HttpUtil {
|
|||||||
HttpUtil._internal() {
|
HttpUtil._internal() {
|
||||||
// 初始化Dio实例
|
// 初始化Dio实例
|
||||||
BaseOptions options = BaseOptions(
|
BaseOptions options = BaseOptions(
|
||||||
baseUrl: baseUrl,
|
baseUrl: AppConfig.baseApiUrl,
|
||||||
connectTimeout: Duration(seconds: timeout),
|
connectTimeout: Duration(seconds: timeout),
|
||||||
receiveTimeout: Duration(seconds: timeout),
|
receiveTimeout: Duration(seconds: timeout),
|
||||||
headers: headers,
|
headers: headers,
|
||||||
@@ -81,10 +80,6 @@ class HttpUtil {
|
|||||||
T Function(dynamic data)? converter,
|
T Function(dynamic data)? converter,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
if (kDebugMode) {
|
|
||||||
path = path.replaceFirst('/food-service', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
Response response = await _dio.request(
|
Response response = await _dio.request(
|
||||||
path,
|
path,
|
||||||
data: data,
|
data: data,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:food_hub_app/layout/index.dart';
|
import 'package:food_hub_app/layout/index.dart';
|
||||||
|
import 'package:food_hub_app/models/layout.dart';
|
||||||
import 'package:food_hub_app/views/moment.dart';
|
import 'package:food_hub_app/views/moment.dart';
|
||||||
import 'package:food_hub_app/views/profile.dart';
|
import 'package:food_hub_app/views/profile.dart';
|
||||||
import 'package:food_hub_app/views/record.dart';
|
import 'package:food_hub_app/views/record.dart';
|
||||||
@@ -15,13 +16,43 @@ class HomePage extends StatefulWidget {
|
|||||||
class _HomePage extends State<HomePage> {
|
class _HomePage extends State<HomePage> {
|
||||||
int _currentIndex = 0;
|
int _currentIndex = 0;
|
||||||
|
|
||||||
final List<Widget> _tabPages = const [
|
final List<NavItem> navItems = [
|
||||||
RecordPage(),
|
NavItem(
|
||||||
StatsPage(),
|
label: "记录",
|
||||||
MomentPage(),
|
icon: Icons.home_outlined,
|
||||||
ProfilePage(),
|
activeIcon: Icons.home,
|
||||||
|
page: RecordPage(),
|
||||||
|
),
|
||||||
|
NavItem(
|
||||||
|
label: "统计",
|
||||||
|
icon: Icons.pie_chart_outline,
|
||||||
|
activeIcon: Icons.pie_chart,
|
||||||
|
page: StatsPage(),
|
||||||
|
),
|
||||||
|
NavItem(
|
||||||
|
label: "朋友圈",
|
||||||
|
icon: Icons.group_outlined,
|
||||||
|
activeIcon: Icons.group,
|
||||||
|
page: MomentPage(),
|
||||||
|
),
|
||||||
|
NavItem(
|
||||||
|
label: "我的",
|
||||||
|
icon: Icons.account_circle_outlined,
|
||||||
|
activeIcon: Icons.account_circle,
|
||||||
|
page: ProfilePage(),
|
||||||
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
List<BottomNavigationBarItem> get bottomNavItems =>
|
||||||
|
navItems.map((item) => BottomNavigationBarItem(
|
||||||
|
icon: Icon(item.icon),
|
||||||
|
activeIcon: Icon(item.activeIcon),
|
||||||
|
label: item.label,
|
||||||
|
)).toList();
|
||||||
|
|
||||||
|
List<Widget> get tabPages =>
|
||||||
|
navItems.map((item) => item.page).toList();
|
||||||
|
|
||||||
bool isShow(int index) {
|
bool isShow(int index) {
|
||||||
return index == 0 || index == 2;
|
return index == 0 || index == 2;
|
||||||
}
|
}
|
||||||
@@ -43,10 +74,11 @@ class _HomePage extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
backgroundColor: Color(0xFFF5F5F5),
|
backgroundColor: Color(0xFFF5F5F5),
|
||||||
endDrawer: const SettingsDrawer(),
|
endDrawer: const SettingsDrawer(),
|
||||||
body: _tabPages[_currentIndex],
|
body: tabPages[_currentIndex],
|
||||||
floatingActionButton:
|
floatingActionButton:
|
||||||
isShow(_currentIndex) ? addItemButton(context) : null,
|
isShow(_currentIndex) ? addItemButton(context) : null,
|
||||||
bottomNavigationBar: NavBar(
|
bottomNavigationBar: NavBar(
|
||||||
|
navItems: bottomNavItems,
|
||||||
currentIndex: _currentIndex,
|
currentIndex: _currentIndex,
|
||||||
onTap: (index) {
|
onTap: (index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
@@ -171,9 +171,9 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color:
|
color:
|
||||||
isSelected
|
isSelected
|
||||||
? Colors.blue
|
? Theme.of(context).primaryColor
|
||||||
: isToday
|
: isToday
|
||||||
? Colors.grey[200]
|
? Colors.grey[300]
|
||||||
: Colors.transparent,
|
: Colors.transparent,
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
@@ -184,7 +184,7 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
|||||||
// 日期数字
|
// 日期数字
|
||||||
Text(
|
Text(
|
||||||
day.day.toString(),
|
day.day.toString(),
|
||||||
style: TextStyle(color: isSelected ? Colors.white : Colors.black87),
|
style: TextStyle(color: isSelected ? Colors.white : Colors.black),
|
||||||
),
|
),
|
||||||
// 底部红点 - 只在指定日期显示
|
// 底部红点 - 只在指定日期显示
|
||||||
if (shouldShowRedDot)
|
if (shouldShowRedDot)
|
||||||
@@ -207,7 +207,6 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Card(elevation: 0, color: Colors.white, child: recipeCalendar()),
|
Card(elevation: 0, color: Colors.white, child: recipeCalendar()),
|
||||||
const SizedBox(height: 10),
|
|
||||||
Expanded(child: dailyItem()),
|
Expanded(child: dailyItem()),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:food_hub_app/config/app_config.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:food_hub_app/widgets/common/index.dart';
|
||||||
@@ -19,7 +20,7 @@ class RecipeCard extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Image.network(
|
Image.network(
|
||||||
'http://172.29.101.108:8100/${recipe.recordList[0].imageUrl}',
|
'${AppConfig.baseApiUrl}/${recipe.recordList[0].imageUrl}',
|
||||||
height: 200,
|
height: 200,
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
|
|||||||
@@ -34,14 +34,11 @@ class _RecipeListState extends State<RecipeList> {
|
|||||||
if (recipeList.isEmpty) {
|
if (recipeList.isEmpty) {
|
||||||
return const TDEmpty(type: TDEmptyType.plain, emptyText: '暂无数据');
|
return const TDEmpty(type: TDEmptyType.plain, emptyText: '暂无数据');
|
||||||
} else {
|
} else {
|
||||||
return ListView.separated(
|
return ListView.builder(
|
||||||
itemCount: recipeList.length,
|
itemCount: recipeList.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return RecipeCard(recipe: recipeList[index]);
|
return RecipeCard(recipe: recipeList[index]);
|
||||||
},
|
}
|
||||||
separatorBuilder: (context, index) {
|
|
||||||
return const SizedBox(height: 10);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:food_hub_app/api/recipe.dart';
|
import 'package:food_hub_app/api/recipe.dart';
|
||||||
|
import 'package:food_hub_app/config/app_config.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:food_hub_app/widgets/common/index.dart';
|
||||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||||
@@ -18,11 +19,11 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
refreshRecord();
|
refreshRecord(DateTime.now().year);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refreshRecord() async {
|
Future<void> refreshRecord(int year) async {
|
||||||
final result = await queryRecordApi("2025-01-01", "2025-07-08");
|
final result = await queryRecordApi("$year-01-01", "$year-12-31");
|
||||||
setState(() {
|
setState(() {
|
||||||
recordList = result;
|
recordList = result;
|
||||||
});
|
});
|
||||||
@@ -36,18 +37,15 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
|||||||
initialYear: DateTime.now().year,
|
initialYear: DateTime.now().year,
|
||||||
minYear: 2000,
|
minYear: 2000,
|
||||||
maxYear: 2100,
|
maxYear: 2100,
|
||||||
onYearChanged: (year) {
|
onYearChanged: (year) => refreshRecord(year)
|
||||||
print('选中的年份: $year');
|
|
||||||
},
|
|
||||||
accentColor: Colors.blue,
|
|
||||||
),
|
),
|
||||||
Expanded(child: TimelineContainer(recordList))
|
Expanded(child: timelineContainer(recordList)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget TimelineContainer(List<Record> recordList) {
|
Widget timelineContainer(List<Record> recordList) {
|
||||||
if (recordList.isEmpty) {
|
if (recordList.isEmpty) {
|
||||||
return const TDEmpty(type: TDEmptyType.plain, emptyText: '暂无数据');
|
return const TDEmpty(type: TDEmptyType.plain, emptyText: '暂无数据');
|
||||||
} else {
|
} else {
|
||||||
@@ -76,6 +74,30 @@ class TimelineCard extends StatelessWidget {
|
|||||||
|
|
||||||
const TimelineCard({super.key, required this.record});
|
const TimelineCard({super.key, required this.record});
|
||||||
|
|
||||||
|
Widget cardContent() {
|
||||||
|
return Card(
|
||||||
|
elevation: 0,
|
||||||
|
color: Colors.white,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(10),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text(record.name, style: TextStyle(fontSize: 16)),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
Image.network(
|
||||||
|
'${AppConfig.baseApiUrl}/${record.imageUrl}',
|
||||||
|
width: double.infinity,
|
||||||
|
height: 250,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
errorBuilder:
|
||||||
|
(context, error, stackTrace) => errorImageContainer(250),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
@@ -89,28 +111,7 @@ class TimelineCard extends StatelessWidget {
|
|||||||
record.date,
|
record.date,
|
||||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
Card(
|
cardContent(),
|
||||||
elevation: 0,
|
|
||||||
color: Colors.white,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.all(10),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Text(record.name, style: TextStyle(fontSize: 16)),
|
|
||||||
const SizedBox(height: 5),
|
|
||||||
Image.network(
|
|
||||||
'http://172.29.101.108:8100/${record.imageUrl}',
|
|
||||||
width: double.infinity,
|
|
||||||
height: 250,
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
errorBuilder:
|
|
||||||
(context, error, stackTrace) =>
|
|
||||||
errorImageContainer(250),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -123,7 +124,6 @@ class YearSelector extends StatefulWidget {
|
|||||||
final int? minYear;
|
final int? minYear;
|
||||||
final int? maxYear;
|
final int? maxYear;
|
||||||
final Function(int) onYearChanged;
|
final Function(int) onYearChanged;
|
||||||
final Color? accentColor;
|
|
||||||
|
|
||||||
const YearSelector({
|
const YearSelector({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -131,17 +131,16 @@ class YearSelector extends StatefulWidget {
|
|||||||
required this.onYearChanged,
|
required this.onYearChanged,
|
||||||
this.minYear,
|
this.minYear,
|
||||||
this.maxYear,
|
this.maxYear,
|
||||||
this.accentColor,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<YearSelector> createState() => _YearSelectorState();
|
State<YearSelector> createState() => _YearSelectorState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SingleTickerProviderStateMixin 动画控制器
|
||||||
class _YearSelectorState extends State<YearSelector>
|
class _YearSelectorState extends State<YearSelector>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late int _currentYear;
|
late int _currentYear;
|
||||||
late Color _accentColor;
|
|
||||||
|
|
||||||
// 用于动画效果
|
// 用于动画效果
|
||||||
late AnimationController _animationController;
|
late AnimationController _animationController;
|
||||||
@@ -151,9 +150,6 @@ class _YearSelectorState extends State<YearSelector>
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_currentYear = widget.initialYear;
|
_currentYear = widget.initialYear;
|
||||||
_accentColor = widget.accentColor ?? Theme
|
|
||||||
.of(context)
|
|
||||||
.primaryColor;
|
|
||||||
|
|
||||||
// 初始化动画控制器
|
// 初始化动画控制器
|
||||||
_animationController = AnimationController(
|
_animationController = AnimationController(
|
||||||
@@ -228,12 +224,13 @@ class _YearSelectorState extends State<YearSelector>
|
|||||||
child: Text(
|
child: Text(
|
||||||
'$_currentYear',
|
'$_currentYear',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 28,
|
fontSize: 24,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: _accentColor,
|
color: Theme.of(context).primaryColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
SizedBox(width: 10),
|
||||||
TDButton(
|
TDButton(
|
||||||
icon: Icons.chevron_right,
|
icon: Icons.chevron_right,
|
||||||
size: TDButtonSize.small,
|
size: TDButtonSize.small,
|
||||||
|
|||||||
Reference in New Issue
Block a user