how can i navigate between icons in the appBar on flutter? - flutter

I am new flutter developer and I would like to browse among these icons in app bar,Any idea?
tmy.png

You can use Tab Bar, please check this : https://m.youtube.com/watch?v=r1sQTA_zPog
If you hope to do it with the hard way you can make a button for each icon and in onPressed add setState with Navigator and modified color
Check ; https://flutter.dev/docs/development/ui/navigation

You can use like the below code for every icon.
IconButton(
icon: Icon(Icons.add_box),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
)

Related

Flutter Drawer Navigation

I have a list of Screens in a custom drawer.
Screen 1,
Screen 2,
Screen 3
What is the proper way of navigating from Screen 1 to Screen 2 on push of a button. Currently, I am losing the hamburger (the drawer button) option when I push or push replace.
The code I have was not written by me and I do not have access to the person who wrote the code.
Any thoughts?
Just use the standard navigation:
TextButton(
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => Screen2()));
}
child:
//child goes here
)

How to change screen index after sliding the tab? flutter

i am using tabbar view with my app that have same floating action button:
floatingActionButton: FloatingActionButton(
onPressed: () async{
print("this is the current Screen :$currentScreen");
if(currentScreen==0)
{
await showInformationDialog(context);
}
else
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddNewVehical(1),
),
);
},
but when i tap on tab it works perfectly and the currentscreen variable changes from 0 to 1 as expected but problem arises when i slide from one tab to another the currentscreen variable print always zero due to which on the other tab it also shows dialogue
can anyone tell me why this is happening? and a solution for it ?
Thanks in advance <3
You can add TabController listener in initState().
_tabController!.addListener(_handleTabSelection);
In _handleTabSelection method, get the tabController index.
currentScreen = _tabController!.index;
You can use TabController. With the index property you can get the currentIndex.
reference : https://api.flutter.dev/flutter/material/TabController-class.html

How to prevent navigation buttons in dart

How to disable navigation buttons on the flutter app so the user can't be redirect to another page, recent view, and home.
Using onWillPop: () async => false, only affects the back button.
Specify null for the values of onTap, onPressed, etc to disable the buttons.
onTap: (someCondition) ? null : () {...}

How to solve Swipe back not working on iOS

each time i use a plugin to move to the next page on iOS the swipe back will not work like
Navigator.push(
context,
Transition(
child: Bio(),
transitionEffect: TransitionEffect.BOTTOM_TO_TOP),
);
i have use like 5 plugin now swipe back is not working
but if i use this
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (ctx) => Actitvities(),
),
);
the swipe back works....
but i want to use transition for the page route
in my case.
i was using a plugin and the plugin is using
WillPopScope (
onWillPop: () async {
},
so i fork the plugin and remove the willpopscope.
then i add the fork plugin like this to my pubspeck
kittens:
git:
url: git://github.com/munificent/kittens.git
ref: some-branch
full example here

Navigation in Flutter App - does not work as intended

I try to build a flutter app and want to navigate trough the pages.
I build a drawer with a menu with several items to open new pages - that works fine.
onTap: () {
Navigator.of(context).pop();
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) => new Page1(),
),
);
},
By pressing on the Page1 menuitem page1 opens fine.
Inside page1 I have a slidable list with "edit" and "details". I open this with
onTap: () {
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => new DetailsPage(),
),
);
},
In the details Page I see all the things i wanna see, but when I press the Back button in the appBar i am back at home screen with closed drawer.
I tried to put onPressed: () => Navigator.pop(context); inside the appBar section but this doesn´t work either.
Now I got what I want by using always Navigator.push but I am sure that this is not right, so that navigator stack gets bigger and bigger.
What I do wrong? Why .pop does not bring me to the last page?
Any ideas?
Thx in advance
Patrick
Just remove the line with the Navigator.of(context).pop();in the Page1 onTap.
you can use pushReplacement in any cases you need to remove current page from stack and route to new page.
Replace the current route of the navigator that most tightly encloses
the given context by pushing the given route and then disposing the
previous route once the new route has finished animating in.
here is the documentation