Flutter中有没有类似于的无模式对话框?如果不是,是否可以使用无模式对话框的属性来构建小部件?
我将尝试更详细地解释。我的原始问题被编辑过了。通过单击画布,我必须调用_handleTapDown函数:
void _handleTapDown (TapDownDetails details)
{
_showModeless (context);
}
在此函数中,需要可视化您的无模式小部件:
void _showModeless (BuildContext context)
{
// How do I show Modeless Widget?
}
发布于 2018-06-19 03:30:02
您可以使用Overlay
添加小部件,并随心所欲地使用它们。
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;
}
}
发布于 2018-06-21 14:09:01
Rémi Rousselet,非常感谢。你的建议很有帮助。下面是我需要的函数原型:
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秒后删除无模式。再次非常感谢。
https://stackoverflow.com/questions/50915680
复制相似问题