Using Positioned inside Stack is not working properly - flutter

I am using a Stack which has Card and Positioned Elements as can be seen in the below image. These Positioned Elements contains the buttons. The issue I am facing is that the lower part of these buttons are hidden.
Also I have not given any extra margin. It might be because of Bottom Navigation Part.
image
This is the code
Stack(
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 40.0, horizontal: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Container(
width: size.width * 0.2,
child: StreamBuilder<String>(
stream: bloc.skills,
builder: (context, snapshot) {
return TextField(
onChanged: bloc.changeSkills,
decoration: new InputDecoration(
contentPadding:
EdgeInsets.symmetric(
vertical: 0,
horizontal: 15.0),
border: new OutlineInputBorder(
borderSide:
const BorderSide(
width: 2.0,
style:
BorderStyle
.solid),
borderRadius:
BorderRadius
.circular(
50.0)),
focusedBorder:
OutlineInputBorder(
borderSide:
const BorderSide(
color:
Colors.grey,
width: 2.0),
borderRadius:
BorderRadius.circular(
50.0),
),
hintText: 'Skills',
hintStyle: new TextStyle(
color: Colors.grey,
fontWeight:
FontWeight.bold),
errorText: snapshot.error),
);
}),
),
SizedBox(height: 20.0),
Container(
width: size.width * 0.2,
child: StreamBuilder<String>(
stream: bloc.role,
builder: (context, snapshot) {
return TextField(
onChanged: bloc.changeRole,
decoration: new InputDecoration(
contentPadding:
EdgeInsets.symmetric(
vertical: 0,
horizontal: 15.0),
border: new OutlineInputBorder(
borderSide:
const BorderSide(
width: 2.0,
style:
BorderStyle
.solid),
borderRadius:
BorderRadius
.circular(
50.0)),
focusedBorder:
OutlineInputBorder(
borderSide:
const BorderSide(
color:
Colors.grey,
width: 2.0),
borderRadius:
BorderRadius.circular(
50.0),
),
hintText: 'Role',
hintStyle: new TextStyle(
color: Colors.grey,
fontWeight:
FontWeight.bold),
errorText: snapshot.error),
);
}),
),
],
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
width: size.width * 0.2,
child: StreamBuilder<String>(
stream: bloc.language,
builder: (context, snapshot) {
return TextField(
onChanged: bloc.changeLanguage,
decoration: new InputDecoration(
contentPadding:
EdgeInsets.symmetric(
vertical: 0,
horizontal: 15.0),
border: new OutlineInputBorder(
borderSide:
const BorderSide(
width: 2.0,
style:
BorderStyle
.solid),
borderRadius:
BorderRadius
.circular(
50.0)),
focusedBorder:
OutlineInputBorder(
borderSide:
const BorderSide(
color:
Colors.grey,
width: 2.0),
borderRadius:
BorderRadius.circular(
50.0),
),
hintText: 'Language',
hintStyle: new TextStyle(
color: Colors.grey,
fontWeight:
FontWeight.bold),
errorText: snapshot.error),
);
}),
),
SizedBox(height: 20.0),
Container(
width: size.width * 0.2,
child: StreamBuilder<String>(
stream: bloc.gender,
builder: (context, snapshot) {
return DropdownButtonHideUnderline(
child:
new DropdownButtonFormField<
String>(
items: <String>[
'Female',
'Male',
'Other'
].map((String value) {
return new DropdownMenuItem<
String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: bloc.changeGender,
decoration:
new InputDecoration(
contentPadding:
EdgeInsets
.symmetric(
vertical:
0,
horizontal:
15.0),
border: new OutlineInputBorder(
borderSide:
const BorderSide(
width:
2.0,
style: BorderStyle
.solid),
borderRadius:
BorderRadius
.circular(
50.0)),
focusedBorder:
OutlineInputBorder(
borderSide:
const BorderSide(
color: Colors
.grey,
width: 2.0),
borderRadius:
BorderRadius
.circular(
50.0),
),
hintText: 'Gender',
hintStyle:
new TextStyle(
color: Colors
.grey,
fontWeight:
FontWeight
.bold),
errorText:
snapshot.error),
),
);
}),
)
],
),
),
],
),
),
),
Positioned(
left: size.width * 0.02,
top: size.height * 0.58 + 2,
child: new Container(
width: 100.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0),
color: Colors.white,
border: Border.all(
width: 2.0, color: Colors.grey)),
child: Align(
alignment: Alignment.center,
child: new Text(
'Back',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold),
),
),
)),
Positioned(
right: size.width * 0.02,
top: size.height * 0.58 + 2,
child: new Container(
width: 100.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0),
color: primaryColor,
// border: Border.all(width: 2.0, color: Colors.grey)
),
child: Align(
alignment: Alignment.center,
child: new Text(
'Create',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
)),
],
),

