0

我正在尝试用 PhotoView 做一个简单的任务。我有一个 AssetImage,我正在尝试显示图像,用户可以放大/缩小比例。

我正在使用 Pubspec 依赖项:

照片视图:^0.9.2

我在网上找到了这个测试代码,但似乎也不起作用:(

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



class KodetrApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Photo View',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Photo View'),
        ),
        body: Center(
          child: AspectRatio(
            aspectRatio: 16 / 9,
            child: ClipRect(
              child: PhotoView(
                imageProvider: NetworkImage(
                  'https://kodetr.herokuapp.com/banners/post/flutter/flutter_photoview.webp',
                ),
                minScale: PhotoViewComputedScale.contained * 0.8,
                maxScale: PhotoViewComputedScale.covered * 2,
                enableRotation: true,

              ),
            ),
          ),
        ),
      ),
    );
  }
}
4

2 回答 2

0

我尝试了您的测试代码,它给了我一个错误,但我做了一些更改,如果它工作正常

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



class KodetrApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Photo View',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Photo View'),
        ),
        body: Center(
          child: AspectRatio(
            aspectRatio: 16 / 9,
            child: ClipRect(
              child: PhotoView(
                imageProvider: AssetImage(ADD IMAGE HERE),
                minScale: PhotoViewComputedScale.contained * 0.8,
                maxScale: PhotoViewComputedScale.covered * 2,
                enableRotation: true,

              ),
            ),
          ),
        ),
      ),
    );
  }
}
于 2020-12-17T17:46:17.103 回答
0

如果要添加网络图像而不是资产,请使用 PhotoView.customChild:

PhotoView.customChild(
child: Image.network('yourImageUrl')),
于 2021-03-25T13:47:34.803 回答