-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05f4f10
commit 6d0bd01
Showing
8 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:byte_banck/models/contact.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
Future<Database> createDatabase() { | ||
return getDatabasesPath().then((dbPath) { | ||
final String path = join(dbPath, 'bytebanck.db'); | ||
return openDatabase(path, onCreate: (database, version) { | ||
database.execute( | ||
'CREATE TABLE contacts( ' | ||
'id INTEGER PRIMARY KEY, ' | ||
'full_name TEXT, ' | ||
'account_number INTEGER)'); | ||
}, version: 1); | ||
}); | ||
} | ||
|
||
Future<int> save(Contact contact) { | ||
return createDatabase().then((database) { | ||
Map<String, dynamic> contactMap = {}; | ||
contactMap['full_name'] = contact.fullName; | ||
contactMap['account_number'] = contact.accountNumber; | ||
return database.insert('contacts', contactMap); | ||
}); | ||
} | ||
|
||
Future<List<Contact>> findAll() { | ||
return createDatabase().then((database) { | ||
return database.query('contacts').then((maps) { | ||
{ | ||
List<Contact> contacts = []; | ||
for (Map<String, dynamic> map in maps) { | ||
contacts.add( | ||
Contact( | ||
map['id'], | ||
map['full_name'], | ||
map['account_number'], | ||
), | ||
); | ||
} | ||
return contacts; | ||
} | ||
}); | ||
} | ||
); | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
class Contact { | ||
final String fullname; | ||
final int acountNumbe; | ||
final int id; | ||
final String fullName; | ||
final int accountNumber; | ||
|
||
Contact( | ||
this.fullname, | ||
this.acountNumbe, | ||
this.id, | ||
this.fullName, | ||
this.accountNumber, | ||
); | ||
|
||
@override | ||
String toString() { | ||
return 'Contact{fullname: $fullname, acountNumbe: $acountNumbe}'; | ||
return '\nContact: {' | ||
'id: $id, ' | ||
'fullName: $fullName, ' | ||
'acountNumbe: $accountNumber' | ||
'}'; | ||
} | ||
} |
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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