ali262883
ali262883

Reputation: 359

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.

Upvotes: 1

Views: 1006

Answers (2)

Alexandru
Alexandru

Reputation: 143

You should use the Row widget, what's the problem?

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:

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

Upvotes: 2

Bruno Lippert
Bruno Lippert

Reputation: 121

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

Upvotes: 3

Related Questions