在Stack小部件中颤振可见性没有变化


String fullPath;
bool isLoading = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
bottomNavigationBar: _bottomTab(),
appBar: AppBar(
title: Text('View'),),
body: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Visibility(
visible: isLoading, child: CircularProgressIndicator()),
),
Align(
alignment: Alignment.center,
child: Container(
color: Colors.white,
height: MediaQuery.of(context).size.height / 1.5,
child: WebviewScaffold(
url: weburl,
displayZoomControls: true,
withJavascript: true,
scrollBar: true,
withZoom: true,
hidden: true,
),
),
),
],
),
);
}
void _onItemTapped(int index) {
setState(() {
switch (index) {
case 0:
break;
case 1:
_makingPhoneCall();
break;
case 2:
setState(() {
isLoading = true;
getPermission('download');
});
break;
case 3:
setState(() {
isLoading = true;
getPermission('share');
});
break;
}
});
}
void getPermission(String downOrShare) async {
try {
print("getPermission");
Map<Permission, PermissionStatus> permissions =
await [Permission.storage].request();
print(permissions[Permission.storage]);
String path = await ExtStorage.getExternalStoragePublicDirectory(
ExtStorage.DIRECTORY_DOWNLOADS);
fullPath = "$path/" + type + ".pdf";
download2(dio, pdfUrl, fullPath, downOrShare);
} catch (e) {
print(e);
}
}
void shareFile(File file) async {
try {
setState(() {
isLoading = false;
});
if (!await file.exists()) {
await file.create(recursive: true);
file.writeAsStringSync("test for share documents file");
}
ShareExtend.share(file.path, "file");
} catch (e) {
print(e);
}
}
Future download2(
Dio dio, String url, String savePath, String downOrShare) async {
try {
//get pdf from link
Response response = await dio.get(
url,
onReceiveProgress: showDownloadProgress,
//Received data with List<int>
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
validateStatus: (status) {
return status < 500;
}),
);
//write in download folder
File file = File(savePath);
var raf = file.openSync(mode: FileMode.write);
raf.writeFromSync(response.data);
await raf.close();
if (downOrShare == 'share') {
shareFile(file);
} else if (downOrShare == 'print') {
// printPdf(file);
} else {
isLoading = false;
Fluttertoast.showToast(
msg: type + "Downloaded in " + fullPath,
toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
} catch (e) {
print(e);
}
}

我在我的应用程序中使用webview和底部导航栏。我有下载,分享选项在底部导航。每当我点击下载和共享选项时,我都想显示CircularProgressIndicator()。我也给setState({})使可见的真或假。为什么不工作?

将您的指示器小部件移动到webview小部件的底部

最新更新