Make flutter web Image widgets clickable - flutter

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
},
),
],
),
);
},
),

Related

How can I implement tap-able Text widget, Flutter?

I have a Text widget on pressing which another Route has to be shown. But I could not see any onPressed() method for the Text widget. Please Help.
In your case there are multiple routes where you can go.
Using material TextButton:
TextButton(onPressed: () {}, child: Text('Your child'))
Using InkWell Widget, which covers your widget with 'as button' properties, splashes etc, which allows you to have more customisable buttons taps:
InkWell(onTap: () {}, onDoubleTap: () {}, onLongPress: () {}, onHover: () {}, ..etc , child: Text('Your child widget'))
Using GestureDetector, is the most customisable solution for any gestures you can provide (from its name), can handle taps, long presses, double taps, drags etc.
Syntax is similar:
GestureDetector(onTap: () {}, child: Text('Your child widget'))
Try using TextButton widget:
TextButton(
onPressed: () {},
child: Text('Simple Button'),
),
The best way to make any widget tappable is to use GestrureDetector you just put it outside of the widget/widgets you want and you can use dozen of properties.
For example
GestureDetector(child:
onPressed: () {},
Text('Your text')
)

How to make a Widget come from below and stack itself on top of current screen?

In Duolingo's app, there is an element that comes animated from the bottom and display some text everytime you unswer a question (see image bellow).
How to replicate that feature with Flutter?
You can use showModalBottomSheet widget. Here is a simple usage of this widget:
showModalBottomSheet(
context: context,
builder: (BuildContext bc){
return Container(
child: new Wrap(
children: <Widget>[
new ListTile(
leading: new Icon(Icons.music_note),
title: new Text('Music'),
onTap: () => {}
),
new ListTile(
leading: new Icon(Icons.videocam),
title: new Text('Video'),
onTap: () => {},
),
],
),
);
}
);
You can read an article about how to use Bottom sheets here
I hope this will help you.

flutter: CupertinoAlertDialog looks different from what is shown in official docs

I tried implementing the CupertinoAlertDialog (https://api.flutter.dev/flutter/cupertino/CupertinoAlertDialog-class.html) but when I used it, it looked like this:
which is quite different from how it looks when signing in with google or as shown in the image here (https://flutter.dev/docs/development/ui/widgets/cupertino)
Here's the code:
showDialog(
context: context,
barrierDismissible: true,
builder: (_) => _buildAlertDialog());
Widget _buildAlertDialog() {
return CupertinoAlertDialog(
title: Text(
'\"Abc\" Wants to Use \"xyz.com\" to Sign In',
),
content: Text(
'This allows the app and website to share information about you.',
),
actions: <Widget>[
CupertinoDialogAction(
child: Text('Cancel'),
onPressed: () {
// Drop the dialog
Navigator.pop(context);
},
),
CupertinoDialogAction(
child: Text('Continue'),
onPressed: () {
// Drop the dialog
Navigator.pop(context);
// handle continue press
},
),
],
);
}
I tested your Code. I get the same result.
After some digging I found this : https://issue.life/questions/57676581
Looks like the backgroundColor is hardcoded. Not sure why that would be, or why it looks different to how it should.
I also found this: Flutter change dialog background color But I couldn't make any of those answers work in this case. Maybe you can though.
If nothing else works, you'll have to write your own Dialog widget. Good luck!

How to create custom Popup menu in flutter

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))
],
);
});

flutter - showDialog's barrierDismissible ignored in ios?

in android, when you tap on the "barrier"/outside/background of a (material) modal dialog created using showDialog(), the dialog closes by default.
when you tap on that barrier on an iphone (physical device), the tap to close is ignored and the modal stays open.
i realize there is a "showCupertinoDialog" option, but i am trying to avoid using it (it doesn't tap-barrier-to-close either).
the flutter/dart documentation doesn't indicate any differences in expected behavior of android -vs- ios. i've included some example code that illustrates the issue, i would expect the _showMaterialDialog() dialog to close on iphones, but it does not.
any idea why this is not working? is this a bug or expected behavior? Thanks!
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class dialogtest extends StatefulWidget {
#override
dialogtestState createState() => dialogtestState();
}
class dialogtestState extends State<dialogtest> {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text('Dialog Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () {
_showMaterialDialog();
},
child: Text('Show Material Dialog'),
),
SizedBox(
height: 20,
),
RaisedButton(
onPressed: () {
_showCupertinoDialog();
},
child: Text('Show Cupertino Dialog'),
),
],
),
)));
}
void _showMaterialDialog() {
showDialog(
context: context,
barrierDismissible: true, // ********* ignored in ios, defaults to true anyway!!
builder: (context) {
return AlertDialog(
title: Text('Material Dialog'),
content: Text('This is the content of the material dialog'),
actions: <Widget>[
FlatButton(
onPressed: () {
_dismissDialog();
},
child: Text('Close')),
FlatButton(
onPressed: () {
print('HelloWorld!');
_dismissDialog();
},
child: Text('HelloWorld!'),
)
],
);
});
}
_dismissDialog() {
Navigator.pop(context);
}
void _showCupertinoDialog() {
showDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text('Cupertino Dialog'),
content: Text('This is the content of the cupertino dialog'),
actions: <Widget>[
FlatButton(
onPressed: () {
_dismissDialog();
},
child: Text('Close')),
FlatButton(
onPressed: () {
print('HelloWorld!');
_dismissDialog();
},
child: Text('HelloWorld!'),
)
],
);
});
}
}
i figured it out in case anyone runs into this behavior randomly.
i was using flutter 1.7 (and working with android only) when I created the project. in order to support "unfocusing" of a text field when tapping outside of it, i wrapped the whole project in a GestureDetector with the instructions from here:
https://flutter360.dev/dismiss-keyboard-form-lose-focus
Everything worked perfectly. When I moved the app to a mac for iOS testing, i did a new install of flutter which came with v1.9.1+hotfix.6. I guess something in flutter changed from 1.7 -> 1.9.1 which breaks this unsupported implementation. not considering the difference between my windows/android flutter version (where it worked) to my mac/ios version (where it did not work), i assumed it was an iOS thing. Once I upgraded flutter on my PC to 1.9.1 the dialogs were no longer dismissible on my android phone.
I still need/want a way to tap-to-dismiss the keyboard from a text field. I am trying out the Listener solution from here which seems to be working as expected so far:
Flutter. A way for TextField to detect tap outside
I guess this is an exercise in side-effects of creative solutions to functionality not provided out of box by the framework coupled with understanding the impacts of updating the framework.