Flutter: How to move the modelBottomSheet up with the keyboard? - flutter

This is the screenshot of the screen. When the floatingActionButton is clicked, I'm presenting modekBottomSheet. The modelBottomSheet has 4 TextFields and 1 RaisedButton. I want the textField and raised button go up along with the keyboard. The RaisedButton bottom should be the top of the keyboard.
floatingActionButton: FloatingActionButton(
onPressed: () {
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return _showModelBottomSheetContent(context);
},
);
},
backgroundColor: Colors.blue,
child: Icon(
Icons.add,
size: 30,
),
),
Container _showModelBottomSheetContent(BuildContext context) {
return Container(
color: Color(0xFF737373),
height: 440,
child: Container(
padding: EdgeInsets.only(top: 20, left: 12, right: 12, bottom: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
"Add Customer",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
),
TextField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(
hintText: "Customer Name",
fillColor: Colors.white54,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(8.0),
borderSide: new BorderSide(),
),
),
),
TextField(
keyboardType: TextInputType.number,
style: TextStyle(fontSize: 18),
decoration: InputDecoration(
hintText: "Mobile No",
fillColor: Colors.white54,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(8.0),
borderSide: new BorderSide(),
),
),
),
TextField(
keyboardType: TextInputType.number,
style: TextStyle(fontSize: 18),
decoration: InputDecoration(
hintText: "Altername mobile no.",
fillColor: Colors.white54,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(8.0),
borderSide: new BorderSide(),
),
),
),
TextField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(
hintText: "Address",
fillColor: Colors.white54,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(8.0),
borderSide: new BorderSide(),
),
),
),
RaisedButton(
padding: EdgeInsets.only(top: 10, bottom: 10),
color: Colors.blue,
child: Text(
'ADD',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w700),
),
onPressed: handleAddCustomer,
),
SizedBox(
height: 20,
)
],
),
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(12),
topRight: const Radius.circular(12),
),
),
),
);
}

Related

Flutter make container transparent

Material(
elevation: 30.0,
shadowColor: Colors.grey,
child: Container(
width: 300,
child: SingleChildScrollView(
child: TextField(
controller: controller,
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'hinttText',
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: Colors.black,
width: 2.0,
),
),
),
......................................
......................................
......................................
How do I make my flutter container color to transparent.(only the container. Not Text Field)
Use Colors.transparent this sets it to transparent
Material(
elevation: 30.0,
shadowColor: Colors.grey,
child: Container(
width: 300,
color: Colors.transparent, //<------ this line
child: SingleChildScrollView(
child: TextField(
controller: controller,
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'hinttText',
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(
color: Colors.black,
width: 2.0,
),
),
)
)
)
)
)

how to create separate box for each category in flutter

I am creating a employee bio data page, for this i have 4 to 5 categories e.g. Personal data, family info, skills, employee history.
my output should be like this
for all categories, how i can create it in flutter.
i have done this
and want to convert it to like above design.
---------------EDITED QUESTION--------------------------------
I did the below code but it is not meeting my requirement.
Padding(padding: EdgeInsets.fromLTRB(15, 5,50, 0),
child:Container(decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent,width: 100)
),
child:Padding(padding: EdgeInsets.fromLTRB(15, 5,50, 0),
child: TextField(
decoration: InputDecoration(border: InputBorder.none),
),
))
here is its output
please help if anyone know the name of widget or how to create it.
You can get this layout by using Stack, Containers and Column
Stack(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(
vertical: 20, horizontal: 20),
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 2),
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextButton(
onPressed: () {},
child: Text(
'Submit',
style: TextStyle(
fontSize: 13,
),
),
style: ButtonStyle(
side: MaterialStateProperty.all(
BorderSide(
width: 2, color: Colors.black),
),
foregroundColor:
MaterialStateProperty.all(
Colors.black),
padding: MaterialStateProperty.all(
EdgeInsets.symmetric(
vertical: 2, horizontal: 30)),
textStyle: MaterialStateProperty.all(
TextStyle(fontSize: 30),
),
),
),
],
),
),
),
Positioned(
left: 30,
top: 10,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 3,
vertical: 2,
),
color: Colors.white,
child: Text(
'Personal Data',
style: TextStyle(
color: Colors.black, fontSize: 12),
),
),
),
],
),
bro take a container giver border to container like this
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent)
),
after that take inputfield and make this field border none like this
borde:InputBorder.none
so you can easily do that by this way

Flutter column not center in vertical

