flutter 文字过长超出范围,Flutter-溢出时自动换行,例如插入省略号或淡入淡出...

在Flutter中,当文本内容过长时,通过设置TextOverflow.ellipsis可以实现省略号显示,但需要确保文本容器能够适应宽度变化。问题在于原始代码中的Text组件没有足够的空间来收缩。解决方法是将Text组件包裹在Flexible或者Expanded组件中,允许其根据需要缩小宽度。
部署运行你感兴趣的模型镜像

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: [

new Card(

child: new Container(

padding: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 18.0),

child: new Row(

children: [

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: [

new Row(

children: [

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: [

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:

HKiLt.png

expected:

rGk9W.png

解决方案

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.

o2nyO.png

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,

),

),

),

),

您可能感兴趣的与本文相关的镜像

ComfyUI

ComfyUI

AI应用
ComfyUI

ComfyUI是一款易于上手的工作流设计工具,具有以下特点:基于工作流节点设计,可视化工作流搭建,快速切换工作流,对显存占用小,速度快,支持多种插件,如ADetailer、Controlnet和AnimateDIFF等

执行 `./flutter-sdk/bin/flutter --version` 提示不是内部外部命令,可能是 Flutter 环境变量配置不正确导致系统无法找到 `flutter` 命令。可以按照以下步骤解决: ### 确认 Flutter SDK 已正确下载和解压 需确保已下载 Flutter SDK 并解压到指定路径。可以从官方链接(https://docs.flutter.dev/get-started/install/macos )下载,国内也可使用码云下载(https://gitee.com/mirrors/Flutter?_from=gitee_search ),解压的是 Stable version 2.5.3 版本,并将其放入相应路径,例如 home 目录下 [^1]。 ### 配置 Flutter 环境变量 开始配置环境变量,以 macOS 系统为例,可通过以下步骤操作: 1. 打开终端,输入 `vim ~/.bash_profile` 编辑环境变量文件。 2. 在文件中输入以下内容: ```bash export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn export PATH=/path/to/flutter/bin:$PATH export NO_PROXY=localhost,127.0.0.1 ``` 注意将 `/path/to/flutter` 替换为实际的 Flutter SDK 解压路径。例如,如果将 Flutter SDK 解压到 home 目录下,路径可能是 `/Users/your_username/flutter` [^1]。 3. 输入 `:wq` 保存并退出文件。 4. 在终端输入命令 `source ~/.bash_profile` 载入配置。 5. 输入 `echo $PATH` 检查配置是否生效,确保 Flutter SDK 的 `bin` 目录已添加到 `PATH` 中 [^1]。 ### 验证配置 在终端运行 `flutter --version` 命令,若能正确显示版本号,说明配置成功;运行 `flutter doctor` 命令可检查依赖状态 [^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值