我试图在行小部件中包装文本(多行),然后是"Read More“。
Lorem Ipsum只是印刷和排版行业的虚拟文本。自从1500年代以来,Lorem就一直是业界标准的虚拟文本,当时一台不知名的打印机拿出一台打字机,把它拼成一本样书。读了更多.
我尝试使用行小部件(阅读更多),它已经溢出到下一行。
只想显示可读的文本,后面跟着内容,而不溢出到下一行。单击“阅读更多”,我将显示底部模型表。
请帮忙..。
发布于 2022-09-02 06:53:38
您可以使用RichText而不是Row
RichText(
text: TextSpan(
style: TextStyle(color: Colors.black),
children: <TextSpan>[
TextSpan(
text:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
),
TextSpan(
text: 'Read more!',
style: TextStyle(fontWeight: FontWeight.bold),
recognizer: TapGestureRecognizer()
..onTap = () {
print('Read more click');
// what you wnat when click more
},
),
],
),
),

发布于 2022-09-02 06:38:42
为此,您可以使用雷德莫尔包。
ReadMoreText(
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
trimLines: 2,
colorClickableText: Colors.pink,
trimMode: TrimMode.Line,
trimCollapsedText: 'Show more',
trimExpandedText: 'Show less',
moreStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
);发布于 2022-09-02 06:50:19
要做到这一点,只需添加一个包readmore: ^2.1.0。
在.dart文件中导入import 'package:readmore/readmore.dart';
使用此代码可自动调整容器高度。
Container(
margin: const EdgeInsets.only(
top: 30,
left: 10,
right: 10,
bottom: 40.0,
),
color: Colors.transparent,
child: ReadMoreText(
'your_text',
trimLines: 4,
colorClickableText: Colors.pink,
trimMode: TrimMode.Line,
trimCollapsedText: 'Show more',
postDataTextStyle: TextStyle(
color: Colors.blue,
),
style: TextStyle(
fontFamily: 'Avenir',
color: Colors.black,
),
trimExpandedText: 'Show less',
lessStyle: TextStyle(
fontFamily: 'Avenir',
fontSize: 16.0,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
moreStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
width: MediaQuery.of(context).size.width,
),https://stackoverflow.com/questions/73578640
复制相似问题