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

时间:2021-03-22 15:59:15

标签: php image flutter dart barcode-scanner

我正在做扫描条码应用程序,我想扫描条码并获取带有信息的图片。首先,我通过扫描条形码成功获取了信息。在此之后,我想在扫描带有信息的条形码后显示产品图片。所以我写了下面的代码,但我再次运行应用程序然后抛出错误 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),
                    ),

1 个答案:

答案 0 :(得分:0)

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

你应该像这样分配它们

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

希望对你有帮助