首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Flutter中有无模式对话框吗?

Flutter中有无模式对话框吗?
EN

Stack Overflow用户
提问于 2018-06-19 02:44:43
回答 2查看 487关注 0票数 1

Flutter中有没有类似于的无模式对话框?如果不是,是否可以使用无模式对话框的属性来构建小部件?

我将尝试更详细地解释。我的原始问题被编辑过了。通过单击画布,我必须调用_handleTapDown函数:

代码语言:javascript
复制
void _handleTapDown (TapDownDetails details)
{
      _showModeless (context);
}

在此函数中,需要可视化您的无模式小部件:

代码语言:javascript
复制
void _showModeless (BuildContext context)
{
// How do I show Modeless Widget?
}
EN

回答 2

Stack Overflow用户

发布于 2018-06-19 03:30:02

您可以使用Overlay添加小部件,并随心所欲地使用它们。

代码语言:javascript
复制
class ModeLess extends StatefulWidget {
  final Widget child;

  ModeLess({this.child});

  @override
  _ModeLessState createState() => new _ModeLessState();
}

class _ModeLessState extends State<ModeLess> {
  OverlayEntry modeless;

  @override
  void initState() {
    super.initState();
    modeless = new OverlayEntry(
        opaque: false,
        builder: (context) {
          return new Positioned(
            top: 50.0,
            left: 50.0,
            child: new SizedBox(
              height: 50.0,
              child: new Card(
                child: new Text("I'm a modeless")
              ),
            ),
          );
        });

    Future.microtask(() {
      Overlay.of(context).insert(modeless);
    });
  }

  @override
  void dispose() {
    modeless.remove();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }
}
票数 2
EN

Stack Overflow用户

发布于 2018-06-21 14:09:01

Rémi Rousselet,非常感谢。你的建议很有帮助。下面是我需要的函数原型:

代码语言:javascript
复制
  OverlayEntry
    _modeless = null;

  void _showModeless(BuildContext context)
  {
     _modeless = new OverlayEntry(
        opaque: false,
        builder: (context) {
          return new Positioned(
            top: 100.0,
            left: 100.0,
            child:
            new Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                new Icon(Icons.content_paste, color: Colors.blueGrey),
                  new Padding(
                    padding: const EdgeInsets.only(left: 16.0),
                    child: new Text('Modeless', overflow: TextOverflow.ellipsis,
                      style: new TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold, color: Colors.lightBlue, decoration: TextDecoration.none
                      ),
                    ),
                  ),
              ],
            ),
          );
        });
    Overlay.of(context).insert(_modeless);
     _startWaiting();
  }

 static const TIMEOUT = const Duration(seconds: 8);
 static Timer _timer = null;

  void _startWaiting()
  {
    _timer = new Timer(TIMEOUT, _handleTimeout);
  }

  void _handleTimeout()
  {
    if (_modeless != null)
      _modeless.remove();
  }

PS。我只添加了另一个函数,允许在8秒后删除无模式。再次非常感谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50915680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档