How to get picture from web in flutter

Viewed 61

I am doing scan barcode application, I want to scan the barcode and get picture with information. First, I have successful in get the information with scan a barcode. After this, I want show product picture after scan barcode with their information. So I write below code but I run again application then throws the error Nosuchmethoderror:the method'/' was called on null Tried calling:/(3). So, What should I do that can pass image and information both together.

@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 Answers

I think your screen height and screenwidth is null

You should assign them like

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

I hope this would be helpfull

Related