dart 文本微件不随值更改而更新-提供程序

lsmd5eda  于 2023-07-31  发布在  其他
关注(0)|答案(1)|浏览(93)

我希望我的小部件重新加载文本更新。我有一个列,它以showGeneralDialog的高度显示,返回WillPopScope。在它里面,我有一个CircularProgressIndicator,它会一直显示,直到后台同步完成。下面,我想显示一个文本,指示同步的进度,如“同步1的10”...这个数字应该在每次同步完成后动态变化。我已准备好提供程序“SyncProvider”。

showLoadingDialog(BuildContext context) {
    showGeneralDialog(
      context: context,
      barrierDismissible: false,
      pageBuilder: (_, __, ___) {      
        return WillPopScope(
          onWillPop: () async => false,
          child: Align(
            alignment: Alignment.center,
            child: Container(
              height: isMobile ? 105.h : 300.h,
              width: isMobile ? 105.w : 300.w,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(15), color: pure_white),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Stack(
                    alignment: Alignment.center,
                    children: [
                      Image.asset(
                        appIconLogoOnly,
                        fit: BoxFit.scaleDown,
                        height: isMobile ? 40.h : 250.h,
                        width: isMobile ? 40.w : 250.w,
                      ),
                      Center(
                        child: ColorfulCircularProgressIndicator(
                          colors: app_colors,
                          strokeWidth: 2.2,
                          duration: const Duration(milliseconds: 500),
                          initialColor: app_colors[0],
                        ),
                      ),
                    ],
                  ),
                  SizedBox(height: isMobile ? 10.h : 20.h,),
                  DefaultTextStyle(
                      style: TextStyle(
                          fontSize: isMobile ? 9 : 15,
                          color: const Color.fromARGB(221, 80, 79, 79),
                          fontWeight: FontWeight.w900),
                      child: Text(
                          "Sync ${ Provider.of<SyncProvider>(context, listen: false).currentSyncProgress} of 10")),
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}```

Appreciate the help!

I tried to get the value by using `Provider.of<SyncProvider>(context, listen: false).currentSyncProgress` but the value is not updating, stays at 0 which I initialized in the `SyncProvider` class.

字符串

fhg3lkii

fhg3lkii1#

在StatefulWideget中分隔返回的Widget,showGeneralDialog没有状态,这就是它没有更改的原因。

showGeneralDialog(
      context: context,
      pageBuilder: (_, __, ___) {
         return MyWidget();   
      },
    );

个字符
希望这对你有帮助

相关问题