如何在颤振中从网络获取图片

问题描述

我正在做扫描条码应用程序,我想扫描条码并获取带有信息的图片。首先,我通过扫描条形码成功获取了信息。在此之后,我想在扫描带有信息的条形码后显示产品图片。所以我写了下面的代码,但我再次运行应用程序然后抛出错误 Nosuchmethoderror:the method'/' was called on null Tried calling:/(3)。那么,我该怎么做才能同时传递图像和信息。

@override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFF121212),body: Center(
        child: product == null
            ? Text(
                  "Value : ${widget.code}",style: TextStyle(color: Colors.blue),)
          : Container(
                child: Column(
                  children: <Widget>[
                    Container(
                    height: screenHeight / 3,width: screenWidth / 1.5,child: CachednetworkImage(
                          fit: BoxFit.fill,imageUrl:
                              "https://smileylion.com/easyshopping/productimage/${product.code}.jpg",placeholder: (context,url) =>
                              new CircularProgressIndicator(),errorWidget: (context,url,error) =>
                              new Icon(Icons.error),),Text(
                      "CODE: ${product.code}",style: TextStyle(fontSize: 20,color: Colors.white),

解决方法

我认为你的屏幕高度和屏幕宽度为空

你应该像这样分配它们

Widget build(BuildContext context) {
screenWidth =MediaQuery.of(context).size.width;
screenHeight=MediaQuery.of(context).size.height;
return ...

希望对你有帮助

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...