'Is it possible to jump the index of flutter listview?

I'm making a text game with a sf fiction writer. This game is similar to the Japanese visual novel. The story changes through choice.

DB is using sqflite. I am loading text via listview.builder. The list with dialogue is named Notes. I made it with reference to the memo app and did not edit it. But I don't want to load the index sequentially. I thought listview.builder was a for loop. Something is different. I want to change idex but it is difficult for me.

I would like to see 4,5 when it is index 2. index 6 and 7 should not be visible. When index 3, index 4,5 should not be visible. I wish I could jump to index 6 or 7.

Actual index 2 and 3 are buttons. I had to post a question in a hurry, so I made a new one. Can you give me a hint? I also upload a table I made randomly. Even if it is different from the intention of my question, please suggest a good direction. It's ok if it's different from my code. Not using DB, not using sqlite, dividing DB in two, using for loop….

text_game_viewer

dialogue_db.csv

 Widget Builder() {
 return FutureBuilder(
  builder: (context, Snap) {
    if ((Snap.data as List).length == 0) {
      return Container(
        child: Text("add a note"),
      );
    }
    return ListView.builder(
      itemCount: (Snap.data as List).length,
      itemBuilder: (context, index) {
        Memo memo = (Snap.data as List)[index];
        getNextItem(index) {
          return Column(
            children: <Widget>[
              Text(
                memo.title,
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
              Text(memo.text),
              Padding(padding: EdgeInsets.only(bottom: 20))
            ],
          );
        }

        return getNextItem(index);
      },
    );
  },
  future: loadMemo(),
);}


Solution 1:[1]

I don't know if this could help you but there is a lot of solution to do that, what I can share is:

  • you can use Graph approach using a simple chained object list (more complex)
  • you can transform the dialog_db.csv to list of object.

simple demonstration that I haven't test using the csv transformation. You need to adapt the code to your needs

For eg:

class MyDialog {
   final int id;
   final String type;
   final String char;
   final String text;
   final List<int> nextIds; //min element count must be 1
   MyDialog(this.id, this.char, this.type, this.text, this.nextIds);
   @override
   String toString() {
       return "$id, $char, $type, $text";
   }
}

data example

var dialog = [
    MyDialog(1, "Toto", "line", "First line message", [2]),
    MyDialog(2, "Toto", "choice", "Yes or no?", [4,5]),
    MyDialog(3, "Toto", "line", "must be hidden", [100]),
    MyDialog(4, "Toto", "choice", "YES", [7]),
    MyDialog(5, "Toto", "choice", "NO", [8]),
    //...
];

implementation example:

void test() {
    //show the dialog 1
    showDialog(1);
    //then 2 and his next dialog, the dialog 3 must be skiped
    showDialog(2);
  }

  MyDialog getDialog(int id) {
    return dialog.where((element) => element.id == id).first;
  }

  void showDialog(int id) {
    var d = getDialog(id);
    print(d);
    for (var i in d.nextIds) {
      print("next: " + getDialog(i).toString());
    }
  }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 niaina