我有以下两个小部件:
Text('Completed Purchases'),
widget.user.profile.designation != ''
? SizedBox(
// width: widget.screenSize.size.width * 0.45,
child: Text(
widget.user.profile.designation,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.ptSansNarrow(
color: Colors.grey,
fontSize: kTextHeading2FontSize,
fontWeight: FontWeight.w700,
),
),
)
: Container(),
Text('Refunds'),
widget.user.profile.designation != ''
? SizedBox(
// width: widget.screenSize.size.width * 0.45,
child: Text(
widget.user.profile.designation,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.ptSansNarrow(
color: Colors.grey,
fontSize: kTextHeading2FontSize,
fontWeight: FontWeight.w700,
),
),
)
: Container(),
我想将它们排成一排。我知道flutter的row属性,但是我不知道如何合并这两个。
最佳答案
您应该使用Row
小部件,这是什么问题?
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("Completed Purchases"),
Text("Refunds")
]
),
TIP: The flutter team recommends to use the Widget
Offstage
instead of creating emptyContainer
's, for example:
Offstage(
offstage: widget.user.profile.designation == '',
child: Text(
widget.user.profile.designation,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.ptSansNarrow(
color: Colors.grey,
fontSize: kTextHeading2FontSize,
fontWeight: FontWeight.w700,
),
),
),
关于flutter - 在Flutter中将小部件彼此相邻放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63394886/