我一直在寻找解决问题的方法。许多人写了一些关于将现有SQLite数据库添加到Flutter的东西,但其中没有一个是确切的。
所以我的问题是如何在Flutter应用程序中添加现有的SQLite数据库(名为products.db
)。我已经创建了产品的模型类,并在其中添加了带有products.db
文件的资产文件夹,当然,我已经使用资产编辑了pubspec.yaml
。
这是我的products.dart
模型类:
class Products {
int _pid;
int _cid;
int _tid;
String _model;
String _description;
String _pictureURI;
double _price;
// Construktor
Products(this._pid,this._cid,this._tid,this._model,this._description,this._pictureURI,this._price);
// getters
int get id => _pid;
int get cid => _cid;
int get tid => _tid;
String get model => _model;
String get description => _description;
String get pictureURI => _pictureURI;
double get price => _price;
// setters dont needed
// Extract a Product Object from a Map Oject
Products.fromMapOject(Map <String,dynamic> map) {
this._pid = map['pid'];
this._cid = map ['cid'];
this._tid = map ['tid'];
this._model = map ['model'];
this._description = map ['description'];
this._pictureURI = map ['pictureURI'];
this._price = map ['price'];
}
}