I need to center my column vertically i try with mainAxisAlignment and crossAxisAlignment but dont know why its not coming in center. Here is my code
return Container(
height: stackHeight * 0.4,
decoration: BoxDecoration(
color: Color(0xff404040),
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10, left: 10, right:10,
bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Would Question',
labelStyle: TextStyle(
color: Colors.blue
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
onSubmitted: (_) => _submitData(),
),
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Rather Question',
labelStyle: TextStyle(
color: Colors.red
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
keyboardType: TextInputType.number,
onSubmitted: (_) => _submitData(),
),
RaisedButton(onPressed: () {
_submitData();
}, child: Text('Add Question', style: TextStyle(
color: Colors.white
),),color: Theme.of(context).primaryColor,
),
],
),
),
],
),
),
);
Also, don't know on border-radius its showing white corners as you see in image emulator I need to remove this white also.
also, When i am opening the keyboard its cover the whole bottomsheet nothing is showing also the yellow line error showing is it possible when keyboard open the bottom shettup move on up side
You can give a transparent background so it will remove the white corners. Color.fromRGBO(255, 0, 0, 0.5)
Also can wrap center with Singlescroll widget. As mention in the above answer.
Wrap your SingleChildScrollView widget with Center widget. And for white corner you can wrap your main container with other container and set color: new Color.fromRGBO(255, 0, 0, 0.5),
Working Code here
return Container(
color: new Color.fromRGBO(255, 0, 0, 0.5),
child: Container(
height: stackHeight * 0.4,
decoration: BoxDecoration(
color: Color(0xff404040),
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
),
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10, left: 10, right:10,
bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Would Question',
labelStyle: TextStyle(
color: Colors.blue
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
onSubmitted: (_) => _submitData(),
),
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Rather Question',
labelStyle: TextStyle(
color: Colors.red
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
keyboardType: TextInputType.number,
onSubmitted: (_) => _submitData(),
),
RaisedButton(onPressed: () {
_submitData();
}, child: Text('Add Question', style: TextStyle(
color: Colors.white
),),color: Theme.of(context).primaryColor,
),
],
),
),
],
),
),
),
),
);
Use this
crossAxisAlignment: CrossAxisAlignment.center,
instead of this
crossAxisAlignment: CrossAxisAlignment.end,
SAMPLE CODE
return Container(
height: stackHeight * 0.4,
decoration: BoxDecoration(
color: Color(0xff404040),
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10, left: 10, right:10,
bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Would Question',
labelStyle: TextStyle(
color: Colors.blue
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
onSubmitted: (_) => _submitData(),
),
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Rather Question',
labelStyle: TextStyle(
color: Colors.red
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
keyboardType: TextInputType.number,
onSubmitted: (_) => _submitData(),
),
RaisedButton(onPressed: () {
_submitData();
}, child: Text('Add Question', style: TextStyle(
color: Colors.white
),),color: Theme.of(context).primaryColor,
),
],
),
),
],
),
),
);

Flutter| While keyboard pops up there will be BottomOverFlowed. Need exact design as shown in image

When keyboard pops up, there will be bottom over flowed. I need to add a expanded card as background for login form and submit button.
And also need that expanded card to move up when there is keyboard.
I have checked through many other solution for keyboard popup, but I couldn't get exact solution for mine design.
return new Scaffold(
body: new Column(children: <Widget>[
SizedBox(
height: 70,
),
new Image.asset(
'assets/logo.png',
fit: BoxFit.cover,
),
new Text(
"Login",
style: TextStyle(fontSize: 20, color: Colors.white),
),
new Text(
"It has noon , but also the Type roman, remaining essentially unchanged for the wish i could do.",
textAlign: TextAlign.center,
),
Column(
children: <Widget>[
Expanded(
child: Container(
child: Container(
padding: EdgeInsets.all(24),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(25.0),
topRight: const Radius.circular(25.0))),
child: new ListView(
children: <Widget>[
TextField(
style: new TextStyle(
color: Color(0xff651515),
),
autofocus: false,
obscureText: false,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "email",
hintText: "email",
labelStyle: TextStyle(
color: Color(0xffa4a4a4),
fontSize: 14,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 2,
color: Color(0xff55c882),
style: BorderStyle.solid),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Color(0xffa4a4a4),
),
),
),
),
SizedBox(
height: 20,
),
TextField(
style: new TextStyle(
color: Color(0xff651515),
),
autofocus: false,
obscureText: false,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "password",
hintText: "password",
labelStyle: TextStyle(
color: Color(0xffa4a4a4),
fontSize: 14,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 2,
color: Color(0xff55c882),
style: BorderStyle.solid),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Color(0xffa4a4a4),
),
),
),
),
],
),
),
))
],
)
]));
you can just wrap your column with a:
SingleChildScrollView(
child: put your column here
)
hope it helped

