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
Related
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),
)
);
leading: Padding(
padding: EdgeInsets.only(left: 20),
child: IconButton(
onPressed: () => print('Menu Tapped'),
icon: Image.asset(
'assets/images/vecteezy_triangle_1200693.png',
fit: BoxFit.fitWidth,
),
),
),
I try adding height: and width: to the Image.asset and iconsize: to IconButton but it does't work
Does it have something to do with edgeInsets?
PS* I'm quite new here, I'm follow YouTube to write a financial management app
if your code is about Appbar you need to increase the icon's space in the Appbar by using toolbarHeight: and leadingWidth: in the Appbar widget.
I hope this work for you.
Since you are providing this widget to "leading", I'm guessing this is for an AppBar. The size of the icon cannot exceed the size of your appbar. You need to increase the size of your appbar to be able to increase the size of your icon. If this doesn't work, provide your code containing the AppBar widget so I can test it out for you.
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
I am trying to make a layout as seen in the image in Flutter, but I don't get how to create a background with two colors and an overlapping button.
I don't know if there is a widget able to do this or need some code...
Any suggest or help will be great! (this was my very first post ever, sorry if there is something wrong about it!!)
Thanks.
Do something like this.
body: Stack(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
height: 300,
color: Colors.grey,
),
],
),
Positioned(
top: 280,
left: 50,
right: 50,
child: RaisedButton(
color: Colors.white,
child: Text("Your Button"),
onPressed: () {},
),
)
],
),
you will get
Let me know if it works
One possible approach is to use a Stack. Set the background color to your grey (i think, color blind), add the white piece as an image positioned at the bottom. Lastly add your button, again positioned at the bottom.
On closer inspection of your image, I now see that what I thought was an image at the bottom was actuall just a color. All you need are two Container s and a button in a Stack. The first Container should fill the whole space, the second Container should have a height setting (be responsive here for multiple device sizes) and lastly add your RaisedButton.
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