masfiq reza
masfiq reza

Reputation: 107

How to show text in in the body of flutter?

I wanted to show text from a string variable before the Wrap widget. But when I wanted to add something like Text before Wrap widget it is giving me error. How can show some text before the Wrap widget.

 @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("Second Route"),
           ),
        body: Center( 
          child:
            Wrap(
              children: _buildButtonsWithNames(),
            ),
          )
      );
    }

Upvotes: 0

Views: 2307

Answers (4)

Kings Samuel
Kings Samuel

Reputation: 185

Just use the column widget and pass the text and wrap widgets as children of the column

Upvotes: 0

masfiq reza
masfiq reza

Reputation: 107

Just found a way right now!!! from another answer.

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Second Route"),
      ),
      body: Column(
        children: <Widget>[
          Text("He"),
          Expanded(
            child: Center(
              child: Wrap(
                children: _buildButtonsWithNames(),
              ),
            ),
          )
        ],
      ),   
    );
  }
}

Upvotes: 0

Ali Yar Khan
Ali Yar Khan

Reputation: 1354

You can give column as a child to the center widget like this:

body: Center(
   child: Column(
       children: [
           Text("Your Text"),
           Wrap(
             children: _buildButtonsWithNames(),
           ),
       ],
   ),
),

Hope it answers the question.

Upvotes: 2

esentis
esentis

Reputation: 4726

If you want the text to be on top of the Wrap, add your Wrap to a Column and before of it add your Text widget.

If you want the text to be just before the Wrap, add your Wrap to a Row widget and do the same as for Column.

Upvotes: 1

Related Questions