我正在尝试用PhotoView做一个简单的任务。我有一个AssetImage,我正在尝试显示图像,用户可以放大/缩小比例。
我使用的是Pubspec依赖项:
photo_view:^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,
),
),
),
),
),
);
}
}
发布于 2020-12-18 01:46:17
我尝试了你的测试代码,它给了我一个错误,但我做了一些修改,如果它工作得很好
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,
),
),
),
),
),
);
}
}
发布于 2021-03-25 21:47:35
如果要添加网络映像,而不是来自资源,请使用PhotoView.customChild:
PhotoView.customChild(
child: Image.network('yourImageUrl')),
https://stackoverflow.com/questions/61599027
复制相似问题