简体   繁体   English

如何同时进行页面切换和主动底部导航?

[英]how to do page switching and active bottom navigation at the same time?

@overrideWidget build(BuildContext context) {
final PageController controller = PageController();
return Scaffold(
  body: SafeArea(
    child: PageView(
      controller: controller,
      children: const [
        Center(
          child: Text("Page 0"),
        ),
        Center(
          child: Text("Page 1"),
        )
      ],
    ),
  ),
  bottomNavigationBar: BlocListener<MenuBloc, MenuState>(
    listener: (context, state) {
      controller.jumpToPage(state.index);
    },
    child: BlocBuilder<MenuBloc, MenuState>(
      builder: (context, state) {
        return BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: const Icon(Icons.explore),
              label: state.index.toString(),
            ),
            BottomNavigationBarItem(
              icon: const Icon(Icons.apps),
              label: state.index.toString(),
            ),
          ],
          onTap: (index) =>
              context.read<MenuBloc>().add(MenuSwitch(state.index)),
          selectedItemColor: Colors.black,
        );
      },
    ),
  ),
);

} }

i want both?我想要两个? how to make it work properly when the selected item is active and changing pages?当所选项目处于活动状态并更改页面时,如何使其正常工作?

Blockquote how to do page switching and active bottom navigation at the same time? Blockquote如何同时进行页面切换和主动底部导航?

It's Worked, With A Little Observation I finally realized it returns index doesn't need state anymore:)它的工作,稍加观察我终于意识到它返回索引不再需要 state :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM