【问题标题】:Assertion failed: url != null is not true断言失败:url != null 不正确
【发布时间】:2020-09-19 20:57:53
【问题描述】:

════════小部件库捕获的异常═════════════════════════════════════ ═ 在构建 HomePage(dirty, state: _HomePageState#493d9) 时抛出了以下断言: 断言失败: F:\...\painting_network_image_web.dart:23 网址!= null 不是真的

这是我在 home.dart 中添加此代码时遇到的错误

WallpaperModel wallpaperModel = WallpaperModel();
wallpaperModel = WallpaperModel.fromMap(element);
wallpapers.add(wallpaperModel);

还有 /widget/widget.dart

Widget wallpapersList({List<WallpaperModel> wallpapers, context}) { return Container( padding: EdgeInsets.symmetric(horizontal: 15.0), child: GridView.count( shrinkWrap: true, physics: ClampingScrollPhysics(), crossAxisCount: 2, childAspectRatio: 1.0, mainAxisSpacing: 5.0, crossAxisSpacing: 5.0, children: wallpapers.map((wallpaper) { return GridTile( child: Container( child: Image.network(wallpaper.src.portrait), ), ); }).toList(), ), ); }

这是我在执行code 时遇到的错误,我尝试使用flutter clean 然后运行flutter run -v

【问题讨论】:

    标签: api flutter dart


    【解决方案1】:

    看到你的代码后,请更改

    return SrcModel(
      orignal: jsonData["orignal"],
      small: jsonData["small"],
      portrait: jsonData["protrait"],
    );
    

    return SrcModel(
      orignal: jsonData["original"],
      small: jsonData["small"],
      portrait: jsonData["portrait"],
    );
    

    现在我看到了你的照片,我喜欢你的设计

    【讨论】:

    • 我可以看到终端中的所有元素
    • 你可以发布堆栈跟踪吗?
    • 但我看到 url 地址错误为空。为什么会出现这个错误?
    • 我可以看到building HomePage(dirty, state: _HomePageState#493d9): 消息,停止并重新运行您的应用
    • @dev-aentgs 你不能在 initState 中使用 await