简体   繁体   English

在 Flutter 中相邻放置 Widget

[英]Place Widgets adjacent to each other in Flutter

I have these two widgets:我有这两个小部件:

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(),

I want to place them beside each other in a row.我想把它们排成一排。 I know the row property of flutter but I don't know how to merge these two.我知道 flutter 的行属性,但我不知道如何合并这两个。

You should use the Row widget, what's the problem?您应该使用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 empty Container 's, for example:提示:flutter 团队建议使用 Widget Offstage而不是创建空的Container ,例如:

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,
        ),
     ),
),

If i understood your question, you want to put this two texts side by side, look at that:如果我理解您的问题,您想将这两个文本并排放置,请看:

Row(
  children: <Widget>[
     Text('Completed Purchases'),
     Text('Refunds'),
  ]
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM