Erro ao criar o banco de dados.
import 'package:bytebank/dao/contact_dao.dart';
import 'package:bytebank/modelos/contact.dart';
import 'package:bytebank/screens/contact_form.dart';
import 'package:flutter/material.dart';
class ContactsList extends StatefulWidget {
@override
_ContactsListState createState() => _ContactsListState();
}
class _ContactsListState extends State<ContactsList> {
final ContactDao _dao = ContactDao();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Contatos'),
),
body: FutureBuilder<List<Contact>>(
initialData: const[],
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')
],
),
);
case ConnectionState.active:
break;
case ConnectionState.done:
// ignore: unused_local_variable
final List<Contact>? contacts = snapshot.data;
return ListView.builder(
itemBuilder: (context, index) {
final Contact contact = contacts![index];
return _ContactItem(contact);
},
itemCount: contacts!.length,
);
}
return Text('Unknown Error');
}),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ContactForm(),
),
)
.then((value) => setState((){}),
);
},
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.name,
style: TextStyle(
fontSize: 24.0,
)),
subtitle: Text(
contact.accountNumber.toString(),
style: TextStyle(fontSize: 16.0),
),
),
);
}
}