Add overflow: Overflow.visible, to the Stack

Related

FLUTTER UI Config widget row with 2 dropdown

I have problem with UI in flutter. Anyone have experienced in widget please help me.
Firstly, here's the target from figma :
both date and time is using dropdown.
This is what it become after my code :
This is my code :
Container(
alignment: Alignment.centerLeft,
child: Text('Schedule',
style: TextStyle(
color: Color.fromRGBO(78, 125, 150, 1),
fontSize: 12,
fontWeight: FontWeight.w600
))),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 40,
width: MediaQuery.of(context).size.shortestSide * 0.5,
color: Colors.white,
child: DropdownButtonFormField(
onChanged: (value) {},
items: _dropdownDate.map((value) =>
DropdownMenuItem(
child: Text(value),
value: value,
)).toList(),
elevation: 4,
dropdownColor: Colors.white,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.calendar_month, size: 16),
hintText: 'Select Date',
hintStyle: TextStyle(fontSize: 12),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
contentPadding: const EdgeInsets.all(16),
fillColor: Colors.white
),
),
),
Container(
height: 40,
width: MediaQuery.of(context).size.shortestSide * 0.3,
color: Colors.white,
child: DropdownButtonFormField(
onChanged: (value) {},
items: _dropdownTime.map((value) =>
DropdownMenuItem(
child: Text(value),
value: value,
)).toList(),
elevation: 4,
dropdownColor: Colors.white,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.watch_later_outlined, size: 16),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
contentPadding: const EdgeInsets.all(16),
fillColor: Colors.white
),
),
),
],
),
I want to make the size in the row like this :
50% dropdown Date,
20% space,
30% dropdown Time
and the problem are :
I don't know how to configure it as a percentage of row space, not with MediaQuery.of(context).size.width because I already use margin.
How to made the percentage is auto fit no matter device the user will used.
Hope to solved this here, thank you before~
Update, after using layout builder :
You should use the LayoutBuilder for that instead of MediaQuery. It's going to give you the available space inside the wrapped widget.
The code changes are below. This is the result:
child: LayoutBuilder(
builder: (context, constraints) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
// height: 40,
width: constraints.maxWidth * 0.5,
color: Colors.white,
child: DropdownButtonFormField(
onChanged: (value) {},
items: _dropdownDate
.map((value) => DropdownMenuItem(
child: Text(value),
value: value,
))
.toList(),
elevation: 4,
dropdownColor: Colors.white,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.calendar_month, size: 16),
hintText: 'Select Date',
hintStyle: TextStyle(fontSize: 12),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
contentPadding: const EdgeInsets.all(16),
fillColor: Colors.white),
),
),
Container(
// height: 40,
width: constraints.maxWidth * 0.3,
color: Colors.white,
child: DropdownButtonFormField(
onChanged: (value) {},
items: _dropdownTime
.map((value) => DropdownMenuItem(
child: Text(value),
value: value,
))
.toList(),
elevation: 4,
dropdownColor: Colors.white,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.watch_later_outlined, size: 16),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
width: 0.8,
color: Colors.grey,
)),
contentPadding: const EdgeInsets.all(16),
fillColor: Colors.white),
),
),
],
);
}
),