A RenderFlex overflowed by 147 pixels on the bottom

Here is the screenshot of the app I am trying to build.
The Date of birth field should show a calendar on click of it. Suppose I am in the email textformfield and the keyboard is open and now the user moves to date of birth field. As soon as user taps on date of birth field, I am removing the keyboard and showing the calendar, at that time I am getting exception saying A RenderFlex overflowed by 147 pixels on the bottom.
I have already gone through a bunch of stack questions on this and it mentioned to use a ListView, which I am using. Here is a snippet of my code.
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(20.0, 8.0, 40.0, 8.0),
child: InkWell(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: ListView(
children: <Widget>[
Image.asset(
"images/alphaurbanelogo.png",
width: 150.0,
height: 150.0,
),
Text("Sign Up",
style: TextStyle(
color: Colors.black,
fontFamily: "aktivgroteskBold",
fontSize: 25.0)),
SizedBox(
height: 5.0,
),
Text("Create an account to access\n TAUP system",
style: TextStyle(
color: Colors.black,
fontFamily: "aktivgroteskLight",
fontSize: 15.0)),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Color(0xFF5c2a7c)),
decoration: InputDecoration(
hintText: "First Name",
hintStyle: TextStyle(color: Color(0xFF5c2a7c)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF5c2a7c)))),
),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Color(0xFF5c2a7c)),
decoration: InputDecoration(
hintText: "Last Name",
hintStyle: TextStyle(color: Color(0xFF5c2a7c)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF5c2a7c)))),
),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Color(0xFF5c2a7c)),
decoration: InputDecoration(
hintText: "Email",
hintStyle: TextStyle(color: Color(0xFF5c2a7c)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF5c2a7c)))),
),
SizedBox(
height: 10.0,
),
InkWell(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
_selectDate(context);
},
child: Row(
children: <Widget>[
Flexible(
child: TextFormField(
style: TextStyle(
color: Color(0xFF5c2a7c), height: 2.0),
enabled: false,
controller: dobController,
decoration: InputDecoration.collapsed(
hintText: "Date of Birth",
hintStyle: TextStyle(color: Color(0xFF5c2a7c)),
)),
),
Icon(
Icons.email,
color: Color(0xFF5c2a7c),
),
],
),
),
Divider(
color: Color(0xFF5c2a7c),
height: 5.0,
),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Color(0xFF5c2a7c)),
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: "Contact Number",
hintStyle: TextStyle(color: Color(0xFF5c2a7c)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF5c2a7c)))),
),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Color(0xFF5c2a7c)),
decoration: InputDecoration(
hintText: "Parent Email",
hintStyle: TextStyle(color: Color(0xFF5c2a7c)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF5c2a7c)))),
),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Color(0xFF5c2a7c)),
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: "Parent Contact Number",
hintStyle: TextStyle(color: Color(0xFF5c2a7c)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF5c2a7c)))),
),
SizedBox(
height: 10.0,
),
DropdownButton<String>(
items: _schools.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(dropDownStringItem),
);
}).toList(),
hint: Text("School/Institution"),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemSelected = newValueSelected;
});
},
value: _currentItemSelected,
style: TextStyle(color: Color(0xFF5c2a7c), fontSize: 16.0),
),
SizedBox(
height: 1.0,
),
Divider(
color: Color(0xFF5c2a7c),
height: 5.0,
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Spacer(),
InkWell(
child: Image.asset(
"images/next.png",
width: 40.0,
height: 40.0,
),
onTap: () {},
)
],
)
],
),
),
)),
BottomBar()
],
),
);
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: new DateTime(1900),
lastDate: new DateTime(2100));
if (picked != null) {
var formatter = new DateFormat('yyyy-MM-dd');
choosenDate = formatter.format(picked);
dobController.text = choosenDate;
}
}
I am using a Form widget and its bottom was overflown, so similar problem. My solution was to apply a SingleChildScrollView widget. It was very convenient, as I was using a padding widget and this one has a padding property too. Just replaced it and perfect.
return Form(
key: _formKey,
autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: const EdgeInsets.all(10.0),
child: Column(
(...)
Source
If you're using a scaffold, type ResizetToAvoidBottomPadding: false.