1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] flutter textfield restore last value

Discussão em 'Mobile' iniciado por Stack, Outubro 1, 2024 às 11:04.

  1. Stack

    Stack Membro Participativo

    I have an error with flutter text field , lets say I have a list of models , each one will be responsible on showing a text field on the screen ,

    List<MyModel>

    so after using this list to showing a text fields and adding some text inside each text field and lets say 1,2,3,4

    when I try to remove the model at index 1 with represent the text field that holds the value of 2 in the ui ,

    it is removed correctly from the list but on the ui all text fields updates their state so that the shows values will be 1,2,3 not as expected 1,3,4,

    I think the problem in the render tree , it keeps its sequence and just removes the last item in the tree,

    I've tried to give each text field a key , in this case it work fine but the state for the item will be lost 1,null,null

    my question is how to make the widget tree reflect these changes correctly.

    here is an image for the showing of text fields

    [​IMG]

    and this is the state for all three columns

    class SsrTableState extends ChangeNotifier {
    var cells = <TableRow>[];

    removeAt(dynamic cardKey) {
    print(cells.map((e) => e.key).toList());
    print(cardKey);

    cells = cells.where((t) => t.key != cardKey).toList();

    print(cells.map((e) => e.key).toList());

    notifyListeners();
    }
    }

    Continue reading...

Compartilhe esta Página