Flutter Box with Navigation on pressed - flutter

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

Related

How to add onclick function to image in a markdown in 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),
)
);

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

How do we can make a image to take the whole space available in the floating action button in flutter

I am trying to add a image in floating action button which I have done easily but the problem I am facing is that I don't know how to make this image to take the whole space available in the floating action button ... I tried my best researched in the internet but did not not fount anything ...any help is appreciated thanks in advance
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
height: MediaQuery.of(context).size.width * 0.24,
width: MediaQuery.of(context).size.width * 0.24,
child: FloatingActionButton(
//backgroundColor:Colors.lightGreen,
child: Image.asset("assets/home_unselected.png"),
onPressed: () {}),
),
You can make use of CircleAvatar widget and pass the desired image as backgroundImage alongwith giving a custom radius to it, as below:
child: FloatingActionButton(
child: CircleAvatar(
radius: 50,
backgroundImage: AssetImage("assets/placeholder.png",
),
),
onPressed: () {}),
Hope this answers your question.
Have you tried warping the "Image" widget with "Expanded" widget?
Not sure about this though.
You just have to put your widget immediately as the child for the floatingActionButton attribute:
floatingActionButton: Image.asset("assets/icons/send_icon.png"),
By this way, you won't have unwanted padding.
You can find more info in the doc by double-clicking the attribute:
/// A button displayed floating above [body], in the bottom right corner.
///
/// Typically a [FloatingActionButton].
final Widget? floatingActionButton;

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')),
)),
],
)

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