Example this Screen short, Click this Red Banner open new Page.
Any one please share Source code.enter image description here
I don't know if that's what you want but you can do it like this:
return GestureDetector(
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => Page(), // The page you want
),
);
},
child: Child(), // The banner
);
Related
I'm building an app for fire tv/fire stick using flutter.
My requirement: Show a dialog on press of a button in the fire TV remote and hide the dialog when the user presses the back button on the remote.
What I have accomplished: I'm able to show the dialog on the press of a button on the remote.
I need help in dismissing the dialog when the user presses back button on the remote.
What is happening now: When I press back while the dialog is shown, the entire page gets rerouted to the previous page.
I'm guessing it has something to do with the context, not sure how to fix this issue.
_showInfoModal(context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
backgroundColor: Colors.transparent,
content: Container(
child: Center(
child: Text(widget.message, style: TextStyle(color: Colors.white)),
),
)
);
},
);
}
This is the code I'm using to show the dialog.
Navigator.of(context, rootNavigator: true).pop();
This is how I'm trying to pop the alert dialog.
Can someone please help me out here? TIA.
Try below code hope its works because I also build apk for TV and use below Alert Code
showAlert(BuildContext context) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Top '),
content: Text('Bottom '),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Ok'),
),
],
);
},
);
}
So I was able to accomplish this using a workaround.
Having a boolean variable and showing either the dialog or a container with 0 height.
Not a good approach but gets the work done.
this question had already asked in this link How to configure go back button in Browser for Flutter Web App
and I implement onWillPop, so when user is in A screen and then click the button See Detail I will navigate them to B screen and then.. when user is in B screen and click the back button of browser I will navigate them back to A screen... the first trial is success but when I do it second time I got an error like this
Error: Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/navigation/history.dart:288:14
_userProvidedRouteName != null
is not true
in my first screen (A Screen), I have a button like this:
FlatButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext ctx) =>
Detail(
value:x[i])));
},
child: Text("See Detail"),
textColor: Colors.white,
color: Colors.blueAccent,
)
and for the Detail Screen (B Screen) I use onWillPop like this
WillPopScope(
onWillPop: () {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (BuildContext ctx) => FirstScreen()));
return Future.value(true);
},
child: Scaffold(
key: _globalKey,
....
is there something that I should add more?
Call Navigator.pop(context); inside the onWillPop of screen B.
Make sure when you navigate from Screen A to Screen B, you should not use Navigator.pushReplacement as it removes ScreenA from the screen stack(not sure if this is the right term)
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ScreenB()),
);
Here is an example by flutter.
https://flutter.dev/docs/cookbook/navigation/navigation-basics
How can I download an image from flutter web?
The image is not clickable/dragable and shows no context menu on right click, for example to "save as".
Web implementation - http://watools.xyz/ankush_apis/flutter_projects/youtube/#/
Is there an alternative Image widget, to make it web clickable?
Like Text and SelectableText.
Maybe an Property, a pub package?
Any answers appreciated.
Did you try to use the InkWell widget? It supports gesture and already implements the clickable effect.
InkWell(
child: Image.network(
'https://i.picsum.photos/id/9/250/250.jpg?hmac=tqDH5wEWHDN76mBIWEPzg1in6egMl49qZeguSaH9_VI'),
onTap: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Options'),
actions: [
TextButton(
child: Text('Save image'),
onPressed: () {
//Code for download the image
},
),
],
),
);
},
),
The "OK" button on my alert dialog navigates to a new page. But when I go back to the previous page, the alert is still there. Is there any way for the alert to disappear after I navigate to the new page?
// Alert Dialog
Future<void> _handlePhoto(BuildContext context) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text('Please Position Crosshair'),
content: const Text(
'Before detecting cancer, ensure your focus area is centered.'),
actions: <Widget>[
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pushNamed(
'/camerapage',
arguments: cameras,
);
},
),
],
);
},
);
}
Before pushing the new page, you need to pop the dialog like this. So when you come back it is not there.
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(
'/camerapage',
arguments: cameras,
);
}
Hi i am newbie into flutter, how can i achieve custom PopUpMenu as shown in below screenshot.
ScreenShot
Any help would be appreciated, Thanks..
You should use the method showDialog to display an AlertDialog Widget.
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("PopUp title"),
content: Text("PopUp content text"),
actions: <Widget>[
FlatButton(child: Text("Close"), onPressed: () => Navigator.pop(context))
],
);
});