扑来 - 不要用文字和容器包裹

发布于 2025-01-22 09:13:16 字数 1652 浏览 3 评论 0原文

我有此代码:

import 'package:flutter/material.dart';

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

class mainApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Chat(),
    );
  }
}

class Chat extends StatefulWidget {
  const Chat({Key? key}) : super(key: key);

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

class _ChatState extends State<Chat> {
  List<InlineSpan> myList = [
    TextSpan(text: 'Hello, my name '),
    WidgetSpan(
      child: Container(
        color: Colors.orange,
        child: GestureDetector(
          onTap: () {
            print('tap');
          },
          child: Container(
            child: Padding(
              padding: const EdgeInsets.all(4.0),
              child: Text(
                'is',
                style: TextStyle(fontSize: 25.0),
              ),
            ),
          ),
        ),
      ),
    ),
    TextSpan(text: ' Gabriele, and i am 21 years old!'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: RichText(
          text: TextSpan(
            style: TextStyle(fontSize: 25.0, color: Colors.black),
            children: myList,
          ),
        ),
      ),
    );
  }
}

这是我当前的输出:

”“在此处输入图像说明”

如您在图像中所看到的,单词'is'(以橙色为obly)略微向上移动。

我如何才能使它与否则的水平相同? (例如,通过对中心的所有方面对齐水平轴..)

我希望你能帮我。

谢谢 :)

i have this code:

import 'package:flutter/material.dart';

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

class mainApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Chat(),
    );
  }
}

class Chat extends StatefulWidget {
  const Chat({Key? key}) : super(key: key);

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

class _ChatState extends State<Chat> {
  List<InlineSpan> myList = [
    TextSpan(text: 'Hello, my name '),
    WidgetSpan(
      child: Container(
        color: Colors.orange,
        child: GestureDetector(
          onTap: () {
            print('tap');
          },
          child: Container(
            child: Padding(
              padding: const EdgeInsets.all(4.0),
              child: Text(
                'is',
                style: TextStyle(fontSize: 25.0),
              ),
            ),
          ),
        ),
      ),
    ),
    TextSpan(text: ' Gabriele, and i am 21 years old!'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: RichText(
          text: TextSpan(
            style: TextStyle(fontSize: 25.0, color: Colors.black),
            children: myList,
          ),
        ),
      ),
    );
  }
}

this is my current output:

enter image description here

as you can see in the image, the word 'is' (highlighted in orange) is slightly shifted upwards.

How can I get it to be on the same level as other words?
(for example by aligning everything in the center regarding the horizontal axis..)

.

I hope you can help me.

Thank you :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱殇璃 2025-01-29 09:13:17

它可能是因为您使用填充

padding: const EdgeInsets.all(4.0)

然后设置

padding: const EdgeInsets.only(left: 4, right: 4, top: 4)

It probably occurs because you are using Padding and you set

padding: const EdgeInsets.all(4.0)

try this instead

padding: const EdgeInsets.only(left: 4, right: 4, top: 4)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文