benyaminbeyzaie / circular_bottom_navigation

Circular bottom navigation is a bottom navigation library for flutter with circular indicator and cool animations.
BSD 3-Clause "New" or "Revised" License
662 stars 97 forks source link

Navigation stuck at setState() #1

Closed UG closed 5 years ago

UG commented 5 years ago

I was trying to using bottom navigation bar, I got stuck animation and not changing state issue.

when I remove setState, working propery but, when I selectedPos change in the setState() It's stucks.

Any idea ?

import 'package:flutter/material.dart';
import 'package:circular_bottom_navigation/circular_bottom_navigation.dart';
import 'package:circular_bottom_navigation/tab_item.dart';
import 'package:mitsurakuapp/view/FavoriteScreen.dart';

class HistoryScreen extends StatefulWidget {
  @override
  HistoryState createState() => HistoryState();
}

class HistoryState extends State<HistoryScreen> with TickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }
  @override
  void dispose(){
    super.dispose();
    _navigationController.dispose();
  }
  CircularBottomNavigationController _navigationController;
  int selectedPos =0;
  List<TabItem> tabItems = List.of([
    new TabItem(Icons.history, "history", Colors.blue),
    new TabItem(Icons.favorite, "favorite", Colors.orange,),
  ]);
  @override
  Widget build(BuildContext context) {
    _navigationController = new CircularBottomNavigationController(selectedPos);
    return new Scaffold(
      body: selectedPos == 0 ? Container(child:Text('test')): FavoriteScreen(),
      bottomNavigationBar: CircularBottomNavigation(tabItems, controller: _navigationController, selectedCallback: (int pos){
       print(pos);
       setState(() {
         this.selectedPos = pos;
       });
      },),
    );
  }
}`
imaNNeo commented 5 years ago

Ok I will check it, but for now what is your purpose with this line :

this.selectedPos = pos;

Do you want to keep track of the selected position? If yes, you can use

_navigationController.value

To get the current selected tab whenever you want. And notice that there is no need to have _navigationController when you don't need to it. I think it's useless in your code.

UG commented 5 years ago

Thanks. great, my issue is solved.