lib/photo_view_screen.dart
import 'package:flutter/material.dart';
import 'package:photoapp/photo.dart';
class PhotoViewScreen extends StatefulWidget {
const PhotoViewScreen({
Key? key,
required this.photo,
required this.photoList,
}) : super(key: key);
// StringではなくPhotoで受け取る
final Photo photo;
final List<Photo> photoList;
@override
_PhotoViewScreenState createState() => _PhotoViewScreenState();
}
class _PhotoViewScreenState extends State<PhotoViewScreen> {
late PageController _controller;
@override
void initState() {
super.initState();
final int initialPage = widget.photoList.indexOf(widget.photo);
// ...
}
@override
Widget build(BuildContext context) {
return Scaffold(
// ...
body: Stack(
children: [
PageView(
controller: _controller,
onPageChanged: (int index) => {},
children: widget.photoList.map((Photo photo) {
return Image.network(
photo.imageURL,
fit: BoxFit.cover,
);
}).toList(),
),
// ...
],
),
);
}
}