flutter开发实战–readmore长文本展开和收缩控件
当长文本展开和收缩控件,我们需要使用readmore来处理长文本展开和收缩,方便阅读
一、引入readmore
readmore: ^2.1.0
const ReadMoreText(
this.data, {
Key? key,
this.preDataText,
this.postDataText,
this.preDataTextStyle,
this.postDataTextStyle,
this.trimExpandedText = 'show less',
this.trimCollapsedText = 'read more',
this.colorClickableText,
this.trimLength = 240,
this.trimLines = 2,
this.trimMode = TrimMode.Length,
this.style,
this.textAlign,
this.textDirection,
this.locale,
this.textScaleFactor,
this.semanticsLabel,
this.moreStyle,
this.lessStyle,
this.delimiter = _kEllipsis + ' ',
this.delimiterStyle,
this.callback,
}) : super(key: key);
二、使用ReadMoreText
ReadMoreText(
'Flutter is Google’s mobile UI open source framework to build high-quality native (super fast) interfaces for iOS and Android apps with the unified codebase.',
trimLines: 2,
colorClickableText: Colors.pink,
trimMode: TrimMode.Line,
trimCollapsedText: 'Show more',
trimExpandedText: 'Show less',
moreStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
import 'package:flutter/material.dart';
import 'package:readmore/readmore.dart';
class ReadMorePage extends StatefulWidget {
const ReadMorePage({super.key});
@override
State<ReadMorePage> createState() => _ReadMorePageState();
}
class _ReadMorePageState extends State<ReadMorePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('HeroPage'),
),
body: Center(
child: ReadMoreText(
'Flutter is Google’s mobile UI open source framework to build high-quality native (super fast) interfaces for iOS and Android apps with the unified codebase.',
trimLines: 2,
colorClickableText: Colors.pink,
trimMode: TrimMode.Line,
trimCollapsedText: 'Show more',
trimExpandedText: 'Show less',
moreStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
),
);
}
}
三、小结
flutter开发实战-readmore长文本展开和收缩控件
原文地址:https://blog.csdn.net/gloryFlow/article/details/134715606
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_20352.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。