flutter 使用IconButton引用本地图片做点击事件
2019-03-21 本文已影响0人
kot_flu
appBar 总是需要去改动和添加按钮去做点击事件
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
centerTitle: true,
title: new Text("SHOWS"),
actions: <Widget>[
new IconButton(
icon: ImageIcon(AssetImage("image/search.png")),
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => new Search()),
);
})
],
backgroundColor: Colors.black,
),

appBar 添加按钮的时候,使用action去做处理
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
appBar: new AppBar(
centerTitle: true,
backgroundColor: Colors.black,
title: Text("标题"),
leading: Offstage(
offstage: true,
child: new IconButton(
tooltip: 'Previous choice',
icon: const Icon(Icons.arrow_back),
onPressed: () {},
)),
actions: <Widget>[
new IconButton(
icon: const Icon(Icons.arrow_forward),
tooltip: 'Next choice',
onPressed: () {},
),
new Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Cancel",
),
),
)
],
));
效果样式

上面可以修改
offstage: false,
返回按钮就隐藏了
