当前位置: 首页 > article >正文

flutter开发实战-readmore长文本展开和收缩控件

flutter开发实战-readmore长文本展开和收缩控件

当长文本展开和收缩控件,我们需要使用readmore来处理长文本展开和收缩,方便阅读

在这里插入图片描述

一、引入readmore

在工程的pubspec.yaml中引入插件

  readmore: ^2.1.0
    

ReadMoreText的属性如下

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长文本展开和收缩控件

学习记录,每天不停进步。


http://www.kler.cn/news/156392.html

相关文章:

  • C++学习 --函数对象
  • 线上超市小程序可以做什么活动_提升用户参与度与购物体验
  • 活动回顾|德州仪器嵌入式技术创新发展研讨会(上海站)成功举办,信驰达科技携手TI推动技术创新
  • 学习-java多线程面试题
  • 在 Linux 上修改 Oracle 控制文件、日志文件和数据文件的目录的脚本
  • Rust UI开发(五):iced中如何进行页面布局(pick_list的使用)?(串口调试助手)
  • (一)舒尔特表练习记
  • 新手村之SQL——函数多表联结
  • rman SBT_TAPE NFS disk 模拟NBU带库 FRA
  • Android跨进程通信,binder,native层,服务端在servicemanager注册服务
  • 【FAQ】运动健康服务端侧数据常见问题及解答
  • Android 透明度颜色值对照表
  • Apache Flink(六):Apache Flink快速入门 - Flink案例实现
  • SpringBoot框架结合Redis实现分布式锁
  • Mover Creator 用户界面
  • 【设计模式】职责链模式设计在线文档帮助系统
  • 销售员怎样才能做到让客户主动来找?
  • (C++)和为s的两个数字--双指针算法
  • CDA level-2 备考经验分享 转数据分析师CDA证书备考 考试相关说明
  • ZYNQ_project:HDMI
  • ubantu配置网卡ip
  • 数据库管理-第122期 配置Halo数据库(202301204)
  • 前后端数据传输格式(下)
  • 日志检索场景ES->Doris迁移最佳实践:函数篇
  • Python+OpenCV实现最强自动扫雷
  • 算法基础--双指针
  • 深度学习——第3章 Python程序设计语言(3.2 Python程序流程控制)
  • PAD平板签约投屏-高端活动的选择
  • C++基础介绍及关键字
  • PHPExcel 导出Excel报错:PHPExcel_IOFactory::load()