Flutter 如何在末尾显示更多的文本来代替TextOverflow.省略号infletter?

Flutter 如何在末尾显示更多的文本来代替TextOverflow.省略号infletter?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我想在文本上实现showMore一种文本来代替省略号或淡入淡出。就像我们可以在React中使用这个库一样 这是一个简单的长文本 Container( color: Colors.white, child: Text( "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text e

我想在文本上实现
showMore
一种文本来代替
省略号或淡入淡出。就像我们可以在
React
中使用这个库一样

这是一个简单的长文本

Container(
  color: Colors.white,
  child: 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. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
    overflow: TextOverflow.ellipsis,
  ),
)

现在,如果我的文本在设备上溢出,我想在末尾显示一个文本
showMore
,它通常显示覆盖容器中的其余内容。

您可以这样做,代码完全正常工作:

import 'package:flutter/material.dart';

final Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatefulWidget {
  @override
  State<MyWidget> createState() => MyWidgetState();
}

class MyWidgetState extends State<MyWidget> {
  bool more = false;
  String 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. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.black,
      child: Column(children: <Widget>[
        more
            ? Text(text)
            : Text(
                text,
                overflow: TextOverflow.ellipsis,
              ),
        FlatButton(
          child: more ? Text("less") : Text("more"),
          onPressed: () => setState(() => more = !more),
        ),
      ]),
    );
  }
}
导入“包装:颤振/材料.省道”;
最终颜色深蓝色=颜色。来自argb(255,18,32,47);
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主题:ThemeData.dark().copyWith(脚手架背景颜色:深蓝色),
debugShowCheckedModeBanner:false,
家:脚手架(
正文:中(
子项:MyWidget(),
),
),
);
}
}
类MyWidget扩展了StatefulWidget{
@凌驾
State createState()=>MyWidgetState();
}
类MyWidgetState扩展了状态{
布尔莫尔=假;
字符串文本=
“Lorem Ipsum仅仅是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是该行业的标准虚拟文本,当时一家不知名的印刷商拿着一个打印厨房,抢着制作一本打印样本书。它不仅存活了五个世纪,而且还跨越到了电子排版,仍然是一本经典之作基本上没有变化。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset表单的发布而流行,最近又随着包括Lorem Ipsum版本在内的Aldus PageMaker等桌面出版软件的发布而流行。”;
@凌驾
小部件构建(构建上下文){
返回容器(
颜色:颜色,黑色,
子项:列(子项:[
更多
?文本(文本)
:文本(
文本
溢出:TextOverflow.省略号,
),
扁平按钮(
孩子:更多?文本(“更少”):文本(“更多”),
按下时:()=>setState(()=>more=!more),
),
]),
);
}
}
请检查插件。 您需要传递要显示文本弹出窗口的小部件的
GlobalKey

showmoretextpoppopup=showmoretextpoppopup(上下文、,
文本:文本,
textStyle:textStyle(颜色:Colors.black),
身高:200,
宽度:100,
背景颜色:颜色(0xFF16CCCC));
弹出显示(
widgetKey:key,

我希望这是可以理解的,如果有的话,请发表评论。这回答了你的问题吗?不是真的,我想在一个覆盖容器中显示其余的文本,就像我们通常在网站中看到的那样。我不知道会溢出的文本的长度。您好,为什么需要文本的长度?谢谢,这就是我想要的R