pedromassango / bottom_navy_bar

A beautiful and animated bottom navigation
https://youtu.be/jJPSKEEiN-E
Apache License 2.0
1.04k stars 219 forks source link

Swiping through pages work but Changing page through nav bar doesnt bar #73

Closed prateekmedia closed 3 years ago

prateekmedia commented 3 years ago

Below is the code in my main.dart file, note that swiping behaviour works but the logic of pageController doesn't work.

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  PageController _pageController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: PageView(
          controller: _pageController,
          children: <Widget>[
            HomeContent(),
            CalendarContent(),
            AddContent(),
            ProjectsContent(),
            SettingsContent()
          ],
          onPageChanged: (index) {
            setState(() {
              _currentIndex = index;
            });
          },
        ),
      ),
      bottomNavigationBar: BottomNavyBar(
        selectedIndex: _currentIndex,
        showElevation: true,
        itemCornerRadius: 24,
        curve: Curves.elasticInOut,
        onItemSelected: (index) => setState(() {
          _currentIndex = index;
          _pageController.animateToPage(index,
              duration: Duration(milliseconds: 300), curve: Curves.ease);
        }),
        items: [
          BottomNavyBarItem(
            icon: Icon(Icons.home),
            title: Text('Home'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.calendar_today_outlined),
            title: Text('Calendar'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.add),
            title: Text('Add'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.work_outline_outlined),
            title: Text('Projects'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
          BottomNavyBarItem(
            icon: Icon(Icons.settings),
            title: Text('Settings'),
            activeColor: Colors.deepPurple[800],
            inactiveColor: Colors.black45
          ),
        ],
      )
    );
  }
}

I tried with both page Controller Jump to page and the animateToPage but it either disables clicking on the items or it doesnt change page and just clicking behaviour works and not page changing one.

Also I tried with and without SizedBox.expand as parent of Page View but it didn't work.

I will try to make a new project and try it again to see if its this package problem or not.

prateekmedia commented 3 years ago

Additional Info in pubspec yaml file

dependencies:
  flutter:
    sdk: flutter

  carousel_slider: ^2.3.1
  bottom_navy_bar: ^5.6.0

Remove the other dependency doesn't work either

prateekmedia commented 3 years ago

https://user-images.githubusercontent.com/41370460/103173403-cdc22a80-4880-11eb-8f7b-2b7fa22f4193.mp4

Above is the issue with this code and I was Clicking really hard on the Buttons

prateekmedia commented 3 years ago

https://user-images.githubusercontent.com/41370460/103173595-044c7500-4882-11eb-8e80-0565c9f88f6b.mp4

This is other clip in which everything in pageView is working button clicking on Bottom Nav Bar doesnt seem to work

prateekmedia commented 3 years ago

I removed pageController and page view that were causing problem and added Widget[_currentIndex] as Children to temporarily fix this issue.

pedromassango commented 3 years ago

Hi @prateekmedia Are you still facing this issue? Could you please tell me which version of this package are you using? Thanks

prateekmedia commented 3 years ago

Actually the problem was that current index variable was not inside the build context.