Flutter screen overflow from bottom

I have a simple page in which I am using SingleChildScrollView to scroll the page so it will not show overflow and show the content of the bottom.
But it's showing an error also the page is not scrollable due to which I can't see the bottom 2 buttons
My code
SingleChildScrollView(
child: Container(
height: Height * 1,
child: Column(
children: <Widget>[
Container(
color: kPrimaryColor,
child: Column(
children: [
SizedBox(
height: Status * 1,
),
SizedBox(
height: Height * 0.065,
),
Padding(
padding: const EdgeInsets.only(left: 13, bottom: 13),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Create Account',
style: TextStyle(
color: Colors.white,
fontSize: 30,
fontFamily: 'SegoeUI-SemiBold'),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 13),
child: Text(
"Please create an account in order to start using your StalkMe Profile.",
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontFamily: 'SegoeUI'),
),
),
SizedBox(
height: Height * 0.04,
),
],
),
),
Expanded(
child: Container(
color: kPrimaryColor,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30))),
child: Form(
key: _formKey,
child: Column(
children: [
GestureDetector(
onTap: () {
print('Login print');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginScreen()),
);
},
child: Padding(
padding: const EdgeInsets.only(
top: 17, right: 17, bottom: 17),
child: Align(
alignment: Alignment.centerRight,
child: Text(
'LOGIN',
style: TextStyle(
color: kPrimaryColor,
fontSize: 16,
fontFamily: 'SegoeUI-SemiBold',
),
)),
),
),
Container(
height: 1,
width: double.infinity,
color: Color(0xffE6E6E6),
),
SizedBox(
height: Height * 0.03,
),
Container(
width: Width * 0.9,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Name',
style: TextStyle(
color: textGreyColor,
fontSize: 16,
fontFamily: 'SegoeUI'),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 11),
child: Container(
width: Width * 0.9,
child: TextFormField(
controller: userName,
validator: (value) {
if (value!.isEmpty) {
return 'Please enter a name';
}
return null;
},
style: TextStyle(
color: textGreyColor,
fontFamily: 'SegoeUI'),
decoration: new InputDecoration(
enabledBorder: new OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
),
filled: true,
hintStyle: new TextStyle(
color: textGreyColor, fontSize: 15),
hintText: "Enter Name",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
),
),
),
),
SizedBox(
height: Height * 0.02,
),
Container(
width: Width * 0.9,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Email Address',
style: TextStyle(
color: textGreyColor,
fontSize: 16,
fontFamily: 'SegoeUI'),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 11),
child: Container(
width: Width * 0.9,
child: TextFormField(
controller: userEmail,
validator: (value) {
if (value!.isEmpty || !value.contains('#')) {
return 'Please enter a valid email address';
}
return null;
},
style: TextStyle(
color: textGreyColor,
fontFamily: 'SegoeUI'),
decoration: new InputDecoration(
enabledBorder: new OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
),
filled: true,
hintStyle: new TextStyle(
color: textGreyColor, fontSize: 15),
hintText: "Enter Email Address",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
),
),
),
),
SizedBox(
height: Height * 0.02,
),
Container(
width: Width * 0.9,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Password',
style: TextStyle(
color: textGreyColor,
fontSize: 16,
fontFamily: 'SegoeUI'),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 11),
child: Container(
width: Width * 0.9,
child: TextFormField(
controller: userPassword,
validator: (value) {
if (value!.isEmpty || value.length < 6) {
return 'Please enter a 6 digit password';
}
return null;
},
obscureText: true,
key: ValueKey('name'),
style: TextStyle(
color: textGreyColor,
fontFamily: 'SegoeUI'),
decoration: new InputDecoration(
enabledBorder: new OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
),
filled: true,
hintStyle: new TextStyle(
color: textGreyColor, fontSize: 15),
hintText: "Enter Password",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Color(0xffE6E6E6), width: 1),
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
),
),
),
),
SizedBox(
height: Height * 0.02,
),
Spacer(),
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
width: Width * 0.9,
height: Height * 0.06,
decoration: BoxDecoration(
color: Color(0xffebf7f7),
borderRadius: BorderRadius.circular(5)),
child: Center(
child: Text(
'GO BACK',
style: TextStyle(
color: kPrimaryColor,
fontSize: 16,
fontFamily: 'SegoeUI'),
),
),
),
),
GestureDetector(
child: Padding(
padding:
const EdgeInsets.only(top: 8, bottom: 18),
child: Container(
width: Width * 0.9,
height: Height * 0.06,
decoration: BoxDecoration(
color: kPrimaryColor,
borderRadius: BorderRadius.circular(5)),
child: Center(
child: Text(
'CREATE ACCOUNT',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontFamily: 'SegoeUI'),
),
),
),
),
),
],
),
),
),
),
),
],
),
),
),
On small devices, it's not scrollable I try everything to try to give full height but now nothing works for me.
Try putting the Column directly below the SingleChildScrollView.
Like this:
SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
color: kPrimaryColor,
height: Height * 1, // if its still needed
child: Column(
Remove the first container(Wrapped by SingleChildScrollView with height, "height: Height * 1")
Remove the Expanded widget.
Give required size to enbounded Container(
Container with color: kPrimaryColor,)

Flutter search on listView with multiple values

I need to simply implement a search with multiple values on ListView. It's working fine with a single value I am stuck on how can I use this for multiple values.
My code
Padding(
padding: const EdgeInsets.only(top: 11),
child: Container(
width: Width * 0.9,
child: TextFormField(
onChanged: (value) {
setState(() {
searchString = value;
});
},
decoration: new InputDecoration(
suffixIcon: Padding(
padding: const EdgeInsets.all(5.0),
child: ClipOval(
child: Material(
color: Color(0xffdee8ec), // Button color
child: InkWell(
splashColor: Colors.red, // Splash color
onTap: () {},
child: Icon(
Icons.search_outlined,
color: kPrimaryColor,
size: 20,
),
),
),
),
),
labelText: "Search",
labelStyle:
TextStyle(color: textGreyColor, fontFamily: 'SegoeUI'),
filled: true,
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderRadius: new BorderRadius.circular(10),
borderSide: BorderSide(color: kPrimaryColor, width: 1.0),
),
enabledBorder: OutlineInputBorder(
borderRadius: new BorderRadius.circular(10),
borderSide:
BorderSide(color: Color(0xffE6E6E6), width: 1.0),
),
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(10),
borderSide: new BorderSide(color: Color(0xffE6E6E6)),
),
//fillColor: Colors.green
),
keyboardType: TextInputType.emailAddress,
style: new TextStyle(
fontFamily: "SegoeUI", color: kPrimaryColor),
),
),
),
Container(
width: Width * 0.9,
child: ListView.builder(
padding: EdgeInsets.only(top: 10),
itemCount: _serviceList.length,
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: ScrollPhysics(),
itemBuilder: (context, index) {
return _serviceList[index]['serviceName']
.toString()
.contains(searchString)
? Padding(
padding: const EdgeInsets.only(bottom: 7),
child: Container(
width: Width * 0.9,
child: Card(
elevation: 2,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'${_serviceList[index]['serviceName']} ',
style: TextStyle(
fontFamily: 'SegoeUI',
color: kPrimaryColor,
fontSize: 15),
),
SizedBox(
height: 5,
),
Text(
'${_serviceList[index]['serviceDuration']}',
style: TextStyle(
fontFamily: 'SegoeUI',
color: textGreyColor,
fontSize: 15),
)
],
),
],
)),
),
),
)
: Container();
},
),
)
You can see it's now searching with ServiceName only I need to use it for multiple values and have no idea how can I do this or I need to change the way I am doing this
You could continue the way you are doing itself. Setup multiple input fields as required and get the value to be searched and include it along with this particular part as conditions:
return _serviceList[index]['serviceName']
.toString()
.contains(searchString)
?
I guess it would be easier and successful. Do comment if you need future clarifications.

How to style this kind of Text Field

I want to style this kind of TextField.
The main problem that I'm facing is to design the US$ part in leading the TextField. This is my code so far.
/// My Place Bid Text Field
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
labelText: "Place Bid",
labelStyle: TextStyle(fontSize: 24)),
),
),
],
),
),
Which gives me output
I know this question is not that complicated, but I'm still relatively new to flutter so your help would be much appreciated.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample"),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey[500],
),
borderRadius: BorderRadius.all(Radius.circular(8))),
width: double.infinity,
height: 50,
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
color: Colors.grey.shade300,
height: 50,
child: Align(
alignment: Alignment.center,
child: Text(
"RS \u20B9",
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
)),
SizedBox(
width: 10,
),
Expanded(
child: Container(
height: 50,
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Bid",
labelStyle: TextStyle(fontSize: 24)),
)))
],
),
),
));
}
Output
You can use the prefixIcon to add a widget at the beginning of the textfield:
Container(
child: Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsetsDirectional.only(start: 2.0),
child: Container(
padding: const EdgeInsets.all(13),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
border: const OutlineInputBorder(),
labelText: 'Hint Text',
),
),
),
],
),
)
example:
https://dartpad.dev/a89aff20d67e2cb31da6a07ba7c17910
Based on your solution.
Notice the "IntrinsicHeight" widget. It makes all the children inside the child the same size (depending on the biggest one). The "Center" widget inside the prefix makes the Container go max height + center the text inside of it. Just make sure not to use IntrinsicHeight too much, since the docs state that it's a bit resource heavy.
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
border: InputBorder.none,
labelText: "Place Bid",
),
),
),
],
),
),
),
The second code is almost the same, except there's no label after typing the text inside the TextField.
Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
border: InputBorder.none,
hintText: "Place Bid",
),
),
),
],
),
),
),
Container(
decoration: BoxDecoration(
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
border:Border.all(color:Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft:Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: new OutlineInputBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(4),
bottomRight:
Radius.circular(4),
),
),
isDense: true,
labelText: "Place Bid",
labelStyle:
TextStyle(fontSize:24)),
),
),
],
),
),

Flutter Navigation undefined "context"

I´m new to flutter and dart and I´m trying to build a Sign up for an app.
I got a start screen (StartPage) with options "login", "login FB", "sign up with email".
When I hit "login" I can navigate to the signup_email_screen. From there I want to navigate to the signup_email_screen_two but it throws "undefined name context".
class StartPage extends StatefulWidget {
#override
_StartPageState createState() => _StartPageState();
}
class _StartPageState extends State<StartPage> {
bool isAuth = false; //isAuth provides a bool if the user is already signed in
Widget buildAuthScreen() {
return Text('Angemeldet');
}
Scaffold buildUnAuthScreen() {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/tenor.gif'),
fit: BoxFit.cover)),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: SizeConfig.blockSizeVertical * 10),
Container(
width: SizeConfig.blockSizeHorizontal * 65,
height: SizeConfig.blockSizeVertical * 20,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Insta_transparent.png'),
fit: BoxFit.scaleDown,
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 0),
Text(
'Nie mehr Langeweile',
style: TextStyle(
fontFamily: "Signatra",
fontSize: SizeConfig.blockSizeHorizontal *8,
color: Colors.white,
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 7),
GestureDetector(
onTap: () => _navigateToLogin(context),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button.png'),
fit: BoxFit.scaleDown,
),
),
)),
SizedBox(height: SizeConfig.blockSizeVertical * 2),
GestureDetector(
onTap: () => print('facebook signin'),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button_FB.png'),
fit: BoxFit.scaleDown,
),
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 2),
GestureDetector(
onTap: () => _navigateToEmailRegister(context),
child: Container(
width: SizeConfig.blockSizeHorizontal * 60,
height: SizeConfig.blockSizeVertical *7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/button-email-registration.png'),
fit: BoxFit.scaleDown,
),
),
),
),
],
),
),
);
}
void _navigateToLogin(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginScreen(),
));
}
void _navigateToEmailRegister(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignupEmailScreen(),
));
}
#override
Widget build(BuildContext context) {
SizeConfig().init(context);
return isAuth ? buildAuthScreen() : buildUnAuthScreen();
}
}
class SignupEmailScreen extends StatelessWidget {
Scaffold signupEmailScreen() {
return Scaffold(
body: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/StartPage_Background.jpg'),
fit: BoxFit.cover)),
alignment: Alignment.center,
),
//AppBar transparent and background full screen with Stack and Positioned
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
title: Text('Registrierung'),
backgroundColor: Colors.transparent, //transparent
elevation: 0.0, //Shadow gone
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(height: SizeConfig.blockSizeVertical * 15),
//Insta image
Container(
width: SizeConfig.blockSizeHorizontal * 50,
height: SizeConfig.blockSizeVertical * 10,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Insta_transparent.png'),
fit: BoxFit.scaleDown,
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 7),
//Email text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.text,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Accountname",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
//Password text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Email",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.visiblePassword,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Passwort",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.visiblePassword,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Passwort wiederholen",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 10),
//log in button
GestureDetector(
onTap: () => _navigateToSignupEmailScreenTwo(context),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button.png'),
fit: BoxFit.scaleDown,
),
),
)),
],
),
],
),
);
}
//ACTIONS
void _navigateToSignupEmailScreenTwo(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignupEmailScreenTwo(),
));
}
//BUILD
#override
Widget build(BuildContext context) {
return signupEmailScreen();
}
}
class SignupEmailScreenTwo extends StatelessWidget {
Scaffold signupEmailScreenTwo() {
return Scaffold(
body: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/StartPage_Background.jpg'),
fit: BoxFit.cover)),
alignment: Alignment.center,
),
//AppBar transparent and background full screen with Stack and Positioned
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
title: Text('Registrierung'),
backgroundColor: Colors.transparent, //transparent
elevation: 0.0, //Shadow gone
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(height: SizeConfig.blockSizeVertical * 15),
Container(
width: SizeConfig.blockSizeHorizontal * 50,
height: SizeConfig.blockSizeVertical * 10,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Insta_transparent.png'),
fit: BoxFit.scaleDown,
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 7),
//Email text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.text,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Dein Vorname",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
//Password text field
Padding(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.safeBlockHorizontal * 5),
child: TextField(
keyboardType: TextInputType.datetime,
style: TextStyle(color: Colors.white, fontSize: 20.0),
decoration: InputDecoration(
labelText: "Dein Geburtsdatum",
labelStyle: TextStyle(
color: Colors.white,
),
hasFloatingPlaceholder: true,
enabledBorder: UnderlineInputBorder(
//Enables the border to change color
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.white, width: 2.0)),
),
),
),
SizedBox(height: SizeConfig.blockSizeVertical * 10),
//log in button
GestureDetector(
onTap: () => print("Einlogggggeeeeeen"),
child: Container(
width: SizeConfig.blockSizeHorizontal * 70,
height: SizeConfig.blockSizeVertical * 7,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Log_In_Button.png'),
fit: BoxFit.scaleDown,
),
),
)),
],
),
],
),
);
}
#override
Widget build(BuildContext context) {
return signupEmailScreenTwo();
}
}
Why is the context undefined?
Appreciate any help!
Because context undefined inside your function :)
**Edit: ** You cant reach context object inside StatelessWidget
These are what you can do:
1- Use StatefulWidget instead of StatelessWidget,
2- You can pass BuildContext context as a parameter into your functions.
3- You can write all widgets inside build method instead of extra function.