lib/photo_view_screen.dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:photoapp/photo.dart';
import 'package:photoapp/providers.dart';
import 'package:share/share.dart';
class PhotoViewScreen extends StatefulWidget {
@override
_PhotoViewScreenState createState() => _PhotoViewScreenState();
}
class _PhotoViewScreenState extends State<PhotoViewScreen> {
// ...
@override
Widget build(BuildContext context) {
return Scaffold(
// ...
body: Stack(
children: [
// ...
Align(
alignment: Alignment.bottomCenter,
child: Container(
// ...
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () => _onTapShare(),
color: Colors.white,
icon: Icon(Icons.share),
),
// ...
],
),
),
),
],
),
);
}
// ...
Future<void> _onTapShare() async {
final photoList = context.read(photoListProvider).data!.value;
final photo = photoList[_controller.page!.toInt()];
// 画像URLを共有
await Share.share(photo.imageURL);
}
}