-
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.
Persistência com Flutter: Crie um app com armazenamento interno
- Loading branch information
Showing
23 changed files
with
391 additions
and
30 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 @@ | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.7+2\\\\","dependencies":[]}],"android":[{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.7+2\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"sqflite","dependencies":[]}],"date_created":"2020-07-28 09:43:34.384780","version":"1.17.5"} |
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
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
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
13 changes: 13 additions & 0 deletions
13
android/app/src/main/kotlin/br/com/alura/bytebank/MainActivity.kt
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,13 @@ | ||
package br.com.alura.bytebank | ||
|
||
import android.os.Bundle | ||
|
||
import io.flutter.app.FlutterActivity | ||
import io.flutter.plugins.GeneratedPluginRegistrant | ||
|
||
class MainActivity: FlutterActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
GeneratedPluginRegistrant.registerWith(this) | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import UIKit | ||
import Flutter | ||
|
||
@UIApplicationMain | ||
@objc class AppDelegate: FlutterAppDelegate { | ||
override func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
) -> Bool { | ||
GeneratedPluginRegistrant.register(with: self) | ||
return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
} | ||
} |
Binary file modified
BIN
-180 Bytes
(98%)
ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
#import "GeneratedPluginRegistrant.h" |
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,15 @@ | ||
import 'package:bytebank/database/dao/contact_dao.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
Future<Database> getDatabase() async { | ||
final String path = join(await getDatabasesPath(), 'bytebank.db'); | ||
return openDatabase( | ||
path, | ||
onCreate: (db, version) { | ||
db.execute(ContactDao.tableSql); | ||
}, | ||
version: 1, | ||
); | ||
} | ||
|
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,48 @@ | ||
import 'package:bytebank/models/contact.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
import 'package:bytebank/database/app_database.dart'; | ||
|
||
class ContactDao { | ||
|
||
static const String tableSql = 'CREATE TABLE $_tableName(' | ||
'$_id INTEGER PRIMARY KEY, ' | ||
'$_name TEXT, ' | ||
'$_accountNumber INTEGER)'; | ||
static const String _tableName = 'contacts'; | ||
static const String _id = 'id'; | ||
static const String _name = 'name'; | ||
static const String _accountNumber = 'account_number'; | ||
|
||
Future<int> save(Contact contact) async { | ||
final Database db = await getDatabase(); | ||
Map<String, dynamic> contactMap = _toMap(contact); | ||
return db.insert(_tableName, contactMap); | ||
} | ||
|
||
Future<List<Contact>> findAll() async { | ||
final Database db = await getDatabase(); | ||
final List<Map<String, dynamic>> result = await db.query(_tableName); | ||
List<Contact> contacts = _toList(result); | ||
return contacts; | ||
} | ||
|
||
Map<String, dynamic> _toMap(Contact contact) { | ||
final Map<String, dynamic> contactMap = Map(); | ||
contactMap[_name] = contact.name; | ||
contactMap[_accountNumber] = contact.accountNumber; | ||
return contactMap; | ||
} | ||
|
||
List<Contact> _toList(List<Map<String, dynamic>> result) { | ||
final List<Contact> contacts = List(); | ||
for (Map<String, dynamic> row in result) { | ||
final Contact contact = Contact( | ||
row[_id], | ||
row[_name], | ||
row[_accountNumber], | ||
); | ||
contacts.add(contact); | ||
} | ||
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Contact { | ||
final int id; | ||
final String name; | ||
final int accountNumber; | ||
|
||
Contact( | ||
this.id, | ||
this.name, | ||
this.accountNumber, | ||
); | ||
|
||
@override | ||
String toString() { | ||
return 'Contact{id: $id, name: $name, accountNumber: $accountNumber}'; | ||
} | ||
} |
Oops, something went wrong.