Flutter 颤振中有无模态对话框?
颤振中是否有类似的无模式对话框?如果没有,是否可以构建具有无模式对话框属性的小部件 我将尝试更详细地解释。我的源问题已编辑。 通过单击画布,我必须调用_handleTappdown函数: 在此函数中,需要可视化无模式小部件:Flutter 颤振中有无模态对话框?,flutter,Flutter,颤振中是否有类似的无模式对话框?如果没有,是否可以构建具有无模式对话框属性的小部件 我将尝试更详细地解释。我的源问题已编辑。 通过单击画布,我必须调用_handleTappdown函数: 在此函数中,需要可视化无模式小部件: 您可以使用Overlay将小部件添加到最上面;你想怎么用就怎么用 类无模式扩展StatefulWidget{ 最后一个孩子; 无模式({this.child}); @凌驾 _ModeLessState createState()=>new_ModeLessState();
您可以使用
Overlay
将小部件添加到最上面;你想怎么用就怎么用
类无模式扩展StatefulWidget{
最后一个孩子;
无模式({this.child});
@凌驾
_ModeLessState createState()=>new_ModeLessState();
}
类_ModeLessState扩展状态{
无模式上入口;
@凌驾
void initState(){
super.initState();
无模式=新覆盖入口(
不透明:假,
生成器:(上下文){
返回新位置(
排名:50.0,
左:50.0,
孩子:新尺寸的盒子(
身高:50.0,
孩子:新卡(
孩子:新文本(“我是无模式的”)
),
),
);
});
Future.microtask(){
覆盖.of(上下文).insert(无模式);
});
}
@凌驾
无效处置(){
modeless.remove();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回widget.child;
}
}
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();
}
OverlayEntry
_无模式=空;
void\u showModeless(构建上下文)
{
_无模式=新覆盖入口(
不透明:假,
生成器:(上下文){
返回新位置(
排名:100.0,
左:100.0,
儿童:
新行(
mainAxisAlignment:mainAxisAlignment.start,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
新图标(Icons.content\u粘贴,颜色:Colors.blueGrey),
新填料(
填充:仅限常量边集(左:16.0),
子项:新文本('Modeless',溢出:TextOverflow.省略号,
样式:新的TextStyle(fontSize:14.0,fontWeight:fontWeight.bold,颜色:Colors.lightBlue,装饰:TextEdition.none
),
),
),
],
),
);
});
Overlay.of(context).insert(_非模态);
_startWaiting();
}
静态常数超时=常数持续时间(秒:8);
静态计时器_Timer=null;
void_startWaiting()
{
_计时器=新计时器(超时,\u handleTimeout);
}
void _handleTimeout()
{
如果(_无模式!=null)
_modeless.remove();
}
另外,我只添加了另一个函数,允许在8秒后删除无模式。再次感谢。请添加更多细节,以帮助其他人更好地理解您的问题,如果可能,请添加代码示例或您想要或试图实现的内容的图像。您可以创建无模式对话。选中showDialogue方法,并创建自己的custimized@Tree这就创建了一个模态对话框,它会阻塞屏幕的其余部分,我认为这是OP试图避免的。尽管需要对此进行一些澄清,但非模态与模态正好相反<代码>显示对话框仅显示模态
Overlay
用于Modalesi试图更详细地解释:我的源问题已更新。编译器在构造中告诉错误:Future.microtask((){Overlay.of(context).insert(modeless);});也许“newfuture.microtask((){..})”?在dart2new
中应该是可选的。但是,是的,如果您需要,请添加I如何在函数体中呈现此小部件_showModeless:void _showModeless(BuildContext context){//如何显示无模式小部件?}我不理解,我编辑了消息并澄清了问题。我希望我能得到答案。
void _showModeless (BuildContext context)
{
// How do I show Modeless Widget?
}
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;
}
}
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();
}