How to create a vertical button in the flutter? - flutter

im try to created a verticle button on the left center screen in the flutter. First i created a Raised Button and rotate it using Rotated Box. But it keeping padding left side of the button. i dont want padding on the left side. How to possible it ?
body: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: RotatedBox(
quarterTurns: 1,
child: RaisedButton(padding: EdgeInsets.all(0), color: Clr.primaryClr, onPressed: () {}, child: Text('SPORTS')))),
pages[currentPage],
],
),

You can remove padding of button with:
RaisedButton(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap)

Related

How to add button in Flutter

I am new in flutter.
I am following some YouTube videos to learn flutter. After adding a picture in card(home screen) now I want to add two buttons below that picture. how can i do it.
the picture Adding code
body: Center(
child: Card(
child: Column(
children: [Image.asset("assets/image-name")],
),
),
),
Here you have a great page, where you can find implementations of basic material widgets in Flutter.
For your example, it would look like this:
body: Center(
child: Card(
child: Column(
children: [
Image.asset("assets/image-name"),
ElevatedButton(
onPressed: () {
// Respond to button press
},
child: Text('CONTAINED BUTTON'),
)
],
),
),
),
For a second button, you can just add another one in the children array.
You can also wrap both buttons in Row widget, that will allow you to place them horizontally, next to each other.

How to move the flutter app bar logo to center left

I want to show a logo on app bar and am achieving it through the following code.
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 3,
title: Align(
alignment: Alignment.centerLeft,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerLeft,
child: Image.asset(
'assets/logo/logo.jpg',
fit: BoxFit.fitWidth,
height: MediaQuery.of(context).size.height * 0.3,
width: MediaQuery.of(context).size.width * 0.2,
),
),
]),
)),
Output am getting
The problem here is The icon is centered how can I stick to the right like this
Desired Output
As in the above code I already tried
alignment: Alignment.centerLeft,
crossAxisAlignment: CrossAxisAlignment.start,
Still not working anyone have any idea? Please support.
It looks like that you are almost there with your code. Here is the snippet that'll place your logo in left inside appbar.
AppBar(
backgroundColor: Colors.white,
elevation: 3,
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset(
'assets/nividata-logo.png',
fit: BoxFit.fitWidth,
height: MediaQuery.of(context).size.height * 0.3,
width: MediaQuery.of(context).size.width * 0.2,
),
])),
Okay, as you can see I've just used row and gave mainAxisAlignment to start, so that'll place every element inside row from start.
If I change this to below code, then It'll start placing elements from right side (end).
mainAxisAlignment: MainAxisAlignment.end,
You can also check below screenshots for results that I'm getting with above code.
This is simply because of the Default Leading applied to The app bar as you navigate from the other page and somehow that leading icon is in white color.
If you enable the Show Boundaries in the Dev tools you can see the Default leading icon is taking that blank spot.
There are two possible outcomes to this problem.
You can change the color to any visible color.
- This will help the user to navigate back.
You can try to set the "automaticallyImplyLeading" property to "false" in the "Appbar" Widget.
- This will disable the default leading icon in the Appbar.
Try below code hope its help to you. just change your widgets inside action tag(like your image)
Scaffold(
appBar: AppBar(
title:Image.network(
'https://image.shutterstock.com/image-photo/kiev-ukraine-may-03-2015-260nw-275974145.jpg',
),
automaticallyImplyLeading:false,
actions: <Widget>[
Icon(Icons.add),
Icon(Icons.person),
],
),
)
Your Result Screen->
Yes, got the answer from one of the comment.
automaticallyImplyLeading:false.
This fixed the issue

Flutter RaisedButton Hightlightelevation delay

I have created the following RaisedButton in Flutter:
The problem is, the button's highlightElevation triggers when you press and hold the button for approximately 1 second when I have the image shown on the left of it, but when I remove the image, it works as intended.
Is there a way to fix this while keeping the image?
here is my code:
Widget systems(String systemName, String systemTitle, Image img) {
return Center(child:
Container( width:width-20,height:110,child:
Column( children: <Widget>[
SizedBox(height: 10),
RaisedButton( elevation: 10,splashColor: Colors.transparent,highlightElevation: 0, shape:
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
color: Colors.white,
onPressed: () {},
child: Padding(
padding: EdgeInsets.only(left:0,top:15,bottom:15),
child: Row(children: [
img,Container(width:width-120,child:
Align(
alignment: Alignment.center,
child: Column(
children: [
Text(systemName, style: TextStyle(fontSize: 18)),
],
),
),)
])))
])));
}
PS: I have called this widget 9 times within a for loop in another widget, and when I reduce the number of the loop to 5 or lower, the button works as intended as well.
According to Flutter SDK highlightElevation is for the button's Material when the button is enabled and pressed.
Please refer https://api.flutter.dev/flutter/material/RawMaterialButton/highlightElevation.html
highlightElevation property :
The elevation for the button's Material when the button is enabled and pressed.

flutter - how to align at the top and at the bottom (this is the issue) - and column middle part

I would like to align a container at the bottom of the widget (given there is containers already at the top and some column in the middle)
So far I can align in at the top followed by some containers using Alignment.topCenter and column.
body: Align(
alignment: Alignment.topCenter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
How can I then put one more container that is right at the bottom of the widget.
reason for this is I want the ad banner to appear at the top and at the bottom. the middle is the real content.
Add Column on top on Align Widget, & add at the bottom of its container with Expanded
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 100, // Give height of banner
color: Colors.green,
),
),
),

Alignment on y-axis doesn't respond flutter

I want a CircleAvatar over an Image so I created a stack, its children are an Image and an Align (CircleAvatar inside).
All seems works but I can't move the CircleAvatar on the y-axis, only on the x-axis and I really need to move it on the y-axis.
Code :
body: new Stack(
children: <Widget>[
new ListView(
children: <Widget>[
new Stack(
children: <Widget>[
new Image.asset('assets/images/io.png',
fit : BoxFit.contain,
),
new Align(
alignment: Alignment(0,0),
child: new CircleAvatar(
minRadius: 50,
maxRadius: 50,
child : ClipRRect(
borderRadius: new BorderRadius.circular(50),
child : _profPicture == null
? new Image.asset('assets/images/empty_profile.jpg')
: _profPicture,
),
),
),
],
),
],
),
],
),
If I change the values inside "Alignment" I can move only the avatar from the left to the right, top-bottom doesn't work.
Instead of Align Widget, you should use Positioned Widget
Positioned(
top: 30,
right: 30,
child: new CircleAvatar(.....)
I had the same issue. Solved by specifying child container height and width that need to be aligned. The problem was I only specified width. So height matched to the parent. So no movement on y axis