如何在一行中的顶部添加多个按钮,这些按钮应该位于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),),
),
),
),
);
}
}
答案 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),),
),
],
)
),
);
}