问题描述
我将simple_slider的依赖项添加到依赖项(simple_slider: "^0.0.1"
下的pubspec.yaml文件中。我安装了它(应用程序运行没有错误)。但是当我添加以下代码时出现错误。
import 'package:Flutter/material.dart';
import 'package:simple_slider/simple_slider.dart';
class HomeScreen extends StatelessWidget {
final _imageUrls = [
"assets/cus.png","assets/trans.png","assets/cus.png","assets/sea.jpg",];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Container(
child: ImageSliderWidget(
imageUrls: _imageUrls,imageBorderRadius: BorderRadius.circular(10.0),imageHeight: 8,),],);
}
}
错误是
Compiler message:
/C:/Users/B.R.P.Perera/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/cached_network_image-0.4.2/lib/cached_network_image.dart:460:24: Error: The method 'CachednetworkImageProvider.load' has fewer positional arguments than those of overridden method 'ImageProvider.load'.
imagestreamCompleter load(CachednetworkImageProvider key) {
^
/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/painting/image_provider.dart:403:24: Context: This is the overridden method ('load').
imagestreamCompleter load(T key,DecoderCallback decode);
^
/C:/Users/B.R.P.Perera/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/cached_network_image-0.4.2/lib/cached_network_image.dart:199:38: Error: The argument type 'void Function(ImageInfo,bool)' can't be assigned to the parameter type 'imagestreamListener'.
- 'ImageInfo' is from 'package:Flutter/src/painting/image_stream.dart' ('/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/painting/image_stream.dart').
- 'imagestreamListener' is from 'package:Flutter/src/painting/image_stream.dart' ('/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/painting/image_stream.dart').
oldimagestream?.removeListener(_handleImageChanged);
^
/C:/Users/B.R.P.Perera/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/cached_network_image-0.4.2/lib/cached_network_image.dart:200:32: Error: The argument type 'void Function(ImageInfo,bool)' can't be assigned to the parameter type 'imagestreamListener'.
- 'ImageInfo' is from 'package:Flutter/src/painting/image_stream.dart' ('/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/painting/image_stream.dart').
- 'imagestreamListener' is from 'package:Flutter/src/painting/image_stream.dart' ('/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/painting/image_stream.dart').
_imagestream.addListener(_handleImageChanged);
^
/C:/Users/B.R.P.Perera/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/cached_network_image-0.4.2/lib/cached_network_image.dart:210:34: Error: The argument type 'void Function(ImageInfo,bool)' can't be assigned to the parameter type 'imagestreamListener'.
- 'ImageInfo' is from 'package:Flutter/src/painting/image_stream.dart' ('/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/painting/image_stream.dart').
- 'imagestreamListener' is from 'package:Flutter/src/painting/image_stream.dart' ('/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/painting/image_stream.dart').
_imagestream?.removeListener(_handleImageChanged);
^
/C:/Users/B.R.P.Perera/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/cached_network_image-0.4.2/lib/cached_network_image.dart:464:31: Error: The argument type 'Null Function(StringBuffer)' can't be assigned to the parameter type 'Iterable<DiagnosticsNode> Function()'.
- 'StringBuffer' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
- 'DiagnosticsNode' is from 'package:Flutter/src/foundation/diagnostics.dart' ('/D:/Flutter/SDK/Flutter/packages/Flutter/lib/src/foundation/diagnostics.dart').
informationCollector: (StringBuffer information) {
^
我做过的错误在哪里? 谢谢。
解决方法
使用此依赖项
photo_view: ^0.10.2
尝试此代码。我对其进行了测试,并且运行正常
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';
class PhotoViewScreen extends StatelessWidget {
final List<String> imageList = [
'https://images.unsplash.com/photo-1533450718592-29d45635f0a9','https://images.unsplash.com/photo-1601902572612-3c850fab3ad8',];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Image Preview')),body: Stack(
children: [
Container(
child: PhotoViewGallery.builder(
scrollPhysics: const BouncingScrollPhysics(),builder: (BuildContext context,int index) {
return PhotoViewGalleryPageOptions(
imageProvider: NetworkImage(imageList[index]),initialScale: PhotoViewComputedScale.contained * 1,minScale: .01,maxScale: 1.0
//heroAttributes: HeroAttributes(tag: galleryItems[index].id),);
},itemCount: imageList.length,//galleryItems.length,loadingBuilder: (context,event) => Center(
child: Container(
width: 50.0,height: 50.0,child: CircularProgressIndicator(
value: event == null
? 0
: event.cumulativeBytesLoaded /
event.expectedTotalBytes,),backgroundDecoration: BoxDecoration(color: Colors.white),],);
}
}