【发布时间】:2022-11-02 12:59:34
【问题描述】:
这是从互联网获取数据的逻辑,加载未完成时显示progressbar小部件,加载完成时显示带有文本字段、图片等的完整小部件树
首先在mainscreen 我检查数据是否从firebase下载
Future<void> getCurrentDriverInfo() async {
// doublenotification++;
currentFirebaseUser = FirebaseAuth.instance.currentUser!;
await driversRef
.child(currentFirebaseUser!.uid)
.once()
.then((DatabaseEvent databaseEvent) {
if (databaseEvent.snapshot.value != null) {
driversInformation = Drivers.fromSnapshot(databaseEvent.snapshot);
}
});
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text("Driver detail downloaded")));
Provider.of<AppData>(context, listen: false).getDriverDetailsDownload(true);
}
这是提供者类
class AppData extends ChangeNotifier {
bool driverDetaildownloaded = false;
void getDriverDetailsDownload(bool driverDetaildownload) {
driverDetaildownloaded = driverDetaildownload;
print("Driverdownload" + driverDetaildownload.toString());
notifyListeners();
}
现在在这个案例中,我想检查数据是否没有下载然后只显示进度条,当数据下载时关闭进度条并显示小部件树
class ProfileTabPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black87,
body: SafeArea(
child: Provider.of<AppData>(context, listen: false)
.driverDetaildownloaded
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
driversInformation!.name!,
style: TextStyle(
fontSize: 65.0,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Signatra',
),
),
]
)
: Center(child: CircularProgressIndicator()),
),
);
}
}
但是 CircularProgressIndicator() 不会关闭并加载小部件。怎么了 ?
【问题讨论】: