如何导航到具有BottomNavigationBar的屏幕并同时更改BottomNavigationBar的选项卡?

问题描述 投票:0回答:1

我想同时导航屏幕并更改bottomNavigationBar中的选项卡。

....

class _MainPageState extends State<MainPage> with TickerProviderStateMixin {
  ...

  Widget selectedAppBar(int index) {
    ...
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: selectedAppBar(_selectedIndex),
        body: SafeArea(
          child: _screenOptions.elementAt(_selectedIndex),
        ),
        bottomNavigationBar: BottomNavigation(
          onChangeScreen: _onChangeScreen,
          selectedIndex: _selectedIndex,
        ),
      );
  }

  ...
}

其他页面,有一个底部,当我单击它时,将导航到主屏幕并更改BottomNavigationBar的选项卡

....

class _ItemState extends State<ItemPage> {

  ItemScreenArguments _screenArguments;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    _screenArguments = ModalRoute.of(context).settings.arguments;
    final item = _screenArguments.item;

    return BlocBuilder<CartBloc, CartState>(
      builder: (BuildContext context, CartState state) {
        ...

        final cart = (state as LoadCartState);
        return Scaffold(
          extendBodyBehindAppBar: true,
          appBar: AppBar(
          backgroundColor: Colors.transparent,
            title: Text(item.name),
              actions: [
                Basket(
                  count: cart.count,
                  onTap: () {
                   // It should navigate main route and fourth section in bottomNavigationBar
                   Navigator.of(context).popUntil(ModalRoute.withName('/main'))
                  },
                )
              ]
            ),
            body: ItemScreen(),
            ...
        );
      }
    );
  }

我尝试使用Bloc还是使用Bloc是个坏主意?

[可能是,使用Router MaterialPageRoute比使用Bloc更好,或者一起使用它们?你怎么做?您可以帮助选择更好的选项吗?

flutter dart
1个回答
0
投票

您可以发送要默认选择的标签号

© www.soinside.com 2019 - 2024. All rights reserved.