Eu preencho o form e clico em criar mas preciso voltar pro dashboard e ir pros contatos para o novo contato aparecer. Vi um post falando que era só transformar o Stateless do contacts_list para Stateful, mas não funcionou cmg. Eu transformei em Stateful, executei o codigo dnv e nada diferente aconteceu
import 'package:bytebank2/database/dao/contact_dao.dart';
import 'package:bytebank2/models/contact.dart';
import 'package:bytebank2/screens/contact_form.dart';
import 'package:flutter/material.dart';
class ContactsList extends StatelessWidget {
final ContactDao _dao = ContactDao();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Contacts"),
),
body: FutureBuilder<List<Contact>>(
initialData: List(),
future: _dao.findAll(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
break;
case ConnectionState.waiting:
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
Text("Loading")
],
),
);
break;
case ConnectionState.active:
break;
case ConnectionState.done:
final List<Contact> contacts = snapshot.data;
return ListView.builder(
itemBuilder: (context, index) {
final Contact contact = contacts[index];
return _ContactItem(contact);
},
itemCount: contacts.length,
);
break;
}
return Text("Unknown error");
},
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ContactForm(),
),
);
},
),
);
}
}
class _ContactItem extends StatelessWidget {
final Contact contact;
_ContactItem(this.contact);
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
title: Text(contact.name, style: TextStyle(fontSize: 24)),
subtitle: Text(contact.accountNumber.toString(),
style: TextStyle(fontSize: 16)),
),
);
}
}