【问题标题】:simple_slider widget in flutter doesn't work颤振中的 simple_slider 小部件不起作用
【发布时间】:2020-11-07 16:25:09
【问题描述】:

我将 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) {
                              ^

我犯的错误在哪里? 谢谢。

【问题讨论】:

    标签: flutter widget


    【解决方案1】:

    使用此依赖项

    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),
                ),
              ),
            ],
          ),
        );
      }
    }
    

    【讨论】:

    • 和那个simple_slider类似吗?
    • 这个我也试过了,还是有错误。说与问题错误相同但关于 photo_view 的内容。你能告诉我SDK在这里会造成什么麻烦吗?
    • 我没有遇到任何问题。你能告诉我你把你的颤振SDK放在哪里吗?通常我们放在 c:\src 并确保环境变量中的路径包括 C:\src\flutter\bin
    猜你喜欢
    • 2021-01-14
    • 2021-05-13
    • 1970-01-01
    • 2023-04-11
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    相关资源
    最近更新 更多