feat:重构模块
This commit is contained in:
@@ -43,15 +43,17 @@ Widget buildScrollToTop({
|
||||
required BuildContext context,
|
||||
required VoidCallback scrollToTop,
|
||||
}) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Positioned(
|
||||
right: 0,
|
||||
bottom: 20,
|
||||
bottom: 80,
|
||||
child: FloatingActionButton(
|
||||
onPressed: scrollToTop,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
backgroundColor: colors.primary,
|
||||
elevation: 2,
|
||||
mini: true,
|
||||
child: const Icon(Icons.arrow_upward, color: Colors.white),
|
||||
child: Icon(Icons.arrow_upward, color: colors.surface),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,26 +12,26 @@ InputDecoration buildInputDecoration({
|
||||
|
||||
return InputDecoration(
|
||||
hintText: hintText,
|
||||
hintStyle: TextStyle(color: colors.onSurface.withAlpha(100)),
|
||||
hintStyle: Theme.of(context).textTheme.bodyMedium,
|
||||
filled: true,
|
||||
fillColor: colors.surface,
|
||||
border: OutlineInputBorder(
|
||||
borderSide: const BorderSide(color: Color(0xFFE5E7EB)),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide.none,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: colors.primary, width: 2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: const BorderSide(color: Colors.red, width: 2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 15, vertical: 14),
|
||||
errorStyle: const TextStyle(fontSize: 12, height: 1, color: Colors.red),
|
||||
prefixIcon:
|
||||
prefixIcon != null
|
||||
? Icon(prefixIcon, size: 20, color: Color(0xFF86909C))
|
||||
? Icon(prefixIcon, size: 20, color: colors.primary)
|
||||
: null,
|
||||
prefixIconConstraints: const BoxConstraints(minWidth: 40),
|
||||
isDense: true,
|
||||
|
||||
@@ -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),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -43,8 +43,8 @@ Widget buildToggleSwitch<T extends Enum>({
|
||||
totalSwitches: tabValues.length,
|
||||
labels: labels,
|
||||
activeBgColor: [colors.primary],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: colors.surfaceContainer,
|
||||
activeFgColor: colors.surface,
|
||||
inactiveBgColor: colors.surface,
|
||||
inactiveFgColor: colors.onSurface,
|
||||
cornerRadius: 12.0,
|
||||
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
||||
@@ -85,10 +85,10 @@ Widget buildTag(BuildContext context, String title) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary.withAlpha(60),
|
||||
color: colors.primary,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(title, style: TextStyle(color: colors.primary)),
|
||||
child: Text(title, style: TextStyle(color: colors.surface)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,24 +135,10 @@ Widget buildInfoButton({
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
elevation: 0,
|
||||
),
|
||||
child: Text(text, style: TextStyle(color: Colors.white)),
|
||||
child: Text(text),
|
||||
);
|
||||
}
|
||||
|
||||
/// 取消按钮样式
|
||||
ButtonStyle cancelButtonStyle() {
|
||||
return ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all(Colors.grey),
|
||||
shape: WidgetStateProperty.all(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Text buttonText({required String text}) {
|
||||
return Text(text, style: TextStyle(color: Colors.white));
|
||||
}
|
||||
|
||||
/// 图片错误显示
|
||||
Widget errorImageContainer(double height) {
|
||||
return Container(
|
||||
|
||||
Reference in New Issue
Block a user