lib/photo_view_screen.dart
import 'package:flutter/material.dart';
class PhotoViewScreen extends StatefulWidget {
const PhotoViewScreen({
Key? key,
required this.imageURL,
// 引数から画像のURL一覧を受け取る
required this.imageList,
}) : super(key: key);
final String imageURL;
final List<String> imageList;
@override
_PhotoViewScreenState createState() => _PhotoViewScreenState();
}
class _PhotoViewScreenState extends State<PhotoViewScreen> {
late PageController _controller;
@override
void initState() {
super.initState();
// 受け取った画像一覧から、ページ番号を特定
final int initialPage = widget.imageList.indexOf(widget.imageURL);
_controller = PageController(
initialPage: initialPage,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
// ...
body: Stack(
children: [
PageView(
// ...
// 受け取った画像一覧を表示
children: widget.imageList.map((String imageURL) {
return Image.network(
imageURL,
fit: BoxFit.cover,
);
}).toList(),
),
// ...
],
),
);
}
}