Когда я хочу получить ссылку на класс Базы данных у меня возникает ошибка "Invalid constructor name". Не могу понять почему это происходит, наверное потому что не знаю всех особенностей языка Dart.
Класс Базы данных
class DatabaseHelperForMeasurements{
static Database db_instance;
final String TABLE_NAME = "Measurements";
Future<Database> get db async{
if(db_instance == null)
db_instance = await initDB();
return db_instance;
}
initDB() async {
io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path,"Measurements_db.db");
var db = await openDatabase(path,version: 1, onCreate: onCreateFunc);
return db;
}
void onCreateFunc(Database db, int version) async{
await db.execute('CREATE TABLE $TABLE_NAME(id INTEGER PRIMARY KEY AUTOINCREMENT, typeOfMuscle TEXT, numberOfMuscle TEXT);');
}
Future<List<MeasurementsDatabaseModel>> getMeasurementsDatabaseModel() async{
var db_connection = await db;
List<Map> list = await db_connection.rawQuery('SELECT * FROM $TABLE_NAME');
List<MeasurementsDatabaseModel> modelList = new List();
for(int i = 0; i < list.length; i++){
MeasurementsDatabaseModel measurementsDatabaseModel = new MeasurementsDatabaseModel();
measurementsDatabaseModel.id = list[i]['id'];
measurementsDatabaseModel.typeOfMuscle = list[i]['typeOfMuscle'];
measurementsDatabaseModel.numberOfMuscle = list[i]['numberOfMuscle'];
modelList.add(measurementsDatabaseModel);
}
return modelList;
}
void getMeasurementsData (String typeOfMuscle, String numberOfMuscle, int id) async{
var db_connection = await db;
String query =
'GET $TABLE_NAME SET typeOfMuscle =\'$typeOfMuscle\', numberOfMuscle =\'$numberOfMuscle\' WHERE id =$id';
await db_connection.transaction((transition) async{
return await transition.rawQuery(query);
});
}
void addNewMeasurementsDatabaseModel(MeasurementsDatabaseModel measurementsDatabaseModel) async {
var db_connection = await db;
String query =
'INSERT INTO $TABLE_NAME(typeOfMuscle, numberOfMuscle) VALUES( \'${measurementsDatabaseModel.typeOfMuscle}\',\'${measurementsDatabaseModel.numberOfMuscle}\')';
await db_connection.transaction((transition) async{
return await transition.rawInsert(query);
});
}
void updateMeasurementsDatabaseModel(MeasurementsDatabaseModel measurementsDatabaseModel) async {
var db_connection = await db;
String query =
'UPDATE $TABLE_NAME SET typeOfMuscle =\'${measurementsDatabaseModel.typeOfMuscle}\', numberOfMuscle =\'${measurementsDatabaseModel.typeOfMuscle}\' WHERE id =${measurementsDatabaseModel.id}';
await db_connection.transaction((transition) async{
return await transition.rawQuery(query);
});
}
void deleteMeasurementsDatabaseModel(MeasurementsDatabaseModel measurementsDatabaseModel) async {
var db_connection = await db;
String query = 'DELETE FROM $TABLE_NAME WHERE id = ${measurementsDatabaseModel.id}';
await db_connection.transaction((transition) async{
return await transition.rawQuery(query);
});
}
}
Класс Моделей
class MeasurementsDatabaseModel{
int id;
String typeOfMuscle;
String numberOfMuscle;
MeasurementsDatabaseModel();
}
Класс где я хочу получить ссылку
class ListItem extends StatefulWidget {
String detail;
int index;
String data;
ListItem({Key key, this.detail, this.index, this.data}) : super(key: key);
@override
_ListItem createState() => _ListItem(); // здесь что-то подсвечивает, сам не смог разобраться
}
class _ListItem extends State<ListItem> {
bool isAppear = false;
DatabaseHelperForMeasurements databaseHelperForMeasurements = new DatabaseHelperForMeasurements();
databaseHelperForMeasurements.getMeasurementsData(typeOfMuscle, numberOfMuscle, id); // здесь возникает ошибка
String typeOfMuscle;
String numberOfMuscle;
// какой-то код
}
}