feat:更新图片url路径
This commit is contained in:
@@ -107,20 +107,23 @@ Widget buildFileImage(BuildContext context, File imageFile) {
|
||||
}
|
||||
|
||||
Widget buildNetworkImage(BuildContext context, String url) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
showFullScreenImage(context, NetworkImage(url));
|
||||
},
|
||||
child: Image.network(
|
||||
url,
|
||||
fit: BoxFit.cover,
|
||||
loadingBuilder: (context, child, loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return buildImageLoadingIndicator(loadingProgress);
|
||||
return AspectRatio(
|
||||
aspectRatio: 1.5,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
showFullScreenImage(context, NetworkImage(url));
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) => _buildErrorImage(),
|
||||
child: Image.network(
|
||||
url,
|
||||
fit: BoxFit.cover,
|
||||
loadingBuilder: (context, child, loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return buildImageLoadingIndicator(loadingProgress);
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) => _buildErrorImage(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -153,7 +153,7 @@ void showSuccessToast(String message) {
|
||||
Fluttertoast.showToast(
|
||||
msg: message,
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
gravity: ToastGravity.TOP,
|
||||
timeInSecForIosWeb: 1,
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
@@ -166,7 +166,7 @@ void showErrorToast(String message) {
|
||||
Fluttertoast.showToast(
|
||||
msg: message,
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
gravity: ToastGravity.TOP,
|
||||
timeInSecForIosWeb: 1,
|
||||
backgroundColor: Colors.red,
|
||||
textColor: Colors.white,
|
||||
|
||||
@@ -57,7 +57,7 @@ class MomentCard extends StatelessWidget {
|
||||
size: TDAvatarSize.medium,
|
||||
type: TDAvatarType.normal,
|
||||
fit: BoxFit.contain,
|
||||
avatarUrl: '${AppConfig.baseApiUrl}/${moment.avatar}',
|
||||
avatarUrl: '${AppConfig.imageBaseUrl}/${moment.avatar}',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class MomentCard extends StatelessWidget {
|
||||
// 生成图片URL列表(用于预览时切换)
|
||||
final List<String> imageUrls =
|
||||
moment.imageList
|
||||
.map((path) => '${AppConfig.baseApiUrl}/$path')
|
||||
.map((path) => '${AppConfig.imageBaseUrl}$path')
|
||||
.toList();
|
||||
|
||||
void imageTapClick(int index) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/apis/recipe.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:food_hub_app/utils/date_util.dart';
|
||||
import 'package:food_hub_app/utils/index.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class RecipeCalendar extends StatefulWidget {
|
||||
const RecipeCalendar({super.key});
|
||||
@@ -23,10 +25,10 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
refreshRecord();
|
||||
_refreshRecord();
|
||||
}
|
||||
|
||||
Future<void> refreshRecord() async {
|
||||
Future<void> _refreshRecord() async {
|
||||
final result = await queryRecordApi(
|
||||
getFirstDayOfMonth(_focusedDay),
|
||||
getLastDayOfMonth(_focusedDay),
|
||||
@@ -40,11 +42,11 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
_selectedDay = _focusedDay;
|
||||
}
|
||||
|
||||
refreshSelectRecord();
|
||||
_refreshSelectRecord();
|
||||
});
|
||||
}
|
||||
|
||||
void refreshSelectRecord() {
|
||||
void _refreshSelectRecord() {
|
||||
setState(() {
|
||||
selectRecordList =
|
||||
recordList
|
||||
@@ -53,7 +55,7 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
});
|
||||
}
|
||||
|
||||
TableCalendar recipeCalendar() {
|
||||
TableCalendar _recipeCalendar() {
|
||||
return TableCalendar(
|
||||
locale: 'zh_CN',
|
||||
headerStyle: const HeaderStyle(
|
||||
@@ -69,13 +71,13 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
setState(() {
|
||||
_selectedDay = selectedDay;
|
||||
_focusedDay = focusedDay;
|
||||
refreshSelectRecord();
|
||||
_refreshSelectRecord();
|
||||
});
|
||||
}
|
||||
},
|
||||
onPageChanged: (focusedDay) {
|
||||
_focusedDay = focusedDay;
|
||||
refreshRecord();
|
||||
_refreshRecord();
|
||||
},
|
||||
// 自定义日期单元格构建器
|
||||
calendarBuilders: CalendarBuilders(
|
||||
@@ -89,7 +91,7 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget dailyItem(BuildContext context) {
|
||||
Widget _dailyItem(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -102,14 +104,49 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
itemCount: selectRecordList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return recipeRecordItem(context, selectRecordList[index]);
|
||||
return _buildRecordItem(context, selectRecordList[index]);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget recipeRecordItem(BuildContext context, FoodRecord record) {
|
||||
Widget _buildRecordItemAvatar(String name, Color color) {
|
||||
return CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: color,
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRecordItemBody(String name, String category) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(name, style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 5),
|
||||
Text(category, style: TextStyle(color: Colors.grey)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _handleEditRecord(BuildContext context, FoodRecord record) {
|
||||
final provider = context.read<FoodProvider>();
|
||||
|
||||
provider.initRecordForm(record);
|
||||
provider.isEditing = true;
|
||||
Navigator.pushNamed(context, "/recordForm");
|
||||
}
|
||||
|
||||
Widget _buildRecordItem(BuildContext context, FoodRecord record) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Card(
|
||||
@@ -119,37 +156,13 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: colors.primary,
|
||||
child: Text(
|
||||
record.category[0],
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildRecordItemAvatar(record.category[0], colors.primary),
|
||||
SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
record.name,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Text(record.category, style: TextStyle(color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: _buildRecordItemBody(record.name, record.category)),
|
||||
circleIconButton(
|
||||
context: context,
|
||||
icon: Icons.chevron_right,
|
||||
onPressed: () => {},
|
||||
onPressed: () => _handleEditRecord(context, record),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -205,8 +218,10 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
buildCard(context: context, child: recipeCalendar()),
|
||||
Expanded(child: buildCard(context: context, child: dailyItem(context))),
|
||||
buildCard(context: context, child: _recipeCalendar()),
|
||||
Expanded(
|
||||
child: buildCard(context: context, child: _dailyItem(context)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,16 +18,6 @@ class RecipeCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final String firstImageUrl = recipe.recordList.first.imageUrl;
|
||||
|
||||
Widget buildRecipeImage() {
|
||||
return AspectRatio(
|
||||
aspectRatio: 1.5,
|
||||
child: buildNetworkImage(
|
||||
context,
|
||||
'${AppConfig.baseApiUrl}/$firstImageUrl',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildRecipeContent(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -96,12 +86,15 @@ class RecipeCard extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
buildRecipeImage(),
|
||||
buildNetworkImage(
|
||||
context,
|
||||
'${AppConfig.imageBaseUrl}/$firstImageUrl',
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: () => navigatorToRecipeDetail(context),
|
||||
child: buildRecipeContent(context)
|
||||
)
|
||||
child: buildRecipeContent(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -31,17 +31,7 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
}
|
||||
|
||||
Widget buildTimelineCard(BuildContext context, FoodRecord record) {
|
||||
final imageUrls = ['${AppConfig.baseApiUrl}/${record.imageUrl}'];
|
||||
|
||||
void imageTapClick() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) => ImagePreviewPage(images: imageUrls, initialIndex: 0),
|
||||
),
|
||||
);
|
||||
}
|
||||
final imageUrl = '${AppConfig.imageBaseUrl}${record.imageUrl}';
|
||||
|
||||
return buildCard(
|
||||
context: context,
|
||||
@@ -50,7 +40,10 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.date_range, color: Theme.of(context).colorScheme.primary),
|
||||
Icon(
|
||||
Icons.date_range,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
Text(
|
||||
record.date,
|
||||
@@ -65,13 +58,7 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
GestureDetector(
|
||||
onTap: () => imageTapClick(),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1.5,
|
||||
child: buildNetworkImage(context, imageUrls.first),
|
||||
),
|
||||
),
|
||||
buildNetworkImage(context, imageUrl),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user