flutter_integrated_whb/lib/customWidget/single_image_viewer.dart

44 lines
1.3 KiB
Dart
Raw Normal View History

import 'dart:io';
2025-07-11 11:03:21 +08:00
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
// 查看大图
class SingleImageViewer extends StatelessWidget {
final String imageUrl;
const SingleImageViewer({Key? key, required this.imageUrl}) : super(key: key);
@override
Widget build(BuildContext context) {
ImageProvider provider;
if (imageUrl.toLowerCase().startsWith('http')) {
provider = NetworkImage(imageUrl);
} else {
provider = FileImage(File(imageUrl));
}
2025-07-11 11:03:21 +08:00
return Scaffold(
backgroundColor: Colors.black.withValues(alpha: 0.5),
2025-07-11 11:03:21 +08:00
appBar: MyAppbar(
2025-07-28 14:22:07 +08:00
isBack: false,
actions: [
IconButton(onPressed: () {
Navigator.of(context).pop();
}, icon: Icon(Icons.close, color: Colors.white, size: 40,),)
],
backgroundColor: Colors.black.withValues(alpha:0.5), title: '',
2025-07-11 11:03:21 +08:00
),
body: Center(
child: PhotoView(
imageProvider: provider,
backgroundDecoration: BoxDecoration(color: Colors.black.withValues(alpha:0.5)),
2025-07-11 11:03:21 +08:00
minScale: PhotoViewComputedScale.contained,
maxScale: PhotoViewComputedScale.covered * 2,
onTapUp: (context, details, controllerValue) {
Navigator.of(context).pop();
},
),
),
);
}
}