close
Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3, flutter error rangeerror index invalid, error rangeerror index invalid value, flutter error rangeerror index

[solved] Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3

Hello Guys How are you all? Hope You all are fine. I am using Listview in my code All the items are rendering fine but also the following error: Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 Occurs ?

I am using Listview in my code All the items are rendering fine but also the following error: 

RangeError (index): Invalid value: Not in range 0..2, inclusive: 3

Here Is my code

  List<String> itemList() {
    return ["Item 1", "Item 2", "Item 3"];
  }

  Widget generateList() {
    List<String> list = itemList();
    ListView myList = new ListView.builder(
      itemBuilder: (context, index) {
        return new ListTile(
          title: new Text(list[index]),
        );
      },
    );
    return myList;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('FlutterCorner'),
      ),
      body: Container(
        child: generateList(),
      ),
    );
  }

Exact Like Above Screenshot

How to solve Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 ?

  1. How to solve Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 ?

    to solve Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 The solution is simple you just have to add itemCount to the builder so that the builder allows it to know the item count. Just like the below Code.

  2. Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3

    to solve Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 The solution is simple you just have to add itemCount to the builder so that the builder allows it to know the item count. Just like the below Code.

Solution 1 : Add itemCount to the builder

The solution is simple you just have to add itemCount to the builder so that the builder allows it to know the item count. Just like the below Code.

  Widget generateList() {
    List<String> list = itemList();
    ListView myList = new ListView.builder(
      itemCount: list.length,
      itemBuilder: (context, index) {
        return new ListTile(
          title: new Text(list[index]),
        );
      },
    );
    return myList;
  }

This Solution worked for me. just add itemCount and give it list of length. So that builder allow to know how much item builder has to build.

Summery

So it’s all About All possible solutions. Hope this above all solution helped you a lot. Comment below Your thoughts and your queries. Comment Below on your suggestion.

Check Out Below Article

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *