我对Flutter 翼是个新手.当我使用TextSpan
小工具时,如何限制文本?
我的代码
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Row(
children: <Widget>[
Stack(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(8)),
child: Image.asset(
lastPlayedGame.imagePath,
height: 60,
width: 45,
fit: BoxFit.cover,
),
),
Positioned(
left: 8,
right: 8,
top: 0,
bottom: 0,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Icon(
Icons.play_arrow,
color: Colors.red,
),
),
),
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: RichText(
text: TextSpan(children: [
TextSpan(text: lastPlayedGame.name, style: headingTwoTextStyle,),
TextSpan(text: '\n'),
TextSpan(text: "${lastPlayedGame.hoursPlayed} hours played", style: bodyTextStyle),
]),
),
)
],
),
),
Expanded(
child: GameProgressWidget(screenWidth: screenWidth, gameProgress: gameProgress),
),
],
),
);
}
}
在我的Android设备上运行时,我会遇到一个错误:
一个RenderFlex在右侧溢出了15个像素.
如何限制文本长度?也许会判断文本是否是屏幕的最大值,是否会显示Assasin's Creed...
(可能会带点?)