Home > database >  How to show text in in the body of flutter?
How to show text in in the body of flutter?

Time:11-28

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

CodePudding user response:

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.

CodePudding user response:

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.

CodePudding user response:

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(),
              ),
            ),
          )
        ],
      ),   
    );
  }
}

CodePudding user response:

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

  • Related