Data not inserted oncreate #632
Unanswered
machadoapoena
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Im trying to insert data oncreate but no data was inserted. DB was created.
`final cbkDataInsert = Callback(
onCreate: (database, version) {
database.insert('tb_stock',
{'name': 'ITAUSA', 'abbreviation': 'ITSA4', 'division': 'Financeiro'},
conflictAlgorithm: ConflictAlgorithm.replace);
});
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await initServices();
runApp(MyApp(
db: await $FloorAppDataBase
.databaseBuilder('mystockreport.db')
.addCallback(cbkDataInsert)
.build()));
}
@entity(tableName: 'tb_stock')
class Stock extends EntityBase {
final String name;
final String abbreviation;
final String division;
Stock({int id, this.name, this.abbreviation, this.division}) : super(id);
factory Stock.fromJson(Map<String, dynamic> json) {
return Stock(
id: json['id'],
name: json['name'],
abbreviation: json['abbreviation'],
division: json['division']);
}
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"abbreviation": abbreviation,
'division': division
};
}
`
Beta Was this translation helpful? Give feedback.
All reactions