小编Art*_*ine的帖子

如何在颤动中在按下/手指/鼠标/光标位置显示菜单

我有这段代码是从Style clipboard in flutter 中得到的

showMenu(
        context: context,
        // TODO: Position dynamically based on cursor or textfield
        position: RelativeRect.fromLTRB(0.0, 600.0, 300.0, 0.0),
        items: [
          PopupMenuItem(
            child: Row(
              children: <Widget>[
                // TODO: Dynamic items / handle click
                PopupMenuItem(
                  child: Text(
                    "Paste",
                    style: Theme.of(context)
                        .textTheme
                        .body2
                        .copyWith(color: Colors.red),
                  ),
                ),
                PopupMenuItem(
                  child: Text("Select All"),
                ),
              ],
            ),
          ),
        ],
      );
Run Code Online (Sandbox Code Playgroud)

这段代码效果很好,除了创建的弹出窗口位于固定位置之外,我将如何使它在鼠标/按下/手指/光标位置或附近的某个位置弹出,有点像你想要的时候复制并粘贴到您的手机上。(此对话框弹出不会用于复制和粘贴)

dart flutter flutter-layout

11
推荐指数
2
解决办法
7729
查看次数

在 Flutter 中临时从树中移除时保留小部件状态

我正在尝试保留小部件的状态,以便如果我暂时从小部件树中删除有状态小部件,然后稍后重新添加它,小部件将具有与删除之前相同的状态。这是我的一个简化示例:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool showCounterWidget = true;
  @override
  Widget build(BuildContext context) {

    return Material(
      child: Center(
        // Center is a layout widget. …
Run Code Online (Sandbox Code Playgroud)

state state-management dart flutter statefulwidget

7
推荐指数
2
解决办法
3961
查看次数