I try go to another page using bottom app bar button with code under onPressed like this:
TextButton(
onPressed: () {
Get.toNamed('/Register');
},
child: const Text("REGISTER"));
But nothing is changed, page is not refreshed. Why? How to do it?
Related
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
)
I set two widgets in a Stack(), the one in the back is a sidebar and the one in the front is my main page.
When I click on the menu button from the main page, the main page gets shifted to the right and then the user can see the sidebar.
Now the problem is when the sidebar gets displyed i'm obliged to click exactly on the menu button to go back to the main page.
What i want to do is just to click anywhere in the main page to hide the sidebar.
I mean that i want to set the whole main page as a button when the sidebar is displayed.
You can use InkWell
InkWell(
onTap: (){
/// do something
},
child: Text('data') /// your widget,
),
You can also use GestureDetector
Generally if you want to make anything tappable you can just wrap the widget with GestureDetector
I fixed it by wrapping the main page with InkWell() and I added this to the onTap property"
InkWell(
onTap: isSidebarCollapsed ? () {
setState(() {
isSidebarCollapsed = false;
});
} : null,
child: Container(...)
)
Note that isSidebarCollapsed is the variable that determines if the menu is displayed or not.
Explaination of the code:
If the sidebar is collapsed (is displayed) then the onTap property returns a function where I set the variable isSidebarCollapsed to false (to say that the sidebar is gonna be hidden).
Else it returns null
I am Making an App with a custom bottom bar. I have made a screen having two containers in a stack one container is the Screens changer and the second container is a bottomMenuBar. I am changing the screens easily from bottomMenuBar container but inside one of the child screens i want to change the the whole screen from a button. please help!
enter image description here
Use this statement:
FlatButton(
child: Text('Third Screen'),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => ThirdScreen()));
},
),
I have a Flutter Application running on web and I need to reload the browser tab programmatically, and I wonder if there is something similarly with html.window.close() but for reload. Is there any way to do this in Flutter?
Use location.reload method
import 'package:universal_html/html.dart' as html;
FlatButton(
child: Text('Refresh'),
onPressed: () {
html.window.location.reload();
},
),
This is my home page code:
routes: {
'/second' : (context) => addExpence(),
},
my second-page code is:
FlatButton(
child: Text("Done".toUpperCase()),
onPressed: (){
Navigator.pop(context);
},
)
please note that both pages are in different files. Now the problem is that I am getting a black screen when popping from the First Page.
It's a natural thing to get a black screen when you pop from the first page because the Navigator will be empty. The only reason you're popping the first page is probably to close your app, for which you should use this method.
#Lewis Weng's answer is the correct one that works for me too.
if(Navigator.canPop(context)){
Navigator.of(context).pop();
}else{
SystemNavigator.pop();
}