i'm using two buttons in my application which is been used inside a method separately.but i'm not able to given enough space between those two buttons,can someone look into it please.
here's my code:
child: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlutterLogo(size: 150),
SizedBox(height: 50),
_signInButton(),
_signInFbButton()
],
),
),
),
);
}
Widget _signInButton() {
return Container(
child: OutlineButton(
splashColor: Colors.grey,
onPressed: () {
signInWithGoogle().whenComplete(() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return FirstScreen();
},
),
);
});
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
highlightElevation: 0,
borderSide: BorderSide(color: Colors.grey),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage("Assets/google_logo.png"), height: 35.0),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
'Sign in with Google',
style: TextStyle(
fontSize: 20,
color: Colors.grey,
}
Widget _signInFbButton() {
return Container(
child: OutlineButton(
splashColor: Colors.grey,
onPressed: () {
signInWithGoogle().whenComplete(() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return FirstScreen();
},
),
);
});
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
highlightElevation: 0,
borderSide: BorderSide(color: Colors.grey),
child: Container(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage("Assets/facebook-logo.png"), height: 35.0),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
'Sign in with Google',
style: TextStyle(
fontSize: 20,
color: Colors.grey,
Here's my screenshot of what im trying to do i'm creating a sign in page using google sign-in and facebook sign-in
Why don't you try what you have already? the SizedBox to achieve that,
_signInButton(),
SizedBox(height: 16),//<----
_signInFbButton()
You can wrap _signInFbButton() widget with Padding and provide top padding per your requirement. Working code below:
_signInButton(),
Padding(
padding: EdgeInsets.only(top: 5),
child: _signInFbButton())
Hope this answers your question.
Related
I know the question is simple but I am in doubt about creating a simple button, which directs to the initial page of user registration.
I'm inserting the code below, there are no errors but when compiling nothing appears, I have already tested it by changing other elements and they update but the new button created does not appear on the screen.
New Button:
Container(
height: 30,
alignment: Alignment.center,
child: SizedBox.expand(
child: TextButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Cadastre-se", style: TextStyle(color: Colors.black))
],
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return RegisterName();
},
),
);
})));
Current Code:
final button = Container(
height: 50,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFF18A00),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(8), bottomLeft: Radius.circular(8)),
),
child: SizedBox.expand(
child: TextButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Entrar", style: TextStyle(color: Color(0xFFFFFFFF)))
],
),
onPressed: _submitEmail)));
final forgotPassword = Container(
height: 40,
alignment: Alignment.center,
//child: FlatButton(
//style: TextStyle(color: Color(0xFF45CAD0))),
// onPressed: () => {},
);
return Scaffold(
backgroundColor: Color.fromRGBO(248, 248, 248, 1),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ListView(
//physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: EdgeInsets.only(left: 70, right: 70),
children: <Widget>[
logo,
SizedBox(height: 30),
email,
password,
button,
SizedBox(height: 20),
forgotPassword,
],
),
],
),
);
}
}
I tried to insert below the "Enter" button and nothing happened.
Where am I going wrong?
If I understand correctly, you want to figure out where to place the code for "New Button". In that case, assign your new button container to a variable like this:
final newButton = Container(
height: 30,
alignment: Alignment.center,
child: SizedBox.expand(
child: TextButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Cadastre-se", style: TextStyle(color: Colors.black))
],
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return RegisterName();
},
),
);
})));
Then, in your Current Code, you can put this variable inside the ListView like the other variables:
return Scaffold(
backgroundColor: Color.fromRGBO(248, 248, 248, 1),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ListView(
//physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: EdgeInsets.only(left: 70, right: 70),
children: <Widget>[
logo,
SizedBox(height: 30),
email,
password,
button,
newButton,
SizedBox(height: 20),
forgotPassword,
],
),
],
),
);
So your final "Current Code" will be:
final button = Container(
height: 50,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFF18A00),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(8), bottomLeft: Radius.circular(8)),
),
child: SizedBox.expand(
child: TextButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Entrar", style: TextStyle(color: Color(0xFFFFFFFF)))
],
),
onPressed: _submitEmail)));
final newButton = Container(
height: 30,
alignment: Alignment.center,
child: SizedBox.expand(
child: TextButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Cadastre-se", style: TextStyle(color: Colors.black))
],
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return RegisterName();
},
),
);
})));
final forgotPassword = Container(
height: 40,
alignment: Alignment.center,
//child: FlatButton(
//style: TextStyle(color: Color(0xFF45CAD0))),
// onPressed: () => {},
);
return Scaffold(
backgroundColor: Color.fromRGBO(248, 248, 248, 1),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ListView(
//physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: EdgeInsets.only(left: 70, right: 70),
children: <Widget>[
logo,
SizedBox(height: 30),
email,
password,
button,
newButton,
SizedBox(height: 20),
forgotPassword,
],
),
],
),
);
replace the Column with Center(child:... and give your scaffold background static color
I've got an issue with the button on the right... The round green one has some kind of vertical margin (in yellow) and I don't know how to get rid of it and its making me crazy !
I would like it to be like the RaisedButton on the left.
This is the code that creates this :
Widget myWidget() {
return Row (
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
color: Colors.red,
child:
RaisedButton(
color: Colors.red,
onPressed: () {},
child: Container(child: Text("+")),
)),
Container(
color: Colors.yellow,
child:ClipOval(
child: Container(
child:InkWell(
onTap: () {
setState((){
});
},
child: myButton("+")
)
)
),
),
And the myButton widget :
Widget myButton(text) {
return new Container(
margin: EdgeInsets.only(left: 20.0, right: 20.0, top: 0, bottom: 0), //horizontal margin works but vertical margin is not impacted by whatever I put here
padding: EdgeInsets.all(20),
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.green,
),
child: new Text(text,
style: new TextStyle(
color: Colors.white,
fontSize:
50.0)),
);
}
The parent widget :
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: [
Align(...),
Align(...)
]
),
Expanded(
child: Card(
child: InputControlParent(),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
myWidget() #<= child presented above
],
)
],
);
Parent code.
Widget myWidget() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
color: Colors.red,
child: RaisedButton(
color: Colors.red,
onPressed: () {},
child: Container(child: Text("+")),
)),
Container(
height: 100,//i put height
width: 100,// i put weidth
color: Colors.yellow,
child: InkWell(
onTap: () {
setState(() {});
},
child: myButton("+")),
),
])
myButton widget :
Widget myButton(text) {//remove the margin that not needed
return new Container(
padding: EdgeInsets.all(20),
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.green,
),
child: Center(
child: new Text(text,
style: new TextStyle(color: Colors.white, fontSize: 50.0)),
),
);
}
i have three buttons in my login page each of them are a different type of login options when i type in bigger texts in one button that itself is changing how can i keep everything constant.can someone look into it please.
Here's my code:
child: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlutterLogo(size: 150),
SizedBox(height: 50),
_signInButton(),
_signInFbButton()
],
),
),
),
);
}
Widget _signInButton() {
return Container(
child: OutlineButton(
splashColor: Colors.grey,
onPressed: () {
signInWithGoogle().whenComplete(() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return FirstScreen();
},
),
);
});
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
highlightElevation: 0,
borderSide: BorderSide(color: Colors.grey),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage("Assets/google_logo.png"), height: 35.0),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
'Sign in with Google',
style: TextStyle(
fontSize: 20,
color: Colors.grey,
}
Widget _signInFbButton() {
return Container(
child: OutlineButton(
splashColor: Colors.grey,
onPressed: () {
signInWithGoogle().whenComplete(() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return FirstScreen();
},
),
);
});
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
highlightElevation: 0,
borderSide: BorderSide(color: Colors.grey),
child: Container(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage("Assets/facebook-logo.png"), height: 35.0),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
'Sign in with Google',
style: TextStyle(
fontSize: 20,
color: Colors.grey,
here's the screen shot of how many buttons are arranged i want to have all the buttons constant and texts inside it formatted properly:
You don't need the column I think. So, I removed that. Here is the way you can create custom button with size. Feel free to change minWidth to get the best result.
new: Please consider using Flexible and Expanded inside the row. If the button text goes in multi-line please reduce the font size to fix it.
Widget _signInButton() {
return ButtonTheme(
minWidth: 400.0,
padding: EdgeInsets.all(10),
child: OutlineButton(
splashColor: Colors.grey,
onPressed: () {},
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
highlightElevation: 0,
borderSide: BorderSide(color: Colors.grey),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
flex: 1,
child: Image.network(
'https://picsum.photos/250?image=9',
height: 35,
),
),
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: Text('Sign in with Facebook',
style: TextStyle(
fontSize: 20, color: Colors.grey))),
)
])
),
);
}
Need to help to copy the layout on image below.
2 buttons with 50% width and padding/spacing in between.
I'm thinking also of using toggle button widget on it.
see my draft code below.
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
children: <Widget>[
Container(
color: Colors.green,
width: (MediaQuery.of(context).size.width) / 2.5,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
MdiIcons.account,
size: 18.0,
),
SizedBox(
width: 4.0,
),
Text(
"Client",
style: TextStyle(fontSize: 16),
)
],
)),
Container(
color: Colors.green,
width: (MediaQuery.of(context).size.width) / 2.5,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
MdiIcons.accountTie,
size: 18.0,
),
SizedBox(
width: 4.0,
),
Text(
"Host",
style: TextStyle(fontSize: 16),
)
],
)),
],
),
),
You can customize it,
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
children: <Widget>[
Expanded(
child: RaisedButton(
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
elevation: 1.5,
color: Colors.white,
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.developer_board),
SizedBox(height: 10),
Text("Experiences"),
],
),
),
),
SizedBox(width: 24),
Expanded(
child: RaisedButton(
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
elevation: 1.5,
color: Colors.white,
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.event),
SizedBox(height: 10),
Text("Events"),
],
),
),
),
],
),
),
the Row in my container contains padding on the left(I think). I want to align with the other children in the Column. I've been playing around with padding for the last two hours and find out how to eliminate the padding...
The sign in should align vertically from the left with buttons above it
#override
Widget build(BuildContext context) {
return SafeArea(
child: Container(
height: MediaQuery.of(context).size.height,
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/img/signin.png'),
fit: BoxFit.cover,
),
),
),
Container(
padding: EdgeInsets.only(top: 100),
child: Opacity(
opacity: _showProgressIndicator ? 1 : 0,
child: CircularProgressIndicator(),
),
),
Container(
// height: MediaQuery.of(context).size.height - 180,
padding:
EdgeInsets.only(top: 20, left: 10, right: 10, bottom: 60),
child: Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
verticalDirection: VerticalDirection.up,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
new FlatButton(
padding: EdgeInsets.zero,
child: new Text('SIGN IN',
style: Theme.of(context).textTheme.body1),
onPressed: () {
Navigator.push(
context, SignInPage(widget.onSignedIn));
},
),
Opacity(
opacity: _showMessage ? 1 : 0,
child: Text('CONSIDER GOOGLE', style:Theme.of(context).textTheme.body1)),
new FlatButton(
padding: new EdgeInsets.all(0.0),
child: new Text(
'SIGN UP WITH EMAIL',
style: Theme.of(context).textTheme.body1,
),
onPressed: () {
Navigator.push(
context, SignUpPage(widget.onSignedIn));
},
),
]),
new Container(
// padding: EdgeInsets.all(10),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new RaisedButton(
color: Colors.blue[800],
padding: EdgeInsets.all(20),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(4))),
child: new Text('CONNECT WITH FACEBOOK',
style: new TextStyle(
fontSize: 16,
letterSpacing: 0.5,
color: Colors.white)),
onPressed: loginWithFb,
),
new SizedBox(height: 20),
new RaisedButton(
color: Colors.red,
padding: EdgeInsets.all(20),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(4))),
child: new Text('CONNECT WITH GOOGLE',
style: new TextStyle(
fontSize: 16,
letterSpacing: 0.5,
color: Colors.white)),
onPressed: loginWithGoogle,
),
],
),
),
],
),
))
],
),
),
);
}
I could fix this by changing the default ButtonTheme if I understand correctly what you mean, because you said:
The sign in should align vertically from the left with buttons above it
Don't you mean horizontally from the left, if that is the case try this:
Wrap the Flatbutton in a Theme with ThemeData and a new ButtonTheme, then change the padding and minWidth with your own(when I only changed the padding or width it didn't work).
This removes the default from the ButtonTheme
Example:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Theme(
data: ThemeData(buttonTheme: ButtonThemeData(minWidth: 20.0,padding: EdgeInsets.all(0.0))),
child: new FlatButton(
child: new Text('SIGN IN',
style: Theme.of(context).textTheme.body1),
onPressed: () {
},
),
),
Opacity(
opacity: true ? 1 : 0,
child: Text('CONSIDER GOOGLE', style:Theme.of(context).textTheme.body1)),
new FlatButton(
padding: new EdgeInsets.all(0.0),
child: new Text(
"SIGN UP WITH EMAIL ",
style: Theme.of(context).textTheme.body1,
),
onPressed: () {
},
),
]),
Result: