扑来 - 不要用文字和容器包裹
我有此代码:
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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能是因为您使用
填充
,然后设置
It probably occurs because you are using
Padding
and you settry this instead