首页 > 解决方案 > 加载第一个共享屏幕时多次单击打开多个共享屏幕

问题描述

我应用了共享包来共享一些我想在 android 和 IoS 中打开共享屏幕时显示加载器的数据。如果用户在显示共享屏幕之前多次单击它会打开多个共享屏幕。

ListTile(
                title: Row(
                  children: <Widget>[
                    Icon(
                      Icons.thumbs_up_down,
                      color: DrawerIconsText,
                      size: 24.0,
                    ),
                    SizedBox(
                      width: 10,
                    ),
                    Text('Share App'),
                  ],
                ),
                onTap: () =>
                    Share.share('Share this data'),
              ),

标签: flutterdart

解决方案


嗨,

你应该使用 Statefulwidget 扩展来解决这个问题。

例如:

// change your class extends to Statefulwidget

bool _isShare = false;

@override
didupdatewidget(){
  // change duration time up to you
  if (_isShare) 
    new Timer(const Duration(milliseconds: 400), () {
      setState(()=> _isShare = false);
    });
}

ListTile(
                title: Row(
                  children: <Widget>[
                    Icon(
                      Icons.thumbs_up_down,
                      color: DrawerIconsText,
                      size: 24.0,
                    ),
                    SizedBox(
                      width: 10,
                    ),
                    Text('Share App'),
                  ],
                ),
                onTap: () {
                  if (!_isShare) Share.share('Share this data');
                  setState(() = _isShare = true)
                },
              ),

推荐阅读