简体   繁体   English

Flutter 带有两个两个文本小部件的行小部件没有相互跟随

[英]Flutter Row widget with two two text widget is not following one another

I am trying to wrap text (multi line) followed by "Read More" in a Row widget.我正在尝试在 Row 小部件中包装文本(多行),然后是“阅读更多”。

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum 只是印刷和排版行业的虚拟文本。 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.自 1500 年代以来,Lorem Ipsum 一直是行业的标准虚拟文本,当时一位不知名的印刷商采用了一种类型的厨房并将其加扰以制作一本类型样本书。 Read More...阅读更多...

I tried using row widget (Read More) it's overflowing to next line.我尝试使用行小部件(阅读更多)它溢出到下一行。

Just want to show the readmore text followed by the content without overflowing to next line.只想显示 readmore 文本后跟内容而不溢出到下一行。 on clicking read more i am showing bottommodelsheet.点击阅读更多我正在显示底部模型表。

Please help..请帮忙..

You can use readmore package for this.您可以为此使用阅读更多package

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),
);

To do this simply add a package readmore: ^2.1.0 .为此,只需添加 package 阅读全文readmore: ^2.1.0

In your.dart file import import 'package:readmore/readmore.dart';在你的.dart 文件中导入import 'package:readmore/readmore.dart';

Use this code to adjust automatically height of container使用此代码自动调整容器的高度

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,
                      ),

You can use RichText instead of Row :您可以使用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
                        },
                    ),
                  ],
                ),
              ),

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM