Flutter - 在溢出时换行文本,如插入省略号或淡入淡出 [英] Flutter - Wrap text on overflow, like insert ellipsis or fade

查看:65
本文介绍了Flutter - 在溢出时换行文本,如插入省略号或淡入淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一行,其中中心文本具有最大大小,如果文本内容太大,则适合大小.

我插入了 TextOverflow.ellipsis 属性来缩短文本并插入三点 ... 但它不起作用.

ma​​in.dart

import 'package:flutter/material.dart';无效主(){运行应用程序(新的我的应用程序());}class MyApp 扩展 StatelessWidget {@覆盖小部件构建(BuildContext 上下文){返回新的 MaterialApp(主页:新主页(),);}}class HomePage 扩展了 StatelessWidget {@覆盖小部件构建(BuildContext 上下文)=>新脚手架(应用栏:新的应用栏(背景颜色:新颜色(0xFF26C6DA),),正文:新的列表视图(孩子们:<小部件>[新卡(孩子:新容器(填充:新的 EdgeInsets.symmetric(水平:16.0,垂直:18.0),孩子:新行(孩子们:<小部件>[新容器(填充:新的 EdgeInsets.only(右:24.0),孩子:新的圆形头像(背景颜色:新颜色(0xFFF5F5F5),半径:16.0,)),新容器(填充:新的 EdgeInsets.only(右:13.0),孩子:新文本('文本拉...',溢出:TextOverflow.ellipsis,样式:新文本样式(字体大小:13.0,fontFamily: 'Roboto',颜色:新颜色(0xFF212121),fontWeight: FontWeight.bold,),),),新容器(孩子:新列(crossAxisAlignment: CrossAxisAlignment.end,孩子们:<小部件>[新行(孩子们:<小部件>[新文本('账单  ',样式:新文本样式(字体大小:12.0,fontFamily: 'Roboto',颜色:新颜色(0xFF9E9E9E)),),新文本('$ -999.999.999,95',样式:新文本样式(字体大小:14.0,fontFamily: 'Roboto',颜色:新颜色(0xFF212121)),),],),新行(孩子们:<小部件>[新文本('限制  ',样式:新文本样式(字体大小:12.0,fontFamily: 'Roboto',颜色:新颜色(0xFF9E9E9E)),),新文本('R$ 900.000.000,95',样式:新文本样式(字体大小:14.0,fontFamily: 'Roboto',颜色:新颜色(0xFF9E9E9E)),),],),]))],),)),]));}

结果:

预期:

解决方案

您应该将 Container 包装在

灵活(孩子:新容器(填充:新的 EdgeInsets.only(右:13.0),孩子:新文本('文本大eeeeeeeeeeeeeeeeeeeeee',溢出:TextOverflow.ellipsis,样式:新文本样式(字体大小:13.0,fontFamily: 'Roboto',颜色:新颜色(0xFF212121),fontWeight: FontWeight.bold,),),),),

I'm trying to create a line in which center text has a maximum size, and if the text content is too large, it fits in size.

I insert the TextOverflow.ellipsis property to shorten the text and inserting the triple points ... but it is not working.

main.dart

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) => new Scaffold(
    appBar: new AppBar(
      backgroundColor: new Color(0xFF26C6DA),
    ),
    body: new ListView  (
      children: <Widget>[
        new Card(
          child: new Container(
            padding: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 18.0),
            child: new Row(
              children: <Widget>[
                new Container(
                  padding: new EdgeInsets.only(right: 24.0),
                  child: new CircleAvatar(
                    backgroundColor: new Color(0xFFF5F5F5),
                    radius: 16.0,
                  )
                ),
                new Container(
                  padding: new EdgeInsets.only(right: 13.0),
                  child: new Text(
                    'Text lar...',
                    overflow: TextOverflow.ellipsis,
                    style: new TextStyle(
                      fontSize: 13.0,
                      fontFamily: 'Roboto',
                      color: new Color(0xFF212121),
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                new Container(
                  child: new Column(
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: <Widget>[
                      new Row(
                        children: <Widget>[
                          new Text(
                            'Bill  ',
                            style: new TextStyle(
                              fontSize: 12.0,
                              fontFamily: 'Roboto',
                              color: new Color(0xFF9E9E9E)
                            ),
                          ),
                          new Text(
                            '$ -999.999.999,95',
                            style: new TextStyle(
                              fontSize: 14.0,
                              fontFamily: 'Roboto',
                              color: new Color(0xFF212121)
                            ),
                          ),
                        ],
                      ),
                      new Row(
                        children: <Widget>[
                          new Text(
                            'Limit  ',
                            style: new TextStyle(
                              fontSize: 12.0,
                              fontFamily: 'Roboto',
                              color: new Color(0xFF9E9E9E)
                            ),
                          ),
                          new Text(
                            'R$ 900.000.000,95',
                            style: new TextStyle(
                              fontSize: 14.0,
                              fontFamily: 'Roboto',
                              color: new Color(0xFF9E9E9E)
                            ),
                          ),
                        ],
                      ),
                    ]
                  )
                )
              ],
            ),
          )
        ),
      ]
    )
  );
}

result:

expected:

解决方案

You should wrap your Container in a Flexible to let your Row know that it's ok for the Container to be narrower than its intrinsic width. Expanded will also work.

Flexible(
  child: new Container(
    padding: new EdgeInsets.only(right: 13.0),
    child: new Text(
      'Text largeeeeeeeeeeeeeeeeeeeeeee',
      overflow: TextOverflow.ellipsis,
      style: new TextStyle(
        fontSize: 13.0,
        fontFamily: 'Roboto',
        color: new Color(0xFF212121),
        fontWeight: FontWeight.bold,
      ),
    ),
  ),
),

这篇关于Flutter - 在溢出时换行文本,如插入省略号或淡入淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