create button to direct to registration page does not appear - flutter

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

Related

how to add a close icon to a container flutter

How to add a close icon to a container flutter. Appreciate your help on this.
showDialogFunc(context, img, cal, index, id, cid, status) {
final Size = MediaQuery.of(context).size;
return showDialog(
context: context,
builder: (context) {
return Center(
child: Material(
type: MaterialType.transparency,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
// color: backgroundBlue,
gradient: boxGradient,
),
padding: const EdgeInsets.only(top: 5, bottom: 5),
width: 350,
height: 350,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.network(
img,
height: 250,
width: 250,
fit: BoxFit.contain,
),
],
),
),
),
),
);
},
);
}
You could use the AlertDialog widget and put the close button as part of the title by using a Column. You can place the close button in the top right corner using the alignment property in a Container and setting the titlePadding to zero.
Here is a very simple example:
void _showDialog() {
showDialog(
context: context,
builder: (context) => AlertDialog(
titlePadding: EdgeInsets.zero,
title: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
alignment: FractionalOffset.topRight,
child: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(Icons.clear),
),
),
const Text('Title'),
],
),
content: const Text('Message here'),
),
);
}
More info in Flutter docs:
AlertDialog
Alignment using FractionalOffset
You should have a look at the Stack widget. It lets you put more widgets, one over the others.
For instance:
Stack(
children: [
Align(
alignment: Alignment.topRight,
child: IconButton(
child: Icon(Icons.close),
onPressed: () => Navigator.of(context).pop()
)
),
Material(
//your code
),
]
)
Something like that should work
Please check the updated code as below with the output. If you want to make cancel button inside, change margin: const EdgeInsets.all(25)
showDialogFunc(context, img, cal, index, id, cid, status) {
return showDialog(
context: context,
builder: (context) {
return Center(
child: Material(
type: MaterialType.transparency,
child: Stack(
alignment: Alignment.topRight,
children: [
Container(
margin: const EdgeInsets.all(25),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.red,
// gradient: boxGradient,
),
padding: const EdgeInsets.only(top: 5, bottom: 5),
width: 350,
height: 350,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.network(
img,
height: 250,
width: 250,
fit: BoxFit.contain,
),
],
),
),
),
InkWell(
onTap: (){
//perform action here.
},
child: Icon(
Icons.cancel,
color: Colors.white,
size: 50,
))
],
),
),
);
},
);
}
code snippet :
Stack(
children: [
//your code,
Positioned(
right: 10,
top: 10,
child: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Align(
alignment: Alignment.topRight,
child: CircleAvatar(
key: const Key('closeIconKey'),
radius: 15,
backgroundColor: Colors.white,
child: Icon(
Icons.close,
color: Colors.red,
),
),
),
),
),
],
),

How Can i Stick a Login Screen?

I am new to flutter. And I'm gaining more and more knowledge in a flutter.
I make A login screen long before for my Project But Someone suggest that your login screen not be scrolled up words should stick in the same position.
Brief about my screen.--
I added singleChildScrollview.I want to stop scrolling
below is my login screen. dart
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
),
body: Center(
child: SingleChildScrollView(
child: Container(
color: Colors.white12,
child: Padding(
padding: const EdgeInsets.all(36.0),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 200,
child: Image.asset(
"assests/man.png",
fit: BoxFit.contain,
)),
SizedBox(height: 45),
emailField,
SizedBox(height: 25),
passwordField,
SizedBox(height: 35),
loginButton,
SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Don't have an account ? "),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
RegistrationScreen()));
// Navigator.push(context, MaterialPageRoute(builder:(context)=>HomeScreen()));
},
child: Text(
"SignUp",
style: TextStyle(
color: Colors.redAccent,
fontWeight: FontWeight.w600,
fontSize: 15,
),
),
)
],
),
],
),
),
),
),
),
),
);
Remove SingleChildScrollview
Like this
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
),
body: Center(
child: Container(
color: Colors.white12,
child: Padding(
padding: const EdgeInsets.all(36.0),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 200,
child: Image.asset(
"assests/man.png",
fit: BoxFit.contain,
)),
SizedBox(height: 45),
emailField,
SizedBox(height: 25),
passwordField,
SizedBox(height: 35),
loginButton,
SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Don't have an account ? "),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
RegistrationScreen()));
// Navigator.push(context, MaterialPageRoute(builder:(context)=>HomeScreen()));
},
child: Text(
"SignUp",
style: TextStyle(
color: Colors.redAccent,
fontWeight: FontWeight.w600,
fontSize: 15,
),
),
)
],
),
],
),
),
),
),
),
);
Add physics to SingleChildScrollView
return SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
// rest of the code here
);
Though i would not recommend it as if the screen size is small and if the keyboard opens up, a render overflow will occur.

