Created
          August 25, 2020 20:25 
        
      - 
      
- 
        Save tiagolpadua/693c7a4557f700b3af51d13770204b13 to your computer and use it in GitHub Desktop. 
    Lista de Contatos
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import 'package:bytebank/database/dao/contact_dao.dart'; | |
| import 'package:bytebank/models/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('Contacts'), | |
| ), | |
| body: FutureBuilder<List<Contact>>( | |
| future: | |
| Future.delayed(Duration(seconds: 1)).then((value) => _dao.findAll()), | |
| builder: (context, snapshot) { | |
| debugPrint('snapshot.connectionState: ${snapshot.connectionState}'); | |
| switch (snapshot.connectionState) { | |
| case ConnectionState.none: | |
| break; | |
| case ConnectionState.waiting: | |
| return Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| children: [ | |
| CircularProgressIndicator(), | |
| Text('Loading'), | |
| ], | |
| ), | |
| ); | |
| break; | |
| case ConnectionState.active: | |
| break; | |
| case ConnectionState.done: | |
| return ListView.builder( | |
| itemCount: snapshot.data.length, | |
| itemBuilder: (context, indice) { | |
| return _ContactItem(snapshot.data[indice]); | |
| }, | |
| ); | |
| break; | |
| } | |
| return Text('Unkown error'); | |
| }), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: () { | |
| Navigator.of(context) | |
| .push(MaterialPageRoute(builder: (context) => ConctactForm())) | |
| .then((newContact) { | |
| setState(() {}); | |
| }); | |
| }, | |
| child: Icon(Icons.add), | |
| ), | |
| ); | |
| } | |
| } | |
| class _ContactItem extends StatelessWidget { | |
| final Contact contact; | |
| const _ContactItem(this.contact); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Card( | |
| child: ListTile( | |
| title: Text( | |
| this.contact.name, | |
| style: TextStyle(fontSize: 24), | |
| ), | |
| subtitle: Text( | |
| this.contact.accountNumber.toString(), | |
| style: TextStyle(fontSize: 16), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment