0

I am getting this error: type 'List>' is not a subtype of type 'List'

Here is the code that's triggering the error.

@override
  Widget build(BuildContext context) {
    if (widget.productId != null) {
      return StreamBuilder(
          stream:
              Document<Product>(path: 'app-data-inventory/${widget.productId}')
                  .streamData(),
          builder: (BuildContext context, AsyncSnapshot snap) {
            if (snap.hasError) {
              print(snap.error);
            }
            if (snap.hasData) {
              Product product = snap.data;

              return Scaffold(
                resizeToAvoidBottomPadding: false,
                backgroundColor: AppAppTheme.white,
                appBar: appBarComponents,
                key: _scaffoldKey,
                body: Stack(
                  children: <Widget>[
                       Builder(
                            builder: (context) => SingleChildScrollView(
                              child: Column(
                                  crossAxisAlignment:
                                      CrossAxisAlignment.stretch,
                                  mainAxisSize: MainAxisSize.min,
                                  children: [
                                    Container(
                                      color: AppAppTheme.primary,
                                      height: 230,
                                      child: _yourWidget(context, product.productStorage['paths']),
                                    ),
                                    SizedBox(
                                      height: 10,
                                    ),
                                    CheckboxListTile(
                                        title: const Text('Terms of services'),
                                        value: _product.termsAgreed != null
                                            ? _product.termsAgreed
                                            : false,
                                        onChanged: (val) {
                                          setState(
                                              () => _product.termsAgreed = val);
                                        }),
                                    SwitchListTile(
                                        title: const Text('Save as draft'),
                                        value: _product.productStatus == 'draft'
                                            ? true
                                            : false,
                                        onChanged: (bool val) => setState(() {
                                              _product.productStatus =
                                                  val ? 'draft' : 'unapproved';
                                            })),
                                  ]),
                            ),
                          )

                    ),
                  ],
                ),
                  ),
                ),
              );
            } else {
              return UIErrorsMessages.notFoundComponent(
                  context, 'Product not found!');
            }
          });
    } else {
      return UIErrorsMessages.somethingIsNotRightComponent(
          context, 'Something went wrong. Try again!');
    }
  }
}

How can I solve this?

0

1 Answer 1

1

You should fetch the data first using FutureBuilder and then provide the data to your widgets.

Following code should work for you:

(I didn't have the full code so I have not tested this, in case of any issue please comment)

Widget _yourWidget(BuildContext context) {
    return 
          color: AppTheme.primary,
          height: 230,
          child: Wrap(
            children: 
            paths.map<Widget>((url) {
              return FutureBuilder(builder: (BuildContext context, AsyncSnapshot snapshot) {
                if (snapshot.hasData){
                  file = snapshot.data;
                  print(file);
                  return Column(
                    children: <Widget>[
                      FlatButton(
                        child: Text(
                          'Delete',
                          style: AppTheme
                              .titleWhite,
                        ),
                        onPressed: () {
                          print(url);
                        },
                      ),
                      Container(
                        width: 100.0,
                        height: 100.0,
                        margin:
                            EdgeInsets
                                .all(
                                    10),
                        color:
                            AppTheme
                                .warn,
                        child: ExtendedImage
                            .network(file ==
                                    null
                                ? '/assets/icons/icon-120x120.png'
                                : file),
                      )
                    ],
                  );
                }else{
                  return Center(child: CircularProgressIndicator());
                }
              },);
       });
  }

  Future fetchDownloadURL(){
    return await _storage
               .ref()
             .child(url)
             .getDownloadURL();
  }
Sign up to request clarification or add additional context in comments.

13 Comments

Thank you. But just calling future: fetchDownloadURL(), won't make sense. Given that it requires an argument(url) for it to return the downloadURL. The urls are in an array call paths. So one will need to do some type of loop to get each url before passing the argument to future: fetchDownloadURL(),. Unless I am getting it all wrong??
Wrap FutureBuilder around Column Widget and give url in parameter to fetchDownloadURL() and it should work for you.
I have something like this: Stack( children: <Widget>[ Builder( builder: (context) => SingleChildScrollView( child: Column( children: [ Container( child: _yourWidget(context, paths) But I do get the url not defined error on the fetchDownloadUrl(). Probably I am not understanding what you mean.
Every thing is correct, the thing is if you want to use Future in your widget tree then you need to use FutureBuilder. In your code you are using Future over the Column Widget because you need data there. Now wrap that widget with FutureBuilder and when you receive data pass it to Column till then show loading widgetor some thing like that.
Thank you. I will add an update to my question code. Hopefully, you'll guide me through better.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.