如何在flutter中的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),),
          ),
        ),
      ),
    );
  }
}

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

最新更新