如何添加可拖动的“文本字段”以在颤振中的图像上添加文本?

2023-12-21

我正在 flutter 中创建一个 Meme 生成器应用程序。我只需要知道是否有一种方法,用户本身可以在图像上添加文本并将该文本拖动到图像区域中的任何位置...这样图片看起来很有趣。我尝试过拖动框小部件,但不知道如何将其用于文本字段。这样我也可以将文本移动到图像上的任何位置。我需要这样的东西 https://i.stack.imgur.com/sgeH5.jpg


    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)),
                    ),
                ),
                )),
        ),
        );
    }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何添加可拖动的“文本字段”以在颤振中的图像上添加文本? 的相关文章

随机推荐