【问题标题】:How to add a draggable "textfield" to add text over images in flutter?如何添加可拖动的“文本字段”以在颤动的图像上添加文本?
【发布时间】:2020-01-18 04:16:10
【问题描述】:

我正在颤振中创建一个 Meme 生成器应用程序..我只需要知道用户本身是否可以在图像上添加文本并将该文本拖动到图像区域的任何位置...这样图片会看起来很有趣.我尝试了拖动框小部件,但不知道如何将它用于文本字段..这样我也可以将我的文本移动到图像上的任何位置。I need something like this

【问题讨论】:

  • 您可以在帖子中包含图片。你应该至少有一个你迄今为止尝试过的例子。

标签: flutter dart textfield photo


【解决方案1】:
    class TextOverImage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        Size size = MediaQuery.of(context).size;
        return Scaffold(
        appBar: AppBar(
            centerTitle: true,
            title: Text('Text Over Image Image Example'),
        ),
        body: Center(
            child: Container(
            height: 300,
            width: 300,
            child: Stack(
                children: <Widget>[
                Container(
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(5),
                        color: Colors.blue,
                        image: DecorationImage(
                            image: new NetworkImage(
                                "https://thumbs.dreamstime.com/b/funny-face-baby-27701492.jpg"),
                            fit: BoxFit.fill)),
                ),
                HomePage()
                ],
            ),
            ),
        ),
        );
    }
    }

    class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() => _HomePageState();
    }

    class _HomePageState extends State<HomePage> {
    Offset offset = Offset.zero;

    @override
    Widget build(BuildContext context) {
        return Container(
        child: Positioned(
            left: offset.dx,
            top: offset.dy,
            child: GestureDetector(
                onPanUpdate: (details) {
                setState(() {
                    offset = Offset(
                        offset.dx + details.delta.dx, offset.dy + details.delta.dy);
                });
                },
                child: SizedBox(
                width: 300,
                height: 300,
                child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Center(
                    child: Text("You Think You Are Funny But You Are Not",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 28.0,
                            color: Colors.red)),
                    ),
                ),
                )),
        ),
        );
    }
    }

【讨论】:

  • 感谢@amitprajapati 的解决方案..它工作得很好..但是还缺少一个小的附加部分..有没有办法可以手动将文本拖放到图像上的另一个位置本身..我对 "Dragbox" 小部件有一些想法..但不知道如何在其中集成文本..如果您提出一些建议,那就太好了..!
  • 是的@amit prajapati ..我尝试了更新的代码,但我面临“媒体查询大小”的错误..所以从昨天开始..我正在尝试解决这个问题..但是得到了通过
  • 我现在尝试了..它就像一个魅力..非常感谢您的解决方案@amit prajapati..!
  • 享受你的代码,别忘了检查答案作为标记
  • 再次感谢您..我检查了标记的答案..您的努力是无价的..!
猜你喜欢
  • 1970-01-01
  • 2019-11-05
  • 1970-01-01
  • 2021-04-23
  • 1970-01-01
  • 1970-01-01
  • 2012-07-15
  • 2017-06-17
  • 1970-01-01
相关资源
最近更新 更多