我正在尝试在我的定位器中注册一个模型,但是当我在模型中输入参数时我变得不确定。service_locator.dart
import 'package:get_it/get_it.dart';
import '/services/repository_service.dart';
import '/models/addcash.dart';
GetIt locator = GetIt.instance;
void setupLocator() {
// // Register services
locator.registerLazySingleton<RepositoryServiceAddCash>(
() => RepositoryServiceAddCash());
// Register models
locator.registerFactory<AddCash>(
() => AddCash(id, name, amount, data, frequency, isDeleted));
}
参数id
, name
, amount
, data
, frequency
,isDeleted
出现未定义。这是我的模型文件
import 'package:scoped_model/scoped_model.dart';
import 'package:cash_on_hand/service_locator.dart';
import 'package:cash_on_hand/services/repository_service.dart';
import '../data/database.dart';
class AddCash extends Model {
RepositoryServiceAddCash storageService = locator<RepositoryServiceAddCash>();
int id;
String name;
int amount;
String date;
String frequency;
bool isDeleted;
AddCash(this.id, this.name, this.amount, this.date, this.frequency,
this.isDeleted);
AddCash.fromJson(Map<String, dynamic> json) {
this.id = json[DatabaseCreator.id];
this.name = json[DatabaseCreator.name];
this.amount = json[DatabaseCreator.amount];
this.date = json[DatabaseCreator.date];
this.frequency = json[DatabaseCreator.frequency];
this.isDeleted = json[DatabaseCreator.isDeleted] == 1;
}
}