- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以通过按下操作按钮来动态创建弹出菜单(PopupMenuButton)并在屏幕中间显示此菜单?比如如何修改标准的flutter应用来实现这个场景:
void _showPopupMenu()
{
// Create and show popup menu
...
}
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
// counter didn't reset back to zero; the application is not restarted.
primarySwatch: Colors.blue,
),
home: new TouchTestPage(title: 'Flutter Demo Home Page'),
);
}
}
class TouchTestPage extends StatefulWidget {
TouchTestPage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_TouchTestPageState createState() => new _TouchTestPageState();
}
class _TouchTestPageState extends State<TouchTestPage> {
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return new Scaffold(
appBar: new AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: new Text(widget.title),
),
body: new Container(
decoration: new BoxDecoration(
color: Colors.white70,
gradient: new LinearGradient(
colors: <Color>[Colors.lightBlue, Colors.white30]),
border: new Border.all(
color: Colors.blueGrey,
width: 1.0,
),
),
child: new Center(child: new TouchControl()),
),
);
}
}
class TouchControl extends StatefulWidget {
final double xPos;
final double yPos;
final ValueChanged<Offset> onChanged;
const TouchControl({
Key key,
this.onChanged,
this.xPos: 0.0,
this.yPos: 0.0,
})
: super(key: key);
@override
TouchControlState createState() => new TouchControlState();
}
class TouchControlState extends State<TouchControl> {
double xPos = 0.0;
double yPos = 0.0;
double xStart = 0.0;
double yStart = 0.0;
double _scale = 1.0;
double _prevScale = null;
void reset()
{
xPos = 0.0;
yPos = 0.0;
}
final List<String> popupRoutes = <String>[
"Properties", "Delete", "Leave"
];
String selectedPopupRoute = "Properties";
void _showPopupMenu3(BuildContext context)
{
showMenu<String>(
context: context,
initialValue: selectedPopupRoute,
position: new RelativeRect.fromLTRB(40.0, 60.0, 100.0, 100.0),
items: popupRoutes.map((String popupRoute) {
return new PopupMenuItem<String>(
child: new
ListTile(
leading: const Icon(Icons.visibility),
title: new Text(popupRoute),
onTap: ()
{
setState(()
{
print("onTap [${popupRoute}] ");
selectedPopupRoute = popupRoute;
});
}
),
value: popupRoute,
);
}).toList(),
);
}
void onChanged(Offset offset)
{
final RenderBox referenceBox = context.findRenderObject();
Offset position = referenceBox.globalToLocal(offset);
if (widget.onChanged != null)
{
// print('---- onChanged.CHANGE ----');
widget.onChanged(position);
}
else
{
// print('---- onChanged.NO CHANGE ----');
}
xPos = position.dx;
yPos = position.dy;
}
@override
bool hitTestSelf(Offset position) => true;
void _handlePanStart(DragStartDetails details) {
print('start');
// _scene.clear();
final RenderBox referenceBox = context.findRenderObject();
Offset position = referenceBox.globalToLocal(details.globalPosition);
onChanged(details.globalPosition);
xStart = xPos;
yStart = yPos;
}
void _handlePanEnd(DragEndDetails details) {
print("_handlePanEnd");
print('end');
}
void _handleTapDown(TapDownDetails details) {
print('--- _handleTapDown ---');
final RenderBox referenceBox = context.findRenderObject();
Offset position = referenceBox.globalToLocal(details.globalPosition);
onChanged(new Offset(0.0, 0.0));
_showPopupMenu3(context); //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
print('+++ _handleTapDown [${position.dx},${position.dy}] +++');
}
void _handleTapUp(TapUpDetails details) {
// _scene.clear();
print('--- _handleTapUp ---');
final RenderBox referenceBox = context.findRenderObject();
Offset position = referenceBox.globalToLocal(details.globalPosition);
onChanged(new Offset(0.0, 0.0));
//_showPopupMenu(context);
print('+++ _handleTapUp [${position.dx},${position.dy}] +++');
}
void _handleDoubleTap() {
print('_handleDoubleTap');
}
void _handleLongPress() {
print('_handleLongPress');
}
void _handlePanUpdate(DragUpdateDetails details) {
// logger.clear("_handlePanUpdate");
final RenderBox referenceBox = context.findRenderObject();
Offset position = referenceBox.globalToLocal(details.globalPosition);
onChanged(details.globalPosition);
}
@override
Widget build(BuildContext context) {
return new ConstrainedBox(
constraints: new BoxConstraints.expand(),
child: new GestureDetector(
behavior: HitTestBehavior.opaque,
onPanStart: _handlePanStart,
onPanEnd: _handlePanEnd,
onPanUpdate: _handlePanUpdate,
onTapDown: _handleTapDown,
onTapUp: _handleTapUp,
onDoubleTap: _handleDoubleTap,
onLongPress: _handleLongPress,
// onScaleStart: _handleScaleStart,
// onScaleUpdate: _handleScaleUpdate,
// onScaleEnd: _handleScaleEnd,
// child: new CustomPaint(
// size: new Size(xPos, yPos),
// painter: new ScenePainter(editor.getScene()),
// foregroundPainter: new TouchControlPainter(/*_scene*//*editor.getScene(),*/ xPos, yPos),
// ),
),
);
}
}
最佳答案
对的,这是可能的
void _showPopupMenu() async {
await showMenu(
context: context,
position: RelativeRect.fromLTRB(100, 100, 100, 100),
items: [
PopupMenuItem(
value: 1
child: Text("View"),
),
PopupMenuItem(
value: 2
child: Text("Edit"),
),
PopupMenuItem(
value: 3
child: Text("Delete"),
),
],
elevation: 8.0,
).then((value){
// NOTE: even you didnt select item this method will be called with null of value so you should call your call back with checking if value is not null
if(value!=null)
print(value);
});
}
GestureDetector(
onTapDown: (TapDownDetails details) {
_showPopupMenu(details.globalPosition);
},
child: Container(child: Text("Press Me")),
);
然后 _showPopupMenu 会像
_showPopupMenu(Offset offset) async {
double left = offset.dx;
double top = offset.dy;
await showMenu(
context: context,
position: RelativeRect.fromLTRB(left, top, 0, 0),
items: [
...,
elevation: 8.0,
);
}
关于popup - 如何在flutter中动态创建和显示弹出菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50758121/
希望你能帮助我。我阅读并再次阅读了 Magnific Popup 的文档,但我对 javascript 还不够好。 1- 我用这个链接打开一个弹出窗口: OPEN POPUP 和这个 javascri
我最近刚刚实现了“Magnific Popup”并且弹出窗口很好,但是当我单击一个输入框时,整个弹出窗口消失回到父页面。在插件网站上显示的示例中,整个对话框都是可单击的,直到您在该框外单击。 我希望它
我的弹出窗口正常工作,但有时用户会点击浏览器上的后退按钮关闭弹出窗口。 如何让浏览器后退按钮关闭已经打开的“magnific-popup”? 谢谢 最佳答案 经过一些挖掘发现 history.js 然
我制作了一个带有华丽弹出窗口的视频库。 但与图片库不同的是,视频库不显示计数器,例如1/3 在视频的右下角。为什么不?在图片库中,它运行良好。 视频库代码: $('.gallery_video').e
我正在使用 magnific popup 和 ajax 将内容加载到其中,并通过将查询字符串附加到 url 将值传递给 ajax 内容,除了在 IE7(可能还有 IE8)中工作正常。原因很可能是查询字
有没有办法绑定(bind)一个事件回调,以便为 Magnific Popup 的所有实例调用它?在我正在构建的网站上,当主浏览器滚动条消失时,几个元素具有固定位置和“跳转”。我想设置一个回调以在打开任
$.magnificPopup.open({ items: { src: $('#cabinet-msg') }, type:'inline', mid
在 jquery 对话框中我们可以做 $("#id").dialog('open|close') 打开关闭对话框。如何在 Magnific-popup 中做到这一点? 最佳答案 $.magnificP
我正在以这种方式制作新窗口: var WSHShell = WScript.CreateObject("WScript.Shell"); WSHShell.Popup("This is popup."
我打开一个带有 js 弹出窗口的 html 页面 Link to popup 现在我的弹出窗口中有一些链接,我想关闭我的链接的弹出窗口 onclick 并在旧窗口中打开链接。对于旧窗口,我指的是
无法在放大的弹出窗口中播放视频。 当我使用 class=iframe ,页面将重定向到 youtube 并播放视频。 但是当我使用 class=popup-youtube ,将显示弹出窗口,但我收到以
我有一个 Leaflet Popup 附加到一个标记,它给用户两个按钮来使用 jQuery 取消或移动到另一个页面。 这些按钮最初工作正常,除非您曾经准确地单击标记以使 Popup 消失,然后再次单击
我有 2 个 JQM 页面和 1 个它们共享的弹出窗口。我有一个事件处理程序绑定(bind)到两者的“pagecreate”,里面有这样的代码: $(document).on("pagecreate"
System.InvalidOperationException: You MUST call Rg.Plugins.Popup.Popup.Init(); prior to using it. 我已
测试 Magnific Popup 当前是否“打开”的最佳方法是什么? 检查某个 div 的存在是否会成为 future 的证明? 例如,如果我使用: if ($(".mfp-ready").leng
我的指令有问题。如果我从弹出 Controller 调用 $scope.popup.show = false 行,它就可以正常工作。如果我从子 contentDirective 调用 $scope.h
我在popup.js中有两个变量。我想把它们放在一起到一个 url ,无论如何就像 chrome.tabs.create({active: true, url: "https://"+savedApi
我有一些代码,它允许用户检查复选框并在提交时打开与新选项卡中的复选框关联的网址。如果两个复选框都被选中,则会打开两个选项卡。它的工作原理与预期一致,看起来像: document.getElementB
我有一个弹出窗口,其高度约为屏幕的 70%。我在这个弹出窗口中有 2 个 div, header-div 具有固定高度,例如20px 和一个 content-div,它应该使用剩余的可用高度。 目前我
我正在构建一个包含教程的 MMO。 当用户在教程中尝试离开教程或关闭选项卡/浏览器时,我需要显示一个自定义弹出窗口,其中包含有关用户退出教程的原因的选项。 我熟悉 onbeforeunload 事件,
我是一名优秀的程序员,十分优秀!