[英]Flutter Wrap is not working with large text
I need some help to create a serie of sequential widgets, one after one, when the first ends, it comes the other directly.我需要一些帮助来创建一系列连续的小部件,一个接一个,当第一个结束时,另一个直接出现。
I tried to use Wrap, but the Text is long and it takes more than the full width, so the other widget goes under the Text, not after it, even that there is space after the Text
我尝试使用 Wrap,但 Text 很长,并且占用的宽度超过了整个宽度,因此其他小部件位于 Text 下方,而不是在它之后,即使 Text 之后有空格
import 'package:flutter/material.dart';
class Testee extends StatefulWidget {
@override
_TesteeState createState() => _TesteeState();
}
class _TesteeState extends State<Testee> {
String loremOne =
"Nostrud cillum ea do sit eu sint reprehenderit est tempor amet. Ex minim cupidatat exercitation officia mollit occaecat dolor sint sit aliqua dolore velit exercitation duis. Eu cupidatat pariatur aliquip aliquip ipsum sint ad ullamco irure eiusmod velit mollit ut elit.";
String loremTwo = "Fugiat aute eu tempor et consequat nulla.";
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.amberAccent,
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(15.0),
child: ListView(
children: [
Wrap(
direction: Axis.horizontal,
spacing: 10.0,
children: [
Text(loremOne),
Icon(Icons.circle, size: 16),
Text(loremOne),
Icon(Icons.circle, size: 16),
Text(loremTwo),
],
),
],
),
),
),
);
}
}
Actually, Wrap
is not to use to separate text, but Wrap
used to separate widgets.其实
Wrap
不是用来分隔文本的,而是Wrap
是用来分隔小部件的。
As @pskink said in the comment.正如@pskink 在评论中所说。 You need
RichText
to create your widget like your shown image.您需要
RichText
来创建您的小部件,就像您显示的图像一样。
I make a comparison beetween Wrap
and RichText
.我在
Wrap
和RichText
之间进行了比较。 May you can try this code你可以试试这个代码
import 'package:flutter/material.dart';
class Testee extends StatefulWidget {
@override
_TesteeState createState() => _TesteeState();
}
class _TesteeState extends State<Testee> {
String loremOne =
"Nostrud cillum ea do sit eu sint reprehenderit est tempor amet. Ex minim cupidatat exercitation officia mollit occaecat dolor sint sit aliqua dolore velit exercitation duis. Eu cupidatat pariatur aliquip aliquip ipsum sint ad ullamco irure eiusmod velit mollit ut elit.";
String loremTwo = "Fugiat aute eu tempor et consequat nulla.";
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.amberAccent,
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(15.0),
child: ListView(
children: [
Wrap(
direction: Axis.horizontal,
spacing: 10.0,
children: [
Text(loremOne),
Icon(Icons.circle, size: 16),
Text(loremOne),
Icon(Icons.circle, size: 16),
Text(loremTwo),
],
),
//may you can compare your wrap with Richtext below
RichText(
text: TextSpan(children: [
TextSpan(text: loremOne),
WidgetSpan(child: Icon(Icons.circle, size: 16)),
TextSpan(text: loremOne),
WidgetSpan(child: Icon(Icons.circle, size: 16)),
TextSpan(text: loremTwo),
]))
],
),
),
),
);
}
}
I recommend that you use the AutoSizeText package
, it is very useful!我推荐你使用AutoSizeText
package
,它非常有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.