リスト 6.5_cf


import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

// リスト 6.5_cf
void main() => runApp(ImagePage());

class ImagePage extends StatelessWidget {
  double? scale;
  double? rotation;

  void listener(PhotoViewControllerValue value) {
    if (value.scale != null) {
      scale = value.scale!;
    }
    rotation = value.rotation;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('ImagePage')
        ),
        body: Center(
          child: PhotoView(
            imageProvider: Image.network('https://flutter.github.io'
                '/assets-for-api-docs/assets/widgets/owl.jpg').image,
            enableRotation: true,
            controller: PhotoViewController()
                          ..outputStateStream.listen(listener),
            backgroundDecoration: BoxDecoration(color: Colors.transparent)
          )
        )
      )
    );
  }
}