gpt4 book ai didi

flutter - 按下后退按钮时,将indexStack设置为0

转载 作者:行者123 更新时间:2023-12-03 04:18:17 25 4
gpt4 key购买 nike

我有一个 IndexStack 作为主要的导航方式,但是当用户点击“后退”按钮时,“导航”会返回到先前的支架。
目前我正在使用WillPopScope(),但是我一直收到一条错误消息,说...

type '() => void' is not a subtype of type '() => Future'


这是代码。
导航页
class NavPages extends StatefulWidget {
@override
_NavPagesState createState() => _NavPagesState();
}

List<Widget> screens = new List();
List<String> site = new List();

class _NavPagesState extends State<NavPages> {
int _selectedIndex = 0;

@override
Widget build(BuildContext context) {
site.add('..............');
return Consumer<User>(
builder: (context, value, child) {
screens.add(GotKeysSites(
user: value,
departmentClicked: (title) {
if (title.isNotEmpty) {
var pos = site.indexWhere((element) => element == title);
setState(() {
_selectedIndex = pos; //Here the index is updated however, i receive the error commented above.
});
}
},
departmentCallback: (title, departmentsAssigned, startTime, endTime) {
if (title.isNotEmpty && departmentsAssigned.isNotEmpty) {
site.add(title);
}
},
));
return Scaffold(
body: IndexedStack(
index: _selectedIndex,
children: screens,
),
);
},
);
}
}

typedef void ReturnIndex();
以及我称之为 ReturnIndex函数的类
return WillPopScope(
onWillPop: widget.returnIndex,
child: Scaffold(
));

最佳答案

OnWillPop范围希望您为其提供适当的功能,因此请尝试执行以下2个更改中的任何一项
更改1

return WillPopScope(
onWillPop:(){
widget.returnIndex;
},
child: Scaffold(
));
要么
更改2
void returnIndex(){//Future<void> if it is a future object
}

关于flutter - 按下后退按钮时,将indexStack设置为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64159917/

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