class BottomNavigationPage extends StatefulWidget {
@override
_BottomNavigationPageState createState() => _BottomNavigationPageState();
}
class _BottomNavigationPageState extends State<BottomNavigationPage> {
int selectedIndex = 0;
final _widgetOptions = [
Explore(),
PortFolio(),
Profile(),
];
final _proposalListingBLoc= ProposalListingBLoc(proposalRepository: ProposalRepository());
_BottomNavigationPageState(){
_proposalListingBLoc.dispatch(FetchAllProposalEvent());
_proposalListingBLoc.dispatch(FetchLatestProposalEvent());
_proposalListingBLoc.dispatch(FetchPartFundedProposalEvent());
_proposalListingBLoc.dispatch(FetchTopRankedProposalEvent());
}
@override
void dispose() {
super.dispose();
_proposalListingBLoc.dispose();
}
@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.search), title: Text('Explore')),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.switch_camera),
title: Text('Newsfeed')),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.photo_camera_solid),
title: Text('Portfolio')),
/* BottomNavigationBarItem(
icon: Icon(CupertinoIcons.home), title: Text('Inbox')),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.person), title: Text('Profile')),*/
],
),
tabBuilder: (BuildContext context, int selectedIndex) {
return BlocProvider(
bloc: _proposalListingBLoc,
child: CupertinoTabView(builder: (BuildContext context) {
return _widgetOptions.elementAt(selectedIndex);
}),
);
},
);
}
}
class Explore extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ExplorePage();
}
}
class PortFolio extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InterestedProposalPage();
}
}
class Profile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ProfilePage();
}
}
Hi @basnetjiten 馃憢
Thanks for opening an issue!
Can you please describe what the issue you're having is as well as what you expect the behavior to be? Thanks! 馃憤
@felangel Thanks for replying. let me share you the scenario of what I want to achieve.
I have a Bottom Navigation page. The first page called ExplorePage has furthure TabBarViews with 4 Tabs. I want to fetch the data into these page. so for that I want to dispatch events from the BottomNavigation Page so that when I move to Explore Page the Tab View with page has already have data fetched. I just want to know if theres way to chain the dispatch method for different events like Redux
@basnetjiten Well if each bloc is independent and each fetch is async, then there is no need for a sequenced chain vs. just calling the dispatches simultaneously. It would help to know what kind of behavior your current code yields but there are a few clear things you should look at:
You only need 1 BlocProvider per bloc, and then all of its children can reference it via context, so there is no need to create a new BlocProvider for each tab, a BlocBuilder would make more sense per tab and might be what you were after.
It is likely that if you are calling independent fetches for each tab, then you should probably just give each tab its own bloc entirely so you can properly handle the various states for each tab's data.
If you do make each tab have its own bloc, you can then just call each initial fetch in the respective bloc's constructor so as soon as the bloc is created, the data is fetched. You would need to initialize the blocs outside of their respective pages if you want the data to already be fetched by the time you go to that tab, and just pass the tab bloc either by constructor or reference via BlocProviderTree.
Thanks @hawkinsjb1 for your detailed response! I really appreciate the help 馃憤
@basnetjiten closing this for now but feel free to comment with any additional questions and I'm more than happy to continue the conversation 馃槃
Most helpful comment
@basnetjiten Well if each bloc is independent and each fetch is async, then there is no need for a sequenced chain vs. just calling the dispatches simultaneously. It would help to know what kind of behavior your current code yields but there are a few clear things you should look at:
You only need 1 BlocProvider per bloc, and then all of its children can reference it via context, so there is no need to create a new BlocProvider for each tab, a BlocBuilder would make more sense per tab and might be what you were after.
It is likely that if you are calling independent fetches for each tab, then you should probably just give each tab its own bloc entirely so you can properly handle the various states for each tab's data.
If you do make each tab have its own bloc, you can then just call each initial fetch in the respective bloc's constructor so as soon as the bloc is created, the data is fetched. You would need to initialize the blocs outside of their respective pages if you want the data to already be fetched by the time you go to that tab, and just pass the tab bloc either by constructor or reference via BlocProviderTree.