【问题标题】:showModalBottomSheet stacking when using a Switch使用 Switch 时的 showModalBottomSheet 堆叠
【发布时间】:2021-10-13 05:51:28
【问题描述】:

我正在尝试在我的应用程序的登录屏幕上显示隐私政策横幅。 每当我单击开关时,另一个 ModalBottomSheet 就会堆叠在另一个之上。

我尝试在单独的 Statefullwidget 中提取按钮,没有任何变化。

有什么建议、提示或想法吗?

    var setting = Provider.of<SettingProvider>(context);
    WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
      if (setting.data == false) {
        showModalBottomSheet(
            barrierColor: Colors.blueGrey.withOpacity(0.1),
            isDismissible: false,
            context: context,
            builder: (BuildContext context) {
              return Container(
                padding: EdgeInsets.fromLTRB(30, 10, 30, 0),
                height: 300,
                child: ListView(
                  children: [
                    Center(
                      child: Text(
                        'Datenschutz',
                        style: TextStyle(
                          fontFamily: 'Caveat',
                          fontSize: 25,
                        ),
                      ),
                    ),
                    Text(
                      'Description.',
                      style: TextStyle(fontSize: 10),
                      textAlign: TextAlign.justify,
                    ),
                    SwitchListTile(
                        title: Text(
                          'I agree.',
                          style: TextStyle(fontSize: 10),
                        ),
                        value: setting.initdata,
                        onChanged: (bool value) {
                          setting.changeInitData(value);
                        }),
                    SizedBox(
                      height: 10,
                    ),
                    ElevatedButton(
                        onPressed: () {
                          if (setting.initdata == true) {
                            setting.changeData(setting.initdata);
                            Navigator.pop(context, 'Sichern');
                          } else {
                            Fluttertoast.showToast(
                                msg:
                                    'Error.',
                                gravity: ToastGravity.TOP);
                          }
                        },
                        child: Text('Sichern')),
                  ],
                ),
              );
            });
      }
    });````

【问题讨论】:

    标签: flutter flutter-showmodalbottomsheet


    【解决方案1】:

    我刚刚找到了一种解决方法。可能不是最优雅的方式,但它确实有效。

    在保存隐私设置的按钮中,我使用了Navigator.of(context).pushReplacementNamed(LogInScreen.routeName); 而不是Navigator.pop

    按下Switch 时,模态框仍在堆叠,但用户不必单击多个模态框..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      • 2011-05-01
      • 2021-07-26
      • 1970-01-01
      • 2010-11-18
      相关资源
      最近更新 更多