Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when using custom navBar on items is null even when passing itemCount #49

Closed
Yetispapa opened this issue Aug 5, 2020 · 11 comments

Comments

@Yetispapa
Copy link

Im' currently facing the issue that the following line is throwing an exception that items is null:

assert(assertMidButtonStyles(navBarStyle, items.length),

Even when I pass the following parameter:

itemCount: items.length, // This is required in case of custom style! Pass the number of items for the nav bar.

It seems there is a simple condition missing

@BilalShahid13
Copy link
Owner

Can you please share your code around PersistentTabView? Also are you using a custom style?

@Yetispapa
Copy link
Author

This will fail:

PersistentTabView(
        controller: _controller,
        itemCount: items.length, // This is required in case of custom style! Pass the number of items for the nav bar.
        screens: _buildScreens(),
        confineInSafeArea: true,
        handleAndroidBackButtonPress: true,
        onItemSelected: (int) {
            setState(() {}); // This is required to update the nav bar if Android back button is pressed
        },
        customWidget: CustomNavBarWidget( // Your custom widget goes here
            items: _navBarsItems(),
            selectedIndex: _controller.index,
            onItemSelected: onItemSelected: (index) {
                setState(() {
                    _controller.index = index; // NOTE: THIS IS CRITICAL!! Don't miss it!
                });
            },
        ),
        navBarStyle: NavBarStyle.custom, // Choose the nav bar style with this property
        );

My fix was:

PersistentTabView(
          items: items, // <== my fix
        controller: _controller,
        itemCount: items.length, // <== this will be ignored | This is required in case of custom style! Pass the number of items for the nav bar.
        screens: _buildScreens(),
        confineInSafeArea: true,
        handleAndroidBackButtonPress: true,
        onItemSelected: (int) {
            setState(() {}); // This is required to update the nav bar if Android back button is pressed
        },
        customWidget: CustomNavBarWidget( // Your custom widget goes here
            items: _navBarsItems(),
            selectedIndex: _controller.index,
            onItemSelected: onItemSelected: (index) {
                setState(() {
                    _controller.index = index; // NOTE: THIS IS CRITICAL!! Don't miss it!
                });
            },
        ),
        navBarStyle: NavBarStyle.custom, // Choose the nav bar style with this property
        );

@BilalShahid13
Copy link
Owner

Yes, I think after the last update an assert is conflicting with the custom widget. Thanks for reporting it and I'll hopefully fix it in the upcoming update!

For now you can go on with the fix that you found. When using customWidget, the items don't matter as they wont be used so passing dummy items list will do here until the next update.

@BilalShahid13
Copy link
Owner

Also keep in mind that some features like popAllScreensOnTapOfSelectedTab will not work with custom widget. You will have to use the provided styles for that or implement it yourself in the custom widget.

@Yetispapa
Copy link
Author

Good to know with popAllScreensOnTapOfSelectedTab

Thanks for your quick response and of course thanks for the great framework!

@Alwin-Lazar
Copy link

Same issue here. I can not use @Yetispapa solution in my case. Because I am using CustomBottomNavBarItem which is not same to items's datatype (PersistentBottomNavBarItem). So I expect a quick fix on this issue. And your are doing a amazing work @BilalShahid13 . We really appreciate that.

@PocketDaniel
Copy link

Same issue here. I can not use @Yetispapa solution in my case. Because I am using CustomBottomNavBarItem which is not same to items's datatype (PersistentBottomNavBarItem). So I expect a quick fix on this issue. And your are doing a amazing work @BilalShahid13 . We really appreciate that.

Same here, but as a "temporary workaround" a.k.a. hack I am creating dummy list with PersistentBottomNavBarItem and some random icon:

items: List<PersistentBottomNavBarItem>.generate(
    pages.length, // Same as itemCount
    (index) => PersistentBottomNavBarItem(icon: Icon(Icons.home)),
),

@BilalShahid13
Copy link
Owner

BilalShahid13 commented Aug 21, 2020

Fix will be released this weekend or early next week. Thank you for your patience!

@Alwin-Lazar
Copy link

@BilalShahid13 Bro the issue still there. do something.

@CnuFederer
Copy link

Hi, This issue is still there. Can u pls release latest update.

Thanks.

@BilalShahid13
Copy link
Owner

This issue has been fixed in latest update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants