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
//lib/sqlite/db_helper.dart | |
import 'dart:io'; | |
import 'package:path_provider/path_provider.dart'; | |
import 'package:sqflite/sqflite.dart'; | |
import 'package:path/path.dart'; | |
import 'models/dog_model.dart'; |
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
//Create | |
createData(Dog dog) async { | |
final db = await database; | |
var res = await db.rawInsert('INSERT INTO $TableName(name) VALUES(?)', [dog.name]); | |
return res; | |
} | |
//Read | |
getDog(int id) async { | |
final db = await database; |
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
class Dog { | |
final int id; | |
final String name; | |
Dog({this.id, this.name}); | |
} |
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
Function makeAdder(num addBy) { | |
return (num i) => addBy + i; | |
} | |
void main() { | |
var add2 = makeAdder(2); | |
var add4 = makeAdder(4); | |
print(add2(3)); | |
print(add4(3)); |
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
import 'dart:async'; | |
import 'dart:isolate'; | |
void main() { | |
Isolate.spawn(sendMessage, 'Hello'); | |
Isolate.spawn(sendMessage, 'Greetings'); | |
Isolate.spawn(sendMessage, 'Welcome'); | |
} | |
void sendMessage(var message) { |
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
void main() { | |
//Iterable | |
Stream.fromIterable([1,2,3,4,5]) | |
.listen((int x) => print('iterable : ${x}')); | |
//Periodic | |
Stream.periodic(Duration(seconds: 1), (x) => x) | |
.take(5) | |
.listen((x) => print('take : ${x}')); |
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
import 'dart:async'; | |
main() async { | |
countSeconds(4); | |
await message(); | |
} | |
void countSeconds(s) { | |
for(var i=1; i<=s; i++ ) { | |
Future.delayed(Duration(seconds: i), () => print(i)); |
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
import 'dart:async'; | |
int a = 0; | |
void main() async { | |
print('first'); | |
func(); | |
print('second'); | |
await func(); | |
print('third'); |
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
void main(){ | |
var data = [1, 2, 3, 4, 5]; | |
//forEach | |
print('forEach1'); | |
var eachData = data.forEach((value) { | |
print(value); | |
return value; | |
}); | |
//print(eachData); //eachData is void. |
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
void main(){ | |
var movie = Movie(); | |
movie..showCount() | |
..showCount() | |
..showCount(); | |
var last = movie..minusCount() | |
..minusCount() | |
..minusCount(); | |
print('last:$last'); |
NewerOlder