How to add onclick function to image in a markdown in flutter? - flutter

I need to download the image file showing in the MarkdownBody in flutter. Is there any way to add function when image is clicked in markdown?
I have surfed for this but I got nothing.

From what I can see you need onPressed method or OnTap on your image in markdown so wrap the entire image/markdown whichever widget you want in either GestureDetactor it has onPressed property or InkWell which has onTap Property and you can write your function inside
For Example refer this sample code
GestureDetector(
onTap: (){
// Write you function/code
},
child: new Container(
width: 500.0,
padding: new EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 40.0),
color: Colors.green,
child: AssetImage(asset/Image/sample.jpg),
)
);

Related

Flutter Box with Navigation on pressed

I am writing a flutter app where i want create boxes like grid and each can be click to navigate on different screen.
Similar to below example
I am a beginner, how can i achieve this. Can you please share some pointer. I went through Documentation but if you can help me with what to search for I can read. or if you can share some exmaple.
You can wrap each box widget with an inkwell and add an onTap to it where you can call the navigation ie:
InkWell(
onTap: () => Navigator.of(context).pop(false),
child: Container(
height: 25.0,
width: 80.0,
child: Text('CANCEL'),
),
InkWell
Gesture Detector

why navigation doesn't work if using alignment property in Flutter?

I have created this page.
I have made some navigation by routes. But the problem is I want to change the position of my IconButton to the Center bottom of the page. That's why I am using the alignment parameter but as soon as I use that parameter my navigation stops working. But my Icon comes to my desired location but onPress function stop working.
I have the alignment code in the image.
Please guide what's wrong.
Thanks
Entire Code
Container(
width: 100,
height: 100,
alignment: Alignment(0, 50),
child: IconButton(
icon: Icon(Icons.play_circle_filled),
color: Colors.yellow[900],
iconSize: 80,
onPressed: () {
Navigator.pushNamed(context, '/Second');
}),
Highlighted alignment codes

What widget to use to get a sign up button with google logo at the left

I saved the google logo a as .png because I want to keep its colors. I am aware there are some packages for predefined sign-in buttons like google or with the google Icon(but I can't keep the colors obviously in this case), but I would like to know if I can somehow make so the .png image acts like an Icon.
You can use whatever button widget you like or you can create your custom button...
According to your image you can use outline button or flat button... then in your child parameter add Row with image and text
OutlineButton(child: Row(children: Image.asset(your_image_location), Text('Sign in with Google')))
body: Stack(
children: <Widget>[
Center(
child: IconButton(
icon: Image.asset('path/the_image.png'),
iconSize: 50,
onPressed: () {},
)
Positioned(
child: Container(
child: Center(child: Text('Sign in With Google')),
)),
],
)

Making a scrollable flat button in Flutter application

I'm trying to embed a flat button with a variable amount of text within a scroll view, so that the user can scroll the text but also tap it in order to perform an action. I tried doing this with a flat button embedded in a ConstrainedBox, which itself is embedded in a SingleChildScrollView.
I've tried embedding the FlatButton in a SingleChildScrollView as below. Earlier, I tried wrapping the text in an expanded widget with a SingleChildScrollView ancestor but that caused runtime errors because the requirements of the scroll view and the expanded view conflict (as far as I understand).
Widget contentScreen() {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(),
child: FlatButton(
onPressed: () {
_toggleContent();
},
child:
Column(children: <Widget>[
Container(
child: Text(
"Lorem Ipsum....",
style: TextStyle(color: Colors.white, fontSize: 20))),
]
)
)
)
);
}
The text just doesn't scroll. Instead it overflows and shows the diagonal yellow bars. I don't have a list of exactly what I've tried, but where I'm at right now is that I'm using the above code but there is no scrolling behavior as expected. :\
I tried this: How to make the Scrollable text in flutter?
This: Make scrollable Text inside container in Flutter
And this: how to make text or richtext scrollable in flutter?
Is there something about the FlatButton's behavior that just precludes scrolling? If so, how can I work around that to still get the two behaviors (ability to both scroll and tap to perform action) that I want?
Have you tried this? Why do you need Expanded widget?
Container(
height: 20.0,
child: FlatButton(
onPressed: () {},
child: SingleChildScrollView(
child: Text('Lorem ipsum'),
),
),
),
Gesture Detector should also work well.
Container(
height: 20.0,
child: FlatButton(
onPressed: () {},
child: SingleChildScrollView(
child: Text('Lorem ipsum'),
),
),
),

Using RaisedButton widget inside Positioned widget issue

I got an issue with RaisedButton when using it inside a Positioned widget.
The problem is when I used RaisedButton inside Positioned widget, onPressed event didn't trigger when clicking on RaisedButton child, but when I clicked on another space of RaisedButton It worked.
Note that It works fine in normal situations and It happened when using RaisedButton inside Positioned widget.
here is my widget :
Positioned(
child: Center(
child: SizedBox(
width: 80,
height: 65,
child: RaisedButton(
padding: EdgeInsets.all(0),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
color: Colors.green,
child: Icon(Icons.message, size: 50, color: Colors.white,),
// When I clicked on this icon, onPressed didn't triggered. but when I click on another space of button it triggered.
onPressed: () {
print('Hello world from onPressed');
},
),
),
),
top: -30,
left: 0,
right: 0,
)
what's your idea to fix this problem ?
The short answer is:
Flutter doesn't trigger push events for items that overlap the bounds of the stack (this is what you do when you set top to -30).
The reason behind this could be found here: Document that widgets in the overflow of stack do not respond to gestures
A possible solution for you is to move all the other items for 30.0 lower, so you can place the button inside the stack.
A solution to this problem is by wrapping the stack in a gesture detector and add what do you want to add in onpressed of the raised button in the ontap property of the gesture detector