How to land the user on a different page while using AutoTabsScaffold and BottomNavigationBar? - flutter

I'm using Auto_Route for routing in my application and AutoTabsScaffold makes it easier. But by default, the user is navigated to the first page in the bottom navigation bar but I want it to be navigated to third page by default. How can I do that?
Here's a snippet of the code:
AutoTabsScaffold(
routes: [
A(),
B(),
C(),
D(),
E(),
],
bottomNavigationBuilder: (_, tabsRouter) {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.black,
selectedItemColor: const Color(0XFFEAF8FF),
unselectedItemColor: Colors.grey,
currentIndex: tabsRouter.activeIndex,
onTap: tabsRouter.setActiveIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.groups_outlined), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.search), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.catching_pokemon), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.library_add_check_outlined), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline), label: ""),
],
);
I want the user to land on C() and not A(). How can I do that? Thanks in advance.

Had the same issue.
I use auto_route package in my project.
We can see that current index depend on tabsRouter.activeIndex property.
So, I just added to the preferred route initial: true, property.
Like this:
CustomRoute(
path: '/',
page: MainScreen,
name: 'MainScreenRoute',
guards: [AuthGuard],
transitionsBuilder: TransitionsBuilders.fadeIn,
children: [
AutoRoute(
path: 'wallet',
page: WalletScreen,
),
AutoRoute(
path: 'trades',
page: TradesScreen,
),
AutoRoute(
path: 'market',
initial: true,
page: MarketScreen,
),

Related

flutter bottom navigation bar icon not showing

When I am used BottomNavigationBarItem, I can't showing my navigation icons.
I am trying this code:
import 'package:flutter/material.dart';
import 'package:task_manager/style/style.dart';
BottomNavigationBar AppBottomNav(currentIndex, OnItemTapped) {
return BottomNavigationBar(
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.list_alt),
label: "New",
),
BottomNavigationBarItem(
icon: Icon(Icons.access_time_rounded),
label: "Progress",
),
BottomNavigationBarItem(
icon: Icon(Icons.check_circle_outlined),
label: "Completed",
),
BottomNavigationBarItem(
icon: Icon(Icons.cancel),
label: "Canceled",
),
],
selectedItemColor: colorGreen,
unselectedItemColor: colorLightGray,
currentIndex: currentIndex,
showSelectedLabels: true,
showUnselectedLabels: true,
onTap: OnItemTapped,
type: BottomNavigationBarType.shifting,
);
}
You need to set uses-material-design: true in pubspec.yaml
Like Alejandro Cumpa said, you need to add uses-material-design: true in your pubspec.yaml.
You need to add this to the bottom:
name: …
description: …
publish_to: …
version: …
environment:
…
dependencies:
…
dev_dependencies:
…
flutter:
…
uses-material-design: true

i tried to Run flutter i got this :Assertion failed:

I tried to Run flutter and i got this error: Another exception was thrown: Assertion failed:
file:///home/moi/snap/flutter/common/flutter/packages/flutter/lib/src/material/bottom_navigation_bar.dart:189:9
You need to provide label on your BottomNavigationBarItem.
You can just empty string like
BottomNavigationBarItem(icon: Icon(Icons.abc), label: ""),
If you like to hide labels, do like this
bottomNavigationBar: BottomNavigationBar(
showSelectedLabels: false,// this
showUnselectedLabels: false,// this
items: [
BottomNavigationBarItem(icon: Icon(Icons.abc), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.abc), label: ""),
],
),

The argument type 'Text' can't be assigned to the parameter type 'String'

I'm getting this issue after after updating from old version (Title) to Label in the bottom nav bar. Here's a sample of the code:
BottomNavigationBarItem(
icon: Icon(iconname.shop),
label: Text(
'Store',
style: tabLinkStyle,
)),
label is accepting String?, not a widget, so your code should be as following:
BottomNavigationBarItem(
icon: Icon(conname.shop),
label: 'Store',
),

Flutter - How to add TextStyle to label in BottomNavigationBarItem?

I have a BottomNavigationBar() in my app however after I updated to Flutter 1.22 the title parameter is deprecated. As the new label only takes a String input I cannot pass the Text() widget to pass a custom TextStyle. How do I achieve this now with the new update?
BottomNavigationBarItem(icon: Icon(Icons.notifications), label: 'tickets'),
BottomNavigationBarItem(icon: Icon(CustomIcons.calendar), label: 'calendar'),
BottomNavigationBarItem(icon: Icon(CustomIcons.home), label: 'home'),
BottomNavigationBarItem(icon: Icon(CustomIcons.podcasts), label: 'microphone'),
BottomNavigationBarItem(icon: Icon(CustomIcons.search), label: 'search')
BottomNavigationBar(
selectedLabelStyle: TextStyle(),//your text style
unselectedLabelStyle: TextStyle(),// your text style
items: [
BottomNavigationBarItem(icon: Icon(Icons.notifications), label: 'tickets'),
BottomNavigationBarItem(icon: Icon(CustomIcons.calendar), label: 'calendar'),
BottomNavigationBarItem(icon: Icon(CustomIcons.home), label: 'home'),
BottomNavigationBarItem(icon: Icon(CustomIcons.podcasts), label:
'microphone'),
BottomNavigationBarItem(icon: Icon(CustomIcons.search), label: 'search'),
]
)

Flutter app - Problems Lifting State...Suggestions?

I'm working on a Flutter app and trying to make my bottom navigator bar more universal. As part of that, I've moved it to its own file and now need to simply lift state up to the parent class in order to highlight the selected icon. I call it like so from the parent:
bottomNavigationBar: buildBottomNavBar(
selectedIndex: selectedIndex,
redrawDisplay: redrawDisplay,
context: context,
),
And the bottomNaviBar is built like so:
return BottomNavigationBar(
currentIndex: selectedIndex,
onTap: (int index) {
selectedIndex = index;
redrawDisplay(selectedIndex);
onBottomMenuTap(index, appProject.picsSelectable, context);
},
elevation: 5.0,
iconSize: 30.0,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.note_add),
label: 'Add Metadata',
),
BottomNavigationBarItem(
icon: Icon(Icons.share),
label: 'Share Pics',
),
BottomNavigationBarItem(
icon: Icon(Icons.delete),
label: 'Delete Pics',
),
],
);
The 'redrawDisplay' function is simply a function in the parent class that sets state, like so:
void redrawDisplay({int selectedIndex}) {
setState(() {
this.selectedIndex = selectedIndex ?? 0;
});
}
I swear this was working a few days ago, but now I'm getting the following exception:
════════ Exception caught by gesture ═════════════════════════════════════════════
Closure call with mismatched arguments: function '_SearchScreenState.redrawDisplay'
Receiver: Closure: ({int selectedIndex}) => dynamic from Function 'redrawDisplay':.
Tried calling: _SearchScreenState.redrawDisplay(0)
Found: _SearchScreenState.redrawDisplay({int selectedIndex}) => dynamic
═══════════════════════════════════════════════════════════════════════
Obviously something has changed in my code, but I have been staring at this for hours and haven't cracked it yet. Anybody have some insight into what I've screwed up?
Thanks in advance.