如何在Flutter中处理此文本小部件?
我有一个返回AlertDialog的函数。下面是它的屏幕截图:。下面是它的代码:如何在Flutter中处理此文本小部件?,flutter,text,widget,Flutter,Text,Widget,我有一个返回AlertDialog的函数。下面是它的屏幕截图:。下面是它的代码: void _showDialog(BuildContext context, List details) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( titlePadding: const EdgeInsets.all(5),
void _showDialog(BuildContext context, List details) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: const EdgeInsets.all(5),
contentPadding: const EdgeInsets.only(left: 10, right: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))
),
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
details[3].toString(),
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 40)
),
]
),
content: Container(
color: Colors.green,
width: double.infinity,
height: 150,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(
'Data: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
Text(
details[0],
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20)
),
],
),
Row(
children: <Widget>[
Text(
'Tipologia: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
Text(
details[2].toLowerCase(),
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20)
),
],
),
details[5] != ''
? Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'Descrizione: ',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
),
],
),
Container(
//width: 100,
child: Text(
details[5],
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20),
overflow: TextOverflow.ellipsis,
maxLines: 5,
textAlign: TextAlign.justify,
),
)
],
)
: Offstage(
child: Text('invisible')
),
Row(
children: <Widget>[
details[4] == 'SI'
? Text(
'Il voto fa media.',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
)
: Text(
'Il voto non fa media.',
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)
)
],
),
],
),
),
actions: <Widget>[
FlatButton(
child: Text(
"Chiudi",
style: test.GoogleFonts.quicksand(color: Colors.black, fontSize: 15)
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
void\u显示对话框(构建上下文上下文,列表详细信息){
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
返回警报对话框(
标题添加:常量边集全部(5),
contentPadding:仅限常量边集(左:10,右:10),
形状:圆形矩形边框(
边界半径:边界半径。全部(半径。圆形(10))
),
标题:世界其他地区(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
正文(
详细信息[3]。toString(),
样式:test.GoogleFonts.quicksand(颜色:Colors.black,字体大小:40)
),
]
),
内容:容器(
颜色:颜色。绿色,
宽度:double.infinity,
身高:150,
子:列(
儿童:[
划船(
儿童:[
正文(
“数据:”,
样式:test.GoogleFonts.quicksand(颜色:Colors.black,fontSize:20,fontWeight:fontWeight.bold)
),
正文(
详情[0],
样式:test.GoogleFonts.quicksand(颜色:Colors.black,字体大小:20)
),
],
),
划船(
儿童:[
正文(
"提波罗吉亚",,
样式:test.GoogleFonts.quicksand(颜色:Colors.black,fontSize:20,fontWeight:fontWeight.bold)
),
正文(
详细信息[2]。toLowerCase(),
样式:test.GoogleFonts.quicksand(颜色:Colors.black,字体大小:20)
),
],
),
详细信息[5]!=''
?立柱(
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
正文(
“描述:”,
样式:test.GoogleFonts.quicksand(颜色:Colors.black,fontSize:20,fontWeight:fontWeight.bold)
),
],
),
容器(
//宽度:100,
子:文本(
详情[5],
样式:test.GoogleFonts.quicksand(颜色:Colors.black,字体大小:20),
溢出:TextOverflow.省略号,
最大行数:5,
textAlign:textAlign.justify,
),
)
],
)
:台下(
子项:文本(“不可见”)
),
划船(
儿童:[
详细信息[4]=“SI”
?文本(
“媒体之音”,
样式:test.GoogleFonts.quicksand(颜色:Colors.black,fontSize:20,fontWeight:fontWeight.bold)
)
:文本(
“非足总媒体之音”,
样式:test.GoogleFonts.quicksand(颜色:Colors.black,fontSize:20,fontWeight:fontWeight.bold)
)
],
),
],
),
),
行动:[
扁平按钮(
子:文本(
“丘迪”,
样式:test.GoogleFonts.quicksand(颜色:Colors.black,字体大小:15)
),
已按下:(){
Navigator.of(context.pop();
},
),
],
);
},
);
}
包含“Data”和“Tipologia”的行没有问题。但是在“descripione”之后有一个文本小部件,它包含一个可变长度的字符串。我希望所说的文本显示在多行上,从“descripione:”之后开始(就像“pratico”从“Tipologia:”之后开始)。我该怎么做?
编辑:下面是它现在的样子我建议您使用
RichText()
而不是Row()
使用文本
就像下面的一样
RichText(
textAlign:textAlign.left,
text:TextSpan(
儿童:[
TextSpan(儿童:[
TextSpan(
文本:“描述:”,
样式:test.GoogleFonts.quicksand(颜色:Colors.black,fontSize:20,fontWeight:fontWeight.bold),
TextSpan(
正文:详情[5],
样式:test.GoogleFonts.quicksand(颜色:Colors.black,字体大小:20),
),
]),
],
),
所以你的代码应该是
void\u显示对话框(构建上下文上下文,列表详细信息){
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
返回警报对话框(
标题添加:常量边集全部(5),
contentPadding:仅限常量边集(左:10,右:10),
形状:圆形矩形边框(
边界半径:边界半径。全部(半径。圆形(10))
),
标题:世界其他地区(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
正文(
详细信息[3]。toString(),
样式:test.GoogleFonts.quicksand(颜色:Colors.black,字体大小:40)
),
]
),
内容:容器(
颜色:颜色。绿色,
宽度:double.infinity,
身高:150,
子:列(
儿童:[
划船(
儿童:[
正文(
“数据:”,
样式:test.GoogleFonts.quicksand(颜色:Colors.blac)
details[5] != ''
? Container(
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment
.start, // This will change how the multi-line text is aligned
children: <Widget>[
Text(
'Descrizione: ',
style: test.GoogleFonts.quicksand(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold),
),
Flexible(
child: Text(
details[5],
style: test.GoogleFonts.quicksand(
color: Colors.black, fontSize: 20),
overflow: TextOverflow.ellipsis,
maxLines: 5,
textAlign: TextAlign.justify,
),
),
],
),
)
: Offstage(child: Text('invisible')),