如何在文字下方添加按钮

时间:2019-02-15 12:43:01

标签: dart flutter

我是个新手,所以这是我的代码,它在其中打印一个中心文本,但是我需要在文本下方添加一个按钮。

import 'package:flutter/material.dart';

void main() 
{
  runApp(MaterialApp(
     title: 'Hello Flutter',
     home: HomeWidget(),

  ));
}


class HomeWidget extends StatelessWidget 
{
    @override
    Widget build(BuildContext context) 
    {
      return Material(
         child: Container(child: Center(child: Text('Hello World Of Flutter Development'),),),       
         // Need Button Here beneath Text   
      );

      } //Widget
} //End of Class

2 个答案:

答案 0 :(得分:0)

使用-Column小部件。

详细了解drawing Layouts

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    title: 'Hello Flutter',
    home: HomeWidget(),
  ));
}

class HomeWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
        Center(
          child: Text('Hello World Of Flutter Development'),
        ),
        RaisedButton(onPressed: (){},child: Text('Button'),) // Button under Text
      ]),

    );
  } //Widget
}

答案 1 :(得分:0)

使用列小部件

 Column(
      children: [
        Text('Hello World Of Flutter Development'),
FlatButton(onPressed:() {}, child:Text('name on button')),           
     ],
    )