Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter Riverpod listview index length

I have a listview which is using flutter_riverpod. The listview have 2 variable.
First variable is word text and second variable is length of index.

ListView.builder(
                      itemCount: ref.watch(itemsProvider).length,
                      itemBuilder: (BuildContext context, int index) {
                        return Row(
                          children: [
                            Text(ref.watch(itemsProvider)[index]),
                            Text(ref.watch(itemsProvider)[index].length),
                          ],
                        );
                      },
                    ),

I am using this listview.builder. the first text of Row is working but second text of Row is not working.
The error:

the argument type ‘int ‘ can’t be assigned to the parameter type ‘string’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I solve this problem. The is no problem in widget. I am using consumerwidget, ref and widgetref. and scopped runapp
Thanks for help.

>Solution :

Text widget seeks from String, Use string format

 Text("${ref.watch(itemsProvider)[index].length}"),

Also, you can use .toString()

More about dart-core

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading