如何在 Riverpod 中使用谷歌导航栏?

问题描述

我在我的应用中使用 flutter-riverpod 进行状态管理。由于使用 Riverpod,我必须将 Stateful widget 更改为 consumer widget,因此无法访问 setState()。现在,使用 Riverpod 为底部栏编写状态管理代码后,它不起作用。

这是我的代码-


int index = 0;

class HomePage extends ConsumerWidget {
  final currentIndex = Provider<int>((ref) => index);

  Widget build(BuildContext context,ScopedReader watch) {
    int _currentIndex = watch(currentIndex);

    

    return auth.when(//authstatchange provider
      data: (e) {
        if (e!=null&&e.uid != null) {
          return Scaffold(
            body: PageView(
              physics: NeverScrollableScrollPhysics(),controller: _pageController,onPageChanged: (ind) {
                index = ind;
              },children: [
                SomePage(),],),bottomNavigationBar: SingleChildScrollView(
              scrollDirection: Axis.horizontal,child: Container(
                someCode(),child: SomeCode(),)
                        tabBackgroundColor: Colors.grey[800],tabs: [
                          tabs()
                        ],selectedIndex: _currentIndex,onTabChange: (ind) {
                          index = ind;
                         _pageController.jumpToPage(index);
                        )//closing brackets (omitted)
   //brackets

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...