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 Flutter | |
import UIKit | |
public class SwiftFlutterAlertDemoPlugin: NSObject, FlutterPlugin { | |
public static func register(with registrar: FlutterPluginRegistrar) { | |
let channel = FlutterMethodChannel(name: "flutter_alert_demo", binaryMessenger: registrar.messenger()) | |
let instance = SwiftFlutterAlertDemoPlugin() | |
registrar.addMethodCallDelegate(instance, channel: channel) | |
} |
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:flutter/material.dart'; | |
import 'dart:async'; | |
import 'package:flutter/services.dart'; | |
import 'package:flutter_alert_demo/flutter_alert_demo.dart'; | |
void main() => runApp(new MyApp()); | |
class MyApp extends StatefulWidget { | |
@override |
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
void showCupertinoSheet<T>({BuildContext context}) { | |
showCupertinoModalPopup<T>( | |
context: context, | |
builder: (BuildContext context) => CupertinoActionSheet( | |
title: const Text('Choose Options'), | |
message: const Text('Your options are '), | |
actions: <Widget>[ | |
CupertinoActionSheetAction( | |
child: const Text('One'), | |
onPressed: () { |
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
class Person { | |
int id; | |
String name; | |
String city; | |
Person({this.id, this.name, this.city}); | |
factory Person.fromMap(Map<String, dynamic> json) => new Person( | |
id: json["id"], | |
name: json["name"], |
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
Future<Database> get database async { | |
if (_database != null) return _database; | |
_database = await getDatabaseInstance(); | |
return _database; | |
} | |
Future<Database> getDatabaseInstance() async { | |
Directory directory = await getApplicationDocumentsDirectory(); | |
String path = join(directory.path, "person.db"); | |
return await openDatabase(path, version: 1, |
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
//return all persons from the database | |
Future<List<Person>> getAllPersons() async { | |
final db = await database; | |
var response = await db.query("Person"); | |
List<Person> list = response.map((c) => Person.fromMap(c)).toList(); | |
return list; | |
} | |
//return single person with id | |
Future<Person> getPersonWithId(int id) async { |
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
addPersonToDatabase(Person person) async { | |
final db = await database; | |
var raw = await db.insert( | |
"Person", | |
person.toMap(), | |
conflictAlgorithm: ConflictAlgorithm.replace, | |
); | |
return raw; | |
} |
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
//delete person with id | |
deletePersonWithId(int id) async { | |
final db = await database; | |
return db.delete("Person", where: "id = ?", whereArgs: [id]); | |
} | |
//delete all persons | |
deleteAllPersons() async { | |
final db = await database; | |
db.delete("Person"); |
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
updatePerson(Person person) async { | |
final db = await database; | |
var response = await db.update("Person", person.toMap(), | |
where: "id = ?", whereArgs: [person.id]); | |
return response; | |
} |
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 'dart:async'; | |
import 'dart:io'; | |
import 'package:path/path.dart'; | |
import 'package:path_provider/path_provider.dart'; | |
import 'package:flutter_sqlite/person.dart'; | |
import 'package:sqflite/sqflite.dart'; | |
class PersonDatabaseProvider { | |
PersonDatabaseProvider._(); |