Видимость флаттера в виджете стека не меняется

#flutter #dart

Вопрос:

 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({}) , чтобы сделать видимым истинное или ложное. Почему это не работает?

Ответ №1:

Переместите виджет индикатора в нижнюю часть виджета webview

Комментарии:

1. нет, я хочу, чтобы индикатор был в центре страницы