2025-10-20 10:44:59 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
import 'package:photo_view/photo_view.dart';
|
|
|
|
|
import 'package:photo_view/photo_view_gallery.dart';
|
|
|
|
|
|
|
|
|
|
class LookImagesTool {
|
|
|
|
|
static lookImages({
|
|
|
|
|
required List<String> listData,
|
|
|
|
|
int? currentPage,
|
|
|
|
|
}) async {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: Get.context!,
|
2025-11-03 15:03:54 +08:00
|
|
|
useSafeArea: false,
|
2025-10-20 10:44:59 +08:00
|
|
|
builder: (_) {
|
|
|
|
|
return LookImagesWidget(
|
|
|
|
|
listData: listData,
|
|
|
|
|
currentPage: currentPage,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class LookImagesWidget extends StatefulWidget {
|
|
|
|
|
final List<String> listData;
|
|
|
|
|
final int? currentPage;
|
|
|
|
|
|
|
|
|
|
const LookImagesWidget({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.listData,
|
|
|
|
|
this.currentPage,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<LookImagesWidget> createState() => _LookImagesWidgetState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LookImagesWidgetState extends State<LookImagesWidget> {
|
|
|
|
|
List listData = [];
|
|
|
|
|
late int currentPage;
|
|
|
|
|
late int initialPage = 0;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
listData = widget.listData;
|
|
|
|
|
if (widget.currentPage == null) {
|
|
|
|
|
initialPage = 0;
|
|
|
|
|
currentPage = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// initialPage = 0;
|
|
|
|
|
currentPage = widget.currentPage ?? 0;
|
|
|
|
|
}
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-11-03 15:01:55 +08:00
|
|
|
return Scaffold(
|
|
|
|
|
body: Stack(
|
2025-10-20 10:44:59 +08:00
|
|
|
children: [
|
2025-11-03 15:01:55 +08:00
|
|
|
PhotoViewGallery.builder(
|
|
|
|
|
itemCount: listData.length,
|
|
|
|
|
pageController: PageController(initialPage: currentPage),
|
|
|
|
|
onPageChanged: (index) {
|
|
|
|
|
setState(() {
|
|
|
|
|
currentPage = index;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
builder: (_, index) {
|
|
|
|
|
return PhotoViewGalleryPageOptions(
|
|
|
|
|
imageProvider: NetworkImage(
|
|
|
|
|
listData[index],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-10-20 10:44:59 +08:00
|
|
|
),
|
2025-11-03 15:01:55 +08:00
|
|
|
Positioned(
|
|
|
|
|
left: 15,
|
|
|
|
|
top: 50,
|
|
|
|
|
child: GestureDetector(onTap: () => Get.back(), child: Icon(Icons.arrow_back_ios, color: Colors.white))),
|
2025-10-20 10:44:59 +08:00
|
|
|
//图片张数指示器
|
|
|
|
|
Positioned(
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
bottom: 20,
|
|
|
|
|
child: Container(
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
child: Text(
|
|
|
|
|
"${currentPage + 1}/${listData.length}",
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|