如何在Flutter的Inkwell小部件中的一行中添加多个按钮

时间:2019-02-17 16:18:56

标签: dart flutter

如何在一行中的顶部添加多个按钮,这些按钮应该位于inkwell小部件内。下面是inkwell小部件的代码

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Flutter Counter"),
      ),
      body:InkWell(
        onTap: () {
          setState(() { _increment();});
        },
        child:Container(
          decoration: new BoxDecoration(color: Colors.blueAccent),
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child:Center(
            child: Text('$counter',

              style: TextStyle(fontSize: 60.0,fontWeight: FontWeight.bold,color: Colors.white),),
          ),

        ),
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

InkWell的内容包装到Stack中,并将Row用于所需的按钮。如果我理解您的问题是正确的

Widget build(BuildContext context) {
  return Scaffold(
      appBar: new AppBar(
        elevation:
        Theme.of(context).platform == TargetPlatform.iOS
            ? 0.0
            : 4.0,
        title: new Text(
          "HelloFlutter",
        ),
      ),
      body: InkWell(
        onTap: () {
          setState(() { _increment();});
        },
        child: Stack(
          children: <Widget>[
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    FlatButton(onPressed: (){ setState(() {
                      counter = 1;
                    }); }, child: Text('Button1')),
                    FlatButton(onPressed: (){setState(() {
                      counter = 2;
                    }); }, child: Text('Button2')),
                    FlatButton(onPressed: (){setState(() {
                      counter = 3;
                    }); }, child: Text('Button3')),
                  ],
                )
              ],
            ),
            Center(
              child: Text('$counter',

                style: TextStyle(fontSize: 60.0,fontWeight: FontWeight.bold,color: Colors.red),),
            ),
          ],
        )
      ),
    );
}