Flutter Bottom Overflow on custom bottom sheet - flutter

You can see the problem here (I turned on flutter inspector gridlines so you can see the problem better)
Overflow disappears when I wrap my Container inside Expanded,
but then my search bar height is just stretching and it isn't good. Tried to use SingleChildScrollView but it didn't do the trick.
Container(
margin: const EdgeInsets.symmetric(
horizontal: AppConstants.bottomModalSheetSearchMarin,
vertical: AppConstants.bottomModalSheetSearchMarin),
decoration: BoxDecoration(
color: AppColors.searchBoxBackgroundColor,
borderRadius:
BorderRadius.circular(AppConstants.searchBoxRadius),
),
child: const TextField(
// onChanged: (value)=>controller.filterMountain(value),
decoration: InputDecoration(
hintStyle:
TextStyle(fontSize: AppFontSizes.searchBoxHintText),
hintText: 'Search',
suffixIcon: Icon(
Icons.search,
color: AppColors.searchBoxSearchIconColor,
),
border: InputBorder.none,
contentPadding:
EdgeInsets.all(AppPaddings.searchBoxPadding),
),
),
),
The problem is in the search bar container (we can see that from flutter inspector - show gridlines)
This is how it looks when I wrap Container with Expanded, (don't be bothered with the different look of the cards below)
Edit:
Here is the full bottomSheet code as requested:
bottomNavigationBar: SolidBottomSheet(
draggableBody: false,
headerBar: Container(
child: ClipRRect(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20)
),
child: OutlinedButton(
child: Column(
children: const [
Icon(Icons.expand_less,),
Text("Search pois")
],
),
onPressed: () {}),
),
),
body: Container(
color:Colors.blue,
child: Column(
children: [
Container(
decoration: BoxDecoration(
color:Colors.red,
borderRadius: BorderRadius.circular(20),
),
child: const TextField(
decoration: InputDecoration(,
hintText: 'Search',
suffixIcon: Icon(Icons.search,),
),
),
),
Obx(
),
],
),
),
),

You can wrap TextFiled's Container with Expanded and enable expanded on TextFiled.
body: Container(
child: Column(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
),
child: TextField(
expands: true,
maxLines: null,
minLines: null,
)),
),
],
),
),
SingleChildScrollView also work
body: SingleChildScrollView(
child: Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
),
child: TextField(
maxLines: 3,
minLines: 1,
)),
],
),
),
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
bottomNavigationBar: SolidBottomSheet(
draggableBody: true,
headerBar: Container(
child: ClipRRect(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(22), topLeft: Radius.circular(22)),
child: OutlinedButton(
child: Column(
children: const [
Icon(
Icons.expand_less,
),
Text(
"Search pois",
)
],
),
onPressed: () {}),
),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
),
child: TextField(
maxLines: 3,
minLines: 1,
)),
],
),
),
),
);
}
}

Related

Textfields shrinking whenever keyboard appears in flutter

I am trying to create an simple login form, there are 3 components in a column: row and 2 text fields.
The row contains an image and text.
The problem is whenever the keyboard appears while I want to type something in the textfield, all UI is shrinking.
I have attached before and after keyboard appears
How to make it such that whenever keyboard appears the elements hidden below the keyboard?
Here is my code:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Flexible(
fit: FlexFit.tight,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: EdgeInsets.only(top: 50),
child: Hero(
tag: "logo",
child: Image.asset(
"images/flash.png", width: 70, height: 50,)
),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(top: 50),
child: Text(
"Demo Chat",
style: TextStyle(
fontSize: 40,
color: Colors.black,
fontWeight: FontWeight.bold
),
),
),
)
],
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 50,
),
),
Flexible(
fit: FlexFit.tight,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
decoration: kTextFieldDecorationEmail,
keyboardType: TextInputType.emailAddress,
),
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 50,
),
),
Flexible(
fit: FlexFit.tight,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
decoration: kTextFieldDecorationPassword,
keyboardType: TextInputType.visiblePassword,
obscureText: true,
),
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 70,
),
),
Flexible(
fit: FlexFit.tight,
child: Padding(
padding: EdgeInsets.all(20),
child: MaterialButton(
color: Colors.blueAccent,
onPressed: (){},
height: 50,
child: Text(
"Login",
style: TextStyle(
color: Colors.black
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)
),
),
),
)
],
),
That is because you are using flexible with FlexFit.tight, this allows it to fit into screen regardless of the size. I would suggest you to use MediaQuery or some other field for this to tackle. An example to eliminate this would be something like this. I have edited your code a slight bit since I do not have the image and decoration at the moment which you are using I have put in some random one for the time being.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(top: 50),
child: Text(
"Demo Chat",
style: TextStyle(
fontSize: 40,
color: Colors.black,
fontWeight: FontWeight.bold),
),
)
],
),
SizedBox(
height: 50,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Username',
filled: true,
fillColor: Colors.grey,
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 6.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
borderRadius: BorderRadius.circular(10.0),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10.0),
),
),
keyboardType: TextInputType.emailAddress,
),
),
SizedBox(
height: 50,
),
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Password',
filled: true,
fillColor: Colors.grey,
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 6.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
borderRadius: BorderRadius.circular(10.0),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10.0),
),
),
keyboardType: TextInputType.visiblePassword,
obscureText: true,
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 70,
),
),
Padding(
padding: EdgeInsets.all(20),
child: MaterialButton(
color: Colors.blueAccent,
onPressed: () {},
height: 50,
child: Text(
"Login",
style: TextStyle(color: Colors.black),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
),
)
],
),
),
);
}
}
Screen:

