gpt4 book ai didi

flutter - 在flutter中为一个按钮执行两个函数

转载 作者:IT王子 更新时间:2023-10-29 06:36:52 26 4
gpt4 key购买 nike

所以我希望能够将用户键入的文本 Controller 中的文本保存到共享首选项中但是,我也想同时转到下一页。

所以:

  1. 将文本保存在共享首选项中
  2. 转到下一页

    final _text = TextEditingController();

    _nameSaver() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString('my_string_key', _text.text);
    }

    FooterRaisedButton(
    "Next",
    () => (_text.text.isEmpty)
    ? null
    : Navigator.pushNamed(context, '/onboardMarket'),
    "#0087a8")

我不知道如何调出保存名字的函数同时按下按钮会转到下一页

最佳答案

去除粗箭头(=>),并像这样实现:

FooterRaisedButton(
"Next",
() async {
if (_text.text.isEmpty)
return; // return if it is empty
await nameSaver(); // else save it here
Navigator.pushNamed(context, '/onboardMarket'); // once done, navigate
}
);

只是给你一个基本的想法,

// only one statement can be executed using fat notation
RaisedButton(onPressed: () => _calculate(1));

// here you can perform as many as you need.
RaisedButton(onPressed: () {
_calculate(1);
_printScreen();
});

关于flutter - 在flutter中为一个按钮执行两个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56372554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com