Button to appear above the keyboard in Flutter - flutter

I have a layout the login button is at the bottom of the screen and the TextFormField's are at the top of the screen. I have an issue where I want to display the button above the keyboard when it appears but I'm having difficulties doing that. I want a clean solution and not some hack, but can't seem to find one. Is using a floatingActionButton or bottomNavigationBar a solution maybe and using MediaQuery.of(context).viewInsets.bottom? Here is the code and pictures.
I have this view of the screen:
but when the keyboard appears I can't see the login button:
I wanted to put the button right beneath the password TexFormField after the keyboard appears.
Is there some sort a simple solution and yet not a hack for this?
Here is the code:
Scaffold(
resizeToAvoidBottomInset: false, // <- here I set this to false so my whole widget doesn't resize when the keyboard appears
backgroundColor: Colors.white,
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
children: [
SizedBox(
height: 48.0,
),
Padding(
padding: const EdgeInsets.only(left: 24.0, right: 25.0),
child: Form(
key: _loginFormKey,
child: Column(
children: [
TextFormField(
onChanged: (value) {
setState(() => email = value);
},
),
SizedBox(
height: 24.0,
),
TextFormField(
onChanged: (value) {
setState(() => password = value);
},
),
],
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(
left: 23.0, right: 24, bottom: 64.0),
child: SizedBox(
width: double.infinity,
child: PrimaryButton(
buttonText: 'LOG IN',
),
),
),
],
),
);
Thanks in advance for you help!

In your code, you have to avoid resizeToAvoidBottomInset: false which makes your button invisible, and yes I see, you need space between edit text and button that's why you add Colum as a parent. but there is another better way to achieve this and the yes button will show in below code as you expected.
Scaffold(
backgroundColor: Colors.white,
body:
Stack(
children: [
Padding(
padding: const EdgeInsets.only(left: 24.0, right: 25.0),
child: Form(
child: Column(
children: [
TextFormField(
onChanged: (value) {},
),
SizedBox(
height: 24.0,
),
TextFormField(
onChanged: (value) {},
),
],
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding:
const EdgeInsets.only(left: 23.0, right: 24, bottom: 64.0),
child: SizedBox(
width: double.infinity,
child: ElevatedButton(
child: Text("Button"),
onPressed: () {},
)),
),
),
],
)
);

Related

Flutter: A RenderFlex overflowed by 4.0 pixels on the bottom

I tried to make a login page with an animated logo, two TextField and a button. when I ran the app and tried to put some value in the TextField then the keyboard shows up and it looks like the image I provided.
The error is: A RenderFlex overflowed by 4.0 pixels on the bottom.
Here is my code :
Scaffold(
body: ModalProgressHUD(
inAsyncCall: _spinner,
child: ListView(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Hero(
tag: 'logo',
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 50),
child: Container(
height: animation.value * 50,
child: Image.asset("lib/images/chat.png"),
),
),
),
const SizedBox(
width: 50,
),
const Text(
"Email",
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(
width: 20,
),
Padding(
padding: const EdgeInsets.all(12.0),
child: TextField(
onChanged: (value) {
email = value;
},
const Text(
"Password",
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(
width: 20,
),
Padding(
padding: const EdgeInsets.all(12.0),
child: TextField(
onChanged: (value) {
Password = value;
},
const SizedBox(
width: 50,
),
Padding(
padding: const EdgeInsets.all(20.0),
child: ElevatedButton(
onPressed: () async {
setState(() {
_spinner = true;
});
},
child: Text("Registar"),
style: ElevatedButton.styleFrom(
primary: Colors.blueAccent,
minimumSize: const Size.fromHeight(40), // NEW
),
),
)
],
),
],
)),
);
image:
Try wrapping your ListView with SingleChildScrollView
Try using resizeToAvoidBottomInset: true,
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,

flutter problem: How to make button with centered text and right side Icon

I want to make a button, In this button I want a text and icon both but text should be in center and icon will be right side.
this is code of button.
bottomNavigationBar: Padding(
padding:
const EdgeInsets.only(top: 20.0, bottom: 20, left: 20, right: 20),
child: SizedBox(
height: 45,
width: MediaQuery.of(context).size.width,
child: FlatButton(
onPressed: () {
_controller.nextPage(
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
);
if(_currentPage + 1 == splashData.length){
Navigator.push(context,
MaterialPageRoute(builder: (context) => HomePage()));
}
},
child: Row(mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Next",
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
SizedBox(width: 50,),
Padding(
padding: const EdgeInsets.only(right: 10),
child: Icon(Icons.arrow_forward,color: whiteColor,),
)
],
),
color: skyBlue,
),
),
),
I want like this button
but is becoming like this.
Try below code, used Opacity widget and set opacity:0
Note: Don't used FlatButton its depricated by Flutter used instead of ElevatedButton, TextButton
Refer here to new buttons
ElevatedButton(
onPressed: () {
//write your onPressed function here
print('Pressed');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Opacity(
opacity: 0,
child: Icon(Icons.arrow_forward),
),
Text('Next'),
Icon(Icons.arrow_forward),
],
),
),
Your result screen->
You can use Stack instead of Row to achieve easily.
Inside Stack you can use Positioned(right: 10, child: Icon()) also.
Stack(
alignment: Alignment.center,
children: const [
Text(
'Next',
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
Align(
alignment: Alignment.centerRight,
child: Icon(Icons.arrow_forward, color: Colors.white,),
)
],
)
We have more than two ways to achieve it. I have given two easiest option to achieve it.
You can use Expanded (and play with the flex property if needed).
Also add an Align
For instance:
Row(mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(),
Expanded(
child: Text(
"Next",
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 10),
child: Icon(Icons.arrow_forward,color: whiteColor),
),
),
),
],
),

Flutter right side floating actions bar

I want to show this kind of side menu when I click button, like a drawer. It is only for specific screen control only not for every screen. May I know which control I can use.
There will be vertical slider and some buttons to control the page.
Should I use bottom sheet or dialog or floating action button? Or is there any library like side menu?
Please refer below code
double _value = 0.0;
#override
Widget build(BuildContext context) {
return Stack(
overflow: Overflow.visible,
children: [
Container(
color: Colors.white,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Center(
child: Text("Example"),
),
),
Align(
alignment: Alignment.center,
child: Row(
children: [
Spacer(),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.symmetric(
vertical: 3.0,
),
padding: EdgeInsets.symmetric(
horizontal: 9.0,
vertical: 12.0,
),
decoration: BoxDecoration(
color: Colors.black54,
borderRadius: BorderRadius.circular(
8.0,
),
),
child: Icon(
Icons.vibration_rounded,
color: Colors.blue,
size: 28.0,
),
),
Container(
margin: EdgeInsets.symmetric(
vertical: 5.0,
),
padding: EdgeInsets.symmetric(
horizontal: 0.0,
vertical: 12.0,
),
decoration: BoxDecoration(
color: Colors.black54,
borderRadius: BorderRadius.circular(
8.0,
),
),
child: Column(
children: [
SfSlider.vertical(
min: 0.0,
max: 100.0,
value: _value,
interval: 10,
showTicks: false,
showLabels: false,
enableTooltip: false,
minorTicksPerInterval: 1,
inactiveColor: Colors.white24,
onChanged: (dynamic value) {
setState(() {
_value = value;
});
},
),
Icon(
Icons.music_note_rounded,
color: Colors.blue,
size: 25.0,
),
SizedBox(
height: 12.0,
),
Icon(
Icons.settings,
color: Colors.white,
size: 25.0,
),
],
),
),
],
),
SizedBox(
width: 9.0,
),
],
),
),
],
);
}
You can use the stack to create a floating menu and also show or hide the floating menu with the Visibility widget.
bool showMenu = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Column(
children: <Widget>[
......................
],
),
Positioned(
top: 50.0,
left: 25.0,
child: Visibility(
child; YourFloatingMenu(),
visible: showMenu,
),
),
],
),
);
}

There are constantly overflows on the card structure

I just started flutter. I tried to make a card structure but I think it is quite wrong. I could never fix it. I am using Gridview extend. In this way, the column numbers change dynamically as the screen gets smaller or larger. but i keep getting overflow error what should i do.
var response = sepet.itemsCount[item.name];
return SizedBox(
child: Padding(
padding: EdgeInsets.all(0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: InkWell(
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
onTap: () {},
child: Column(
children: <Widget>[
ListTile(
title: Text(item.name ?? ''),
subtitle: Text(item.defaultPrice.toString() + '\$'),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
countChanger(sepet, false, item),
Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: Text(
response != null ? response.toString() : '0',
style: TextStyle(fontSize: 18.0),
),
),
countChanger(sepet, true, item),
],
),
ButtonTheme(
height: 25,
minWidth: 25,
child: ElevatedButton(
onPressed: () {
!isAdded
? sepet.sepeteEkle(item)
: sepet.deleteItem(item);
},
style: ElevatedButton.styleFrom(
primary: !isAdded
? Colors.teal
: Colors.red,
),
child: Text(!isAdded ? 'Ekle' : 'Çıkar'),
),
),
],
),
)
],
),
),
),
],
),
),
);
My gridview extend structure is like this
child: GridView.extent(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
maxCrossAxisExtent: 250.0,
crossAxisSpacing: 20.0,
mainAxisSpacing: 20.0,
children: List.generate(foods!.length, (index) {
return itemCard(foods[index].menuItem ?? MenuItem(), value);
}),
The question you need to answer is what would you like to happen if the width of that card is so small? Do you want a different arrangement of those elements? If you do decide on what that would look like and check the constraint with LayoutBuilder Or the whole screen width with MediaQuery whatever you feel is best. You could also make that bit scroll horizontally by using SingleChildScrollView. This is a design decision. You must image what things look like when screen size changes, and be as deliberate as possible with the responsiveness rather then to just try to find some magic widget which we are all guilty of doing sometimes.
Try below code hope its helpful to you I have try similar to your code and add your widgets in Expanded or Flexible Widgets.
flexible widgets
expanded Widgets
GridView.builder(
padding: const EdgeInsets.all(8),
itemCount: 4,
itemBuilder: (ctx, i) {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text('data'),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
margin: EdgeInsets.all(10),
height: 35.0,
width: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.grey,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
InkWell(
child: Icon(Icons.remove, color: Colors.green),
onTap: () {},
),
Spacer(),
Text(
'0',
style: Theme.of(context)
.textTheme
.subtitle2!
.copyWith(fontSize: 16.0),
),
Spacer(),
InkWell(
child: Icon(
Icons.add,
color: Colors.green,
),
onTap: () {},
),
],
),
),
),
Expanded(
child: ElevatedButton(
onPressed: () {},
child: Text(
'Sub Total',
style: TextStyle(
fontSize: 15,
),
),
),
),
],
),
],
),
);
},
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 170.0,
mainAxisExtent: 93,
),
),
Your Result screen like->

showDialog in flutter is not working in release version of iOS

I am creating an app for iOS using Flutter.
For that Application, I am using dialogue in one screen.
For that dialogue, It is showing a grey layer on dialogue in the
release version of iOS but it is working as expected in the Simulator or debug version
There is a grey layer on dialogue I have added my code to anyone facing the same issue?
need help.
static dynamic customPage(BuildContext context) {
return showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return CustomDialog(
insetPadding: const EdgeInsets.all(20),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
child: Container(
child: Stack(
children: [
Positioned(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Positioned(
right: 0.0,
child: GestureDetector(
onTap: () {
if (Navigator.canPop(context))
Navigator.pop(context, true);
},
child: Container(
color: Colors.transparent,
child: Icon(
Icons.close,
color: Colors.black,
size: 25,
),
),
),
),
),
right: 1.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
"images/bind_loader.gif",
height: 90.0,
width: 90.0,
),
],
),
Padding(
padding: const EdgeInsets.only(top: 80.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomDialougeUtil(),
],
),
),
Padding(
padding: const EdgeInsets.only(
right: 12.0, bottom: 10.0, top: 120),
child: Text(
"Please wait while we are confirming your payment",
style: bindTheme.textTheme.headline3,
textAlign: TextAlign.center,
),
),
],
),
),
);
},
);
}
// this is a Widget that is showDialog
class _CustomDialougeUtilState extends State<CustomDialougeUtil> {
//State full widget that uses normal timer view to display on dialogue
}