Cannot apply decoration to Container in Flutter

After applying border to my Container, it disappears with this error:
Incorrect use of ParentDataWidget.
After commenting decoration. Widget is rendered.
But i need to give outline border like this:
I am getting this commenting the decoration:
Container(
child: Row(
children: [
Container(
// commenting this line fixes the issue
decoration: BoxDecoration( borderRadius: BorderRadius.circular(10) ),
child: Expanded(
child: Row(
children: [
Icon(LineAwesomeIcons.search),
Expanded(
child: TextField(
decoration: null,
minLines: 1,
maxLines: 2,
controller: pickupController,
onChanged: (val) {
},
),
),
Icon(LineAwesomeIcons.times),
],
),
),
),
SizedBox(width: 20,),
Text('Map'),
],
),
)
You can just decorate the TextField.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search),
suffixIcon: const Icon(Icons.close),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: Colors.grey,
width: 1,
),
),
),
),
),
FlatButton(
onPressed: () {},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
visualDensity: VisualDensity.compact,
child: const Text('Map'),
),
],
),
),
);
}
}
This should do the job:
Row(
children: [
Flexible(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: controller,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.search,
color: Colors.black,
),
suffixIcon: IconButton(
icon: Icon(
Icons.close,
color: Colors.black,
),
onPressed: () {
//TODO: implement functionality here.
},
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black.withOpacity(
0.1,
),
),
borderRadius: BorderRadius.circular(10),
),
),
),
),
),
Text(
"Map",
style:
TextStyle(fontWeight: FontWeight.w400, fontSize: 25),
)
],
),
Where did you go wrong:
The Row widget wants to determine the intrinsic size of its non-flexible children so it knows how much space that it has left for the flexible ones. However, TextField doesn't have an intrinsic width; it only knows how to size itself to the full width of its parent container. Try wrapping it in a Flexible or Expanded to tell the Row that you're expecting the TextField to take up the remaining space:
add width size to the second Container
then add border: Border.all() to BoxDecoration
Container(
child: Row(
children: [
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
border: Border.all(),
),
child: Expanded(
child: Row(
children: [
Icon(Icons.search),
Expanded(
child: TextField(
decoration: null,
minLines: 1,
maxLines: 2,
onChanged: (val) {},
),
),
Icon(Icons.clear),
],
),
),
),
SizedBox(
width: 20,
),
Text('Map'),
],
),
),

I want to make a button like this but not getting the desired output

I want to make a text form field and button inside a container and the click of a button text in the form should be copied to clipboard. How can I achieve this?
My Requirement is like this
Container(
height: 65.0,
width: 270.0,
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: "https://",
border: OutlineInputBorder(
borderRadius:
BorderRadius
.circular(10.0),
borderSide:
BorderSide()))),
),
Container(
child: FlatButton(
onPressed: () {},
child: Text("Copy Link")),
)
],
),
)
You have two things to learn to achieve, what you want, these are:
Clipboard class => Which does the clipboard copy. Also, do import this import 'package:flutter/services.dart'; in your file to use this Class
suffixIcon in InputDecoration, which will add the item to the end inside your TextField()
FINAL SOLUTION:
// mandatory for Clipboard class
import `'package:flutter/services.dart';
class _MyHomePageState extends State<MyHomePage> {
final key = new GlobalKey<ScaffoldState>();
final TextEditingController _controller = new TextEditingController();
#override
Widget build(BuildContext context){
return Scaffold(
key: key,
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
height: 65.0,
width: 270.0,
child: TextField(
controller: _controller,
decoration: InputDecoration(
hintText: "https://",
suffixIcon: FlatButton(
onPressed: () {
// Here what you have to do the operation using Clipboard
Clipboard.setData(new ClipboardData(text: _controller.text.toString()));
key.currentState.showSnackBar(
new SnackBar(content: new Text("Copied to Clipboard")));
},
child: Text("Copy Link")
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide()
)
)
)
)
),
);
}
}
RESULT:
You need to add the border to the Container and not the Textfield
Container(
height: 50.0,
width: 270.0,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(10.0),
),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 10.0),
hintText: "https://",
border: InputBorder.none,
),
),
),
Container(
height: 50.0,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(6.0),
),
child: FlatButton(onPressed: () {}, child: Text("Copy Link")),
),
],
),
)
Try this:
Container(
height: 65.0,
width: 270.0,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(20.0)),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "https://")),
),
Container(
child: FlatButton(
onPressed: () {},
child: Text("Copy Link")),
)
],
),
)
);
this will give

Keyboard hides TextField - Flutter

I've made a chat page that contains the header, a MessagesStream and a Row that includes the TextField and RaisedButton. I've checked every single page there is about this issue, both in GitHub and StackOverflow, but I wasn't able to find any solution. The row does not go up when the keyboard is launched, instead it goes over the bottom part of the screen, hiding everything.
Could anyone please help me figure this out? I've literally tried everything.
This is my Scaffold:
Widget build(BuildContext context) {
return GestureDetector(
onTap: (){
FocusScope.of(context).requestFocus(new FocusNode());
},
child: Scaffold(
resizeToAvoidBottomInset: true,
backgroundColor: Colors.lightGreenAccent,
appBar: new AppBar(
backgroundColor: Colors.lightGreenAccent,
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
centerTitle: true,
title: Image(
image: iconApp,
height: 50,
width: 50,
),
),
body: SafeArea(
child: Column(
children: <Widget>[
SizedBox(height: 10),
Expanded(
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Material(
borderRadius: BorderRadius.only(topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0)),
color: grayWhite,
elevation: 2,
child: Padding(
padding: const EdgeInsets.only(bottom:10),
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10.0, left: 15),
child: CircleAvatar(
child: Image.network(
),
),
),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10, left: 15),
child: Text(
"Test",
style: TextStyle(
color: Colors.black54,
fontSize: 20
),
),
),
Padding(
padding: const EdgeInsets.only(top: 3, left: 15),
child: Text(
"Test2",
style: TextStyle(
color: Colors.black54,
fontSize: 15
),
),
),
Container(
height: 1,
color: Colors.white70,
)
],
),
)
],
),
),
),
MensagensStream(),
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: textEditingController,
autofocus: true,
autocorrect: true,
onChanged: (value) {
mensagem = value;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
),
hintText: "Digite a sua mensagem..."
),
),
),
),
ButtonTheme(
height: 55,
minWidth: 10,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
100,
)
),
color: Colors.lightGreenAccent,
child: Icon(Icons.send, color: Colors.white),
onPressed: () => {
textEditingController.clear(),
firestore.collection('mensagens').add({
'Mensagem': mensagem,
'Remetente': googleEmail,
'Destinatario': "patio#teste.com",
'DataHorario': FieldValue.serverTimestamp(),
})
},
),
),
],
)
],
),
),
)
],
),
),
),
);
}
}```
Wrap either one of you Columns (probably the outer one) with a SingleChildScrollView. The issue is that simply popping up the keyboard doesn't suddenly tell the layout that it needs to be able to scroll. You have explicitly say you want it to be able to scroll.
See this for more information on the SingleChildScrollView.
You can use a Scaffold and place the text field as bottomSheet

How to fix Bottom Overflowed by 137 pixels on flutter

I'm building a login page for my APP ( delivery app )
I'm getting "Bottom overflowed by 89 pixels" and I can,t fix it.
I looked everywhere.
the only way I found was to add
resizeToAvoidBottomPadding: false
on the scaffold, but it did not work.
how to fix it?
Do i need to wrap something?
If yes, how to do it ?
And for last, what does "Bottom overflowed by 89 pixels" means?
class LoginPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
//
// Captura o tema do titulo
TextStyle titleTheme = Theme.of(context).textTheme.headline6.copyWith(
color: Layout.light(),
);
return Scaffold(
backgroundColor: Layout.primaryDark(),
body: Column(
children: <Widget>[
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 20),
ClipRRect(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Layout.light(),
width: 0,
),
borderRadius: BorderRadius.circular(160),
color: Layout.dark(.8),
),
child: Image.asset('assets/foto_app.png'),
),
borderRadius: BorderRadius.circular(170),
),
SizedBox(height: 20),
Text('Distribuidora Ilha Grande', style: titleTheme),
],
),
),
Stack(
children: <Widget>[
Positioned(
top: 10,
left: 0,
right: 0,
child: Container(
height: 50,
decoration: BoxDecoration(
color: Colors.transparent,
boxShadow: [
BoxShadow(
color: Layout.dark(),
offset: const Offset(0, 0),
spreadRadius: 8,
blurRadius: 15,
),
],
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25),
),
color: Layout.light(),
),
height: MediaQuery.of(context).size.height * .5,
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(50),
),
),
),
initialValue: 'Email',
),
SizedBox(height: 15),
TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(50),
),
),
),
initialValue: 'Senha',
),
SizedBox(height: 15),
SizedBox(
width: double.infinity,
height: 50,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(50),
),
),
onPressed: () {},
child: Text(
'ENTRAR',
style: titleTheme,
),
),
)
],
),
),
)
],
)
],
),
);
}
}
Replace the Top Column with Flex, and then use Expanded.
Flex(
direction:Axis.Vertical,
child: Expanded(...)
)