How can i align evenly?

I am new in Flutter and trying to put SizedBox and container which had "validate" text EVENLY. But mainAxisAlignment after Column didn't work. There is still no space. Should i use sth else rather than mainAxis, could you please help me
body: SingleChildScrollView(
child: new Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
createPaymentPage(),
SizedBox(width:400,height:200, child: Image.network('https://www.vippng.com/png/detail/424-4249192_credit-card-design-and-collaterals-black-credit-card.png'),
),
new GestureDetector(
child: Container(
alignment: Alignment.center,
width: 150,
height: 40,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.amber,
),
child: Text(
' Validate',
style: TextStyle(fontSize: 20, color: Colors.white),
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MapScreen()),
);
},
),
],
),
),
);
}
}

Error displaying List view below container

I am trying to display Listview using Listview builder below the purple color(as seen in the image)container with the below code:
return Scaffold(
body: Column(
children: <Widget>[
Container(
height: 300,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(75.0)),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 200, 0),
child: Container(
padding: EdgeInsets.fromLTRB(0, 30,200,0),
child: IconButton(icon: Icon(Icons.arrow_back,),
color: Colors.black,
onPressed: () {
Navigator.pop(context);
},
),
),
),
SizedBox(height: 20,),
Text('Semester 1',
style: TextStyle(color: Colors.white,
fontSize: 30),
)
],
)
),
Container(
child: ListView.builder(
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return new Container(
child: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Card(
child: new Container(
child: new Text("hello"),
padding: const EdgeInsets.all(20),
))
],
)));
}),
)
],
),
);
It returns a blank screen after running the code,without showing any error. I am not able to figure out the problem.
Please help!
If you use listview is small and inside Column then you should add
shrinkWrap: true in ListView
Column(
children: <Widget>[
ListView(
shrinkWrap: true, // use it
)
],
)
Or If your ListView Height is fix then use
Column(
children: <Widget>[
SizedBox(
height: 200, // constrain height
child: ListView(),
)
],
)
or If you want to fill all remaining space the use
Column(
children: <Widget>[
Expanded(
child: ListView(...),
)
],
)
Simply wrap the ListView in Expanded. The error here is that ListView doesn't know how to size itself (it has unbounded height from the Column). Using Expanded will tell it to fill up all the remaining space and fix the sizing problem
return Scaffold(
body: Column(
children: <Widget>[
Container(
height: 300,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(75.0)),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 200, 0),
child: Container(
padding: EdgeInsets.fromLTRB(0, 30,200,0),
child: IconButton(icon: Icon(Icons.arrow_back,),
color: Colors.black,
onPressed: () {
Navigator.pop(context);
},
),
),
),
SizedBox(height: 20,),
Text('Semester 1',
style: TextStyle(color: Colors.white,
fontSize: 30),
)
],
)
),
Container(
child: Expanded( // <-- wrap with expanded
child: ListView.builder(
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return new Container(
child: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Card(
child: new Container(
child: new Text("hello"),
padding: const EdgeInsets.all(20),
))
],
)));
}),
),
)
],
),
);
Error is caused by Container that is wrapping ListView. You need to specify bounds for that Container.
return Scaffold(
body: Column(
children: <Widget>[
Container(
height: 300,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(75.0)),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 200, 0),
child: Container(
padding: EdgeInsets.fromLTRB(0, 30, 200, 0),
child: IconButton(
icon: Icon(
Icons.arrow_back,
),
color: Colors.black,
onPressed: () {
Navigator.pop(context);
},
),
),
),
SizedBox(
height: 20,
),
Text(
'Semester 1',
style: TextStyle(color: Colors.white, fontSize: 30),
)
],
),
),
Container(
height: 300,
child: ListView.builder(
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Card(
child: Container(
child: Text("hello"),
padding: const EdgeInsets.all(20),
))
],
)));
}),
)
],
),
Above code should be working. Please note that, you don't need to specify "new" keyword in flutter.

How to change the size of button in flutter?

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))),
)
])
),
);
}