我想在我的颤振项目中使用提供程序包(4.0),但我收到“试图使用具有可听/流子类型的提供程序”错误/警告。
我的星座:
我有一个Api()
包含用于 firebase-cloudstorage 的基本 CRUD 功能的类。
我有一个EventService()
-class,它使用Api()
带有具体参数的-class。
对于我的观点,我有一个EventOverviewModel
使用 EventService的 ViewModel 类。
我的提供程序配置如下所示:
List<SingleChildWidget> providers = [
...independentServices,
...dependentServices,
...uiConsumableProviders,
];
// Services die unabhängig von anderen sind
List<SingleChildWidget> independentServices = [
Provider<EventService>(create: (_) => EventService(api: Api('events')))
];
// Services die von anderen Services abhängig sind
List<SingleChildWidget> dependentServices = [
ProxyProvider<EventService, EventOverviewModel>(
update: (_, srvc, __) => EventOverviewModel(eventService: srvc),
)
];
List<SingleChildWidget> uiConsumableProviders = [];
Run Code Online (Sandbox Code Playgroud)
一切似乎都在应用程序中工作,但无论如何我都得到了“尝试使用具有可听/流子类型的提供程序”。
我应该如何更改我的代码以不再收到此错误消息?
Running Gradle task 'assembleDebug'...
I/flutter …
Run Code Online (Sandbox Code Playgroud) 我最近尝试使用Elm的Http模块从服务器获取数据,并且我坚持将解码json解码为Elm中的自定义类型.
我的JSON看起来像这样:
[{
"id": 1,
"name": "John",
"address": {
"city": "London",
"street": "A Street",
"id": 1
}
},
{
"id": 2,
"name": "Bob",
"address": {
"city": "New York",
"street": "Another Street",
"id": 1
}
}]
Run Code Online (Sandbox Code Playgroud)
哪个应解码为:
type alias Person =
{
id : Int,
name: String,
address: Address
}
type alias Address =
{
id: Int,
city: String,
street: String
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我发现的是我需要编写解码器功能:
personDecoder: Decoder Person
personDecoder =
object2 Person
("id" := int)
("name" := string)
Run Code Online (Sandbox Code Playgroud)
对于前两个属性,但我如何集成嵌套的Address属性以及如何组合它来解码列表?
我想编写一个泛型函数,用Gson反序列化泛型类型List,代码如下:
private <T> List<T> GetListFromFile(String filename)
{
//Read textfile
BufferedReader reader;
String data="";
try
{
reader = new BufferedReader(new FileReader(filename));
data = reader.readLine();
reader.close();
}
catch (FileNotFoundException ex)
{
}
catch (IOException ex)
{
}
if (data == null)
{
List<T> Spiel = new ArrayList<T>();
return Spiel;
}
else
{
//get list with Deserialise
Gson gson = new Gson();
List<T> something = gson.fromJson(data, new TypeToken<List<T>>(){}.getType());
return something;
}
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码不起作用,我得到一个奇怪的结构,但不是我的类型列表
当我使用时:
List<concreteType> something = gson.fromJson(data, new TypeToken<List<T>>(){}.getType());
Run Code Online (Sandbox Code Playgroud)
我的工作我得到了List<concreteType>
!! …
我有以下代码:
//Marks all users which are reading the book with the bookId
var markAsReading = function (bookId,cb) {
User.find({}, function (err,users) {
if(err)
cb(err);
//Go through all users with lodash each function
_(users).each(function (user) {
//Go through all books
_(user.books).each(function (book) {
if(book.matchId === bookId)
{
user.isReading = true;
//cb();
}
});
});
//Need to callback here!!#1 cb(); -->Not working!
});
//Or better here! cb() --> Not working
};
exports.markAsReading = markAsReading;
Run Code Online (Sandbox Code Playgroud)
我正在将nodejs与mongoose和mongodb一起使用。我想做的事:
我的问题是,仅当位置2上的所有操作都完成时,我才需要回调,但是整个User.find及其嵌套的回调尚未准备好! …