【问题标题】:Failed assertion: line 373 pos 7: 'pixels == null || (minScrollExtent != null && maxScrollExtent != null)'断言失败:第 373 行 pos 7: 'pixels == null || (minScrollExtent != null && maxScrollExtent != null)'
【发布时间】:2021-01-18 12:54:28
【问题描述】:

我是 Flutter 的新手,所以当我尝试从 api 获取 图像 并将它们添加到列表中然后使用 时,我无法解决 page view exception列表中的 foreach 循环 以在 carousel pro

中显示图像

我的代码是--

 if (widget.user_id != null) {
      body = jsonEncode(<String, dynamic>{
        'respObj': {
          "Id": widget.user_id,
        },
      });
    } else {
      body = jsonEncode(<String, dynamic>{});
    }
 final http.Response response = await http.post(
      'api url',
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: body,
    );
    var res = json.decode(response.body);
    if (response.statusCode == 200) {
      res["resplist"].forEach((element){
        setState(() {
          images.add(element["categoryBanner"]);
        });
      });
      images.forEach((element) {
        setState(() {
          _img.add(NetworkImage(element));
        });
      });
    } else {
      images==null;
    }

    Widget imageCrousel = Container(
      height: 140.0,
      child: Carousel(
        indicatorBgPadding: 5.0,
        dotIncreasedColor: Colors.red,
        dotColor: Colors.white,
        boxFit: BoxFit.cover,
        images:_img==null?
        [AssetImage('assets/defimg.jpg')]:_img,
        autoplay: false,
        animationCurve: Curves.fastOutSlowIn,
        animationDuration: Duration(milliseconds: 1000),
      ),
    );

例外---

Page value is only available after content dimensions are established.
'package:flutter/src/widgets/page_view.dart':
Failed assertion: line 373 pos 7: 'pixels == null || (minScrollExtent != null && maxScrollExtent != null)'

【问题讨论】:

    标签: flutter flutter-layout carousel flutter-dependencies pageviews


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2021-04-06
    • 2020-06-05
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 2019-05-24
    • 2020-08-31
    相关资源
    最近更新 更多