How to get the height and width of a imageProvider in flutter?

Viewed 1436

In Flutter, How to get the width and height of a imageProvider?

In the example below, I need to get the width of the imageProvider. So that I can calculate the minScale for the PhotoView widget in photo_view package.

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

class ImageViewerScreen extends StatelessWidget {

  final ImageProvider imageProvider;

  ImageViewerScreen({@required this.imageProvider});

  @override
  Widget build(BuildContext context) {
    final double _screenWidth = MediaQuery.of(context).size.width;
    final double _imageWidth =
        imageProvider.width; //Here is the question: how to get the width of this imageProvider?
    final double _minScale = _screenWidth / _imageWidth;

    return Scaffold(
      appBar: AppBar(),
      body: Container(
          child: PhotoView(
        imageProvider: imageProvider,
        minScale: _minScale,
      )),
    );
  }
}
0 Answers
Related