美文网首页
flutter 使用IconButton引用本地图片做点击事件

flutter 使用IconButton引用本地图片做点击事件

作者: kot_flu | 来源:发表于2019-03-21 11:59 被阅读0次

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,
      ),
样式.jpg

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

效果样式


样式2.jpg

上面可以修改

offstage: false,

返回按钮就隐藏了


样式3.jpg

相关文章

网友评论

      本文标题:flutter 使用IconButton引用本地图片做点击事件

      本文链接:https://www.haomeiwen.com/subject/tmlqvqtx.html