2
respostas

Pagina não é atualizada após de inclusão de item / 2

import 'package:bytebank2/database/app_database.dart'; import 'package:bytebank2/modelo/contact.dart'; import 'package:bytebank2/screens/contactForm.dart'; import 'package:flutter/material.dart';

class ContactsList extends StatelessWidget {

final List contacts = List();

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Contacts'), ), //AppBar body: FutureBuilder<List>( initialData: List(), future: findAll(), builder: (context, snapshot) { switch(snapshot.connectionState){

        case ConnectionState.none:
          findAll();
          break;
        case ConnectionState.waiting:
          Center(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                CircularProgressIndicator(),
                Text('Carregando'),
              ],
            ),
          );
          break;
        case ConnectionState.active:
          break;
        case ConnectionState.done:

          final List<Contact> contacts = snapshot.data;
          return ListView.builder(
              itemCount: contacts.length,
              itemBuilder: (context, index) {
                final Contact contact = contacts[index];
                return _ContactItem(contact);
              }
          );
          break;
      }
      return Text("Erro desconhecido.");
    },
  ),

  floatingActionButton: FloatingActionButton(
    onPressed: () {
      Navigator.of(context).push(
        MaterialPageRoute(builder: (context) => ContactForm(),),
      );
    },
    child: Icon(Icons.add,),
  ),
);}

}

class _ContactItem extends StatelessWidget { final Contact contact;

_ContactItem(this.contact);

@override Widget build(BuildContext context) { return Card( child: ListTile( title: Text(contact.nome,style: TextStyle(fontSize: 18),), subtitle: Text(contact.accountNumber.toString(),style: TextStyle(fontSize: 16)), ), ); } }

2 respostas

Deve-se mudar para steleafull e criar a classe State igual o FormContact

Se possível post o código da pagina inteira.

Outra coisa, remover o código findAll() do Status NONE.