import 'package:flutter/material.dart';
import 'package:flutter2/components/progress.dart';
import 'package:flutter2/database/app_database.dart';
import 'package:flutter2/models/contact.dart';
import 'package:flutter2/screens/transaction_form.dart';
import 'contact_form.dart';
class ContactList extends StatefulWidget {
@override
_ContactListState createState() => _ContactListState();
}
class _ContactListState extends State<ContactList> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Transfer'),
),
body: FutureBuilder<List<Contact>>(
initialData: List(),
future: findAll(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
// TODO: Handle this case.
break;
case ConnectionState.waiting:
return Progress(
message: 'Loading Contacts',
);
break;
case ConnectionState.active:
break;
case ConnectionState.done:
final List<Contact> contacts = snapshot.data;
return ListView.builder(
itemBuilder: (context, index) {
final contact = contacts[index];
return _ContactItem(
contact,
onClick: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => TransactionForm(contact),
),
);
},
);
},
itemCount: contacts.length,
);
break;
}
return Text('unknown error!');
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ContactForm(),
),
);
},
child: Icon(
Icons.add,
),
),
);
}
}
class _ContactItem extends StatelessWidget {
final Contact contact;
final Function onClick;
_ContactItem(this.contact, {@required this.onClick});
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
onTap: onClick(),
title: Text(
contact.name,
style: TextStyle(fontSize: 24.0),
),
subtitle: Text(contact.accountNumber.toString(),
style: TextStyle(fontSize: 16.0))));
}
}