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

Navigation stuck at setState() #1

Closed
UG opened this issue Feb 20, 2019 · 2 comments
Closed

Navigation stuck at setState() #1

UG opened this issue Feb 20, 2019 · 2 comments

Comments

@UG
Copy link

UG commented Feb 20, 2019

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
Copy link
Collaborator

imaNNeo commented Feb 20, 2019

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
Copy link
Author

UG commented Feb 20, 2019

Thanks. great, my issue is solved.

@UG UG closed this as completed Feb 20, 2019
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

2 participants