Flutter Back button with return data

后端 未结 11 1020
长情又很酷
长情又很酷 2020-12-01 15:46

I have an interface with two buttons that pop and return true or false, like so:

onPressed: () => Navigator.pop(context, false)

I need t

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 16:25

    While you can override the back button for custom behaviors, don't.

    Instead of overriding the button with a custom pop, you should handle the null scenario. There are a few reasons why you don't want to manually override the icon:

    • The icon change on IOS and Android. On IOS it uses arrow_back_ios while android uses arrow_back
    • The icon may automatically disappear if there's no route to go back
    • Physical back button will still return null.

    Instead should do the following:

    var result = await Navigator.pushNamed(context, "/");
    if (result == null) {
      result = false;
    }
    

提交回复
热议问题