Skip to content

Commit

Permalink
Listagem na tela dos contatos salvos no database.
Browse files Browse the repository at this point in the history
  • Loading branch information
GamaGustavo committed Feb 3, 2022
1 parent 6d0bd01 commit 5571cc6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
6 changes: 0 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import 'package:byte_banck/database/app_database.dart';
import 'package:flutter/material.dart';

import 'screans/dashboard.dart';

void main() {
runApp(const ByteBanck());

findAll().then((value) {
debugPrint(value.toString());
});

}

class ByteBanck extends StatelessWidget {
Expand Down
76 changes: 61 additions & 15 deletions lib/screans/contact_list.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:byte_banck/database/app_database.dart';
import 'package:byte_banck/models/contact.dart';
import 'package:flutter/material.dart';

import 'contact_form.dart';
Expand All @@ -11,26 +13,70 @@ class ContactsList extends StatelessWidget {
appBar: AppBar(
title: const Text("Contacts"),
),
body: ListView(
children: const [
Card(
child: ListTile(
title: Text('Gustavo',style: TextStyle(fontSize: 22.0),),
subtitle: Text('20000'),
),
)
],
body: FutureBuilder<List<Contact>>(
future: Future.delayed(const Duration(seconds: 5)).then((value) => findAll()),
initialData: const [],
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
break;
case ConnectionState.waiting:
return Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(color:Theme.of(context).colorScheme.secondary,),
const Text('Loading'),
],
),
);
case ConnectionState.active:
break;
case ConnectionState.done:
final List<Contact> contacts = snapshot.data;
return ListView.builder(
itemBuilder: (context, index) {
return _ContactIten(
contact: contacts.elementAt(index),
);
},
itemCount: contacts.length,
);
}
return const Text('Unknown error');
},
),
floatingActionButton: FloatingActionButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ContactForm(),
),
).then((value) {
debugPrint(value.toString());
onPressed: () => Navigator.of(context)
.push(
MaterialPageRoute(
builder: (context) => const ContactForm(),
),
)
.then((value) {
debugPrint(value.toString());
}),
child: const Icon(Icons.add),
),
);
}
}

class _ContactIten extends StatelessWidget {
const _ContactIten({Key? key, required this.contact}) : super(key: key);
final Contact contact;

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

0 comments on commit 5571cc6

Please sign in to comment.