feat:重构模块

This commit is contained in:
2026-06-27 17:12:38 +08:00
parent a5e788eee6
commit a340ba424e
31 changed files with 919 additions and 623 deletions

View File

@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:food_hub_app/config/app_config.dart';
import 'package:photo_view/photo_view.dart';
@@ -53,6 +54,8 @@ class _ImagePreviewPageState extends State<ImagePreviewPage> {
@override
Widget build(BuildContext context) {
final index = '${_currentIndex + 1}/${widget.images.length}';
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
@@ -63,10 +66,7 @@ class _ImagePreviewPageState extends State<ImagePreviewPage> {
onPressed: () => Navigator.pop(context),
),
// 显示实时更新的页码(当前索引+1 / 总数量)
title: Text(
'${_currentIndex + 1}/${widget.images.length}',
style: const TextStyle(color: Colors.white),
),
title: Text(index, style: const TextStyle(color: Colors.white)),
centerTitle: true,
),
body: PhotoViewGallery(
@@ -95,21 +95,6 @@ class CommonImage extends StatelessWidget {
const CommonImage({super.key, required this.imageUrls, required this.index});
Widget _buildImageLoadingIndicator(ImageChunkEvent? progress) {
final value =
progress?.expectedTotalBytes != null
? progress!.cumulativeBytesLoaded / progress.expectedTotalBytes!
: null;
return Center(
child: SizedBox(
width: 30,
height: 30,
child: CircularProgressIndicator(value: value),
),
);
}
Widget _buildErrorImage() {
return Container(
color: Colors.grey[200],
@@ -140,14 +125,16 @@ class CommonImage extends StatelessWidget {
onTap: () {
_navigateToImagePreview(context, imageUrls, index);
},
child: Image.network(
'${AppConfig.imageBaseUrl}${imageUrls[index]}',
child: CachedNetworkImage(
imageUrl: '${AppConfig.imageBaseUrl}${imageUrls[index]}',
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return _buildImageLoadingIndicator(loadingProgress);
},
errorBuilder: (context, error, stackTrace) => _buildErrorImage(),
progressIndicatorBuilder:
(context, url, downloadProgress) => CircularProgressIndicator(
strokeWidth: 1.5,
padding: EdgeInsetsGeometry.all(20),
value: downloadProgress.progress,
),
errorWidget: (context, error, stackTrace) => _buildErrorImage(),
),
),
),
@@ -213,19 +200,19 @@ Widget buildImageUploadButton({
onTap: onTap,
borderRadius: BorderRadius.circular(8),
child: Container(
width: 96,
height: 96,
width: double.infinity,
height: 250,
decoration: BoxDecoration(
color: colors.surface,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.black),
border: Border.all(color: colors.surface),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add, color: colors.onSurface.withAlpha(100)),
Icon(Icons.camera_alt, color: colors.onSurface.withAlpha(100)),
SizedBox(height: 6),
Text('添加图片', style: TextStyle(color: colors.onSurface.withAlpha(100))),
Text('点击上传美食图片', style: Theme.of(context).textTheme.bodyMedium),
],
),
),