以下是用于将数据从Firebase实时数据库加载到列表中的代码段:
size=len(classes)
mobile = tf.keras.applications.mobilenet.MobileNet( include_top=False,
input_shape=(image_size,image_size,3),
pooling='avg', weights='imagenet',
alpha=1, depth_multiplier=1)
x=mobile.layers[-1].output
x=keras.layers.BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001 )(x)
predictions=Dense (len(classes), activation='softmax')(x)
model = Model(inputs=mobile.input, outputs=predictions)
for layer in model.layers:
layer.trainable=True
model.compile(Adamax(lr=lr_rate), loss='categorical_crossentropy', metrics=['accuracy'])
[1]: https://keras.io/api/applications/mobilenet/
[2]: https://keras.io/api/callbacks/reduce_lr_on_plateau/
[3]: https://keras.io/api/callbacks/model_checkpoint/
[4]: https://keras.io/api/optimizers/adamax/
我将这些数据存储到列表中,并将其显示在ListView.builder中。 我想在数据完全加载后显示该屏幕,同时它显示某种加载小部件或加载屏幕,但在我的情况下,该屏幕看起来空白,并且在一段时间后显示数据。如果互联网连接速度慢,则会出现一分钟的空白屏幕并加载它(因为我的数据也包含图像)。我也想如果加载时间超过某个特定时间,它将显示尝试重新加载或互联网连接错误。请帮忙。
答案 0 :(得分:1)
正如其他人已经说过的那样,我认为最好的解决方案是像这样的FutureBuilder:
FutureBuilder(
future: //your future you want the data from,
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text("None");
case ConnectionState.active:
return Text("active");
case ConnectionState.waiting: /while you are waiting for the data...
return CupertinoActivityIndicator(); //thats the typical apple loading
return CircularProgressIndicator(); // this would be a blue circle
case ConnectionState.done:
//you have the data and can access it with 'snapshot.data'
}
}),