Bottom sheet covered by keyboard - flutter

friends!
I create FAB bottom sheet and want to make it to be "search" text field. But, when i push the FAB, it turns out, that keyboard appears and lays on the bottom sheet, so I can't see what I really type. Wanting to push bottom sheet up by using solutions recommended here:
Scaffold( resizeToAvoidBottomPadding: false, body: ...)
or
new Scaffold(
body: SingleChildScrollView(child: //your existing body...)
But, it doesn't work. Here is the result:
Bottom Sheet Appears
Keyboard covers the sheet
and here is my code:
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: new AppBar(
elevation: 0.1,
backgroundColor: Colors.lightBlue,
title: Text('WOW!'),
actions: <Widget>[
new IconButton(
icon: Icon(
Icons.shopping_cart,
color: Colors.white,
),
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => new cart())),
)
],
),
floatingActionButton: new FloatingActionButton(
child: const Icon(Icons.search),
backgroundColor: Colors.lightBlue,
onPressed: () => modal.mainBottomSheet(context)),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
bottomNavigationBar: new BottomAppBar(
color: Colors.white,
),
And here is the modal, that the code routes to:
class Modal {mainBottomSheet(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
color: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 30),
height: 400,
child: SingleChildScrollView(
child: Column(children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
child: Row(
children: <Widget>[
Icon(Icons.search),
Text(' SEARCH'),
],
),
),
Divider(
height: 8.0,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(children: <Widget>[
Expanded(child: Text('Keyword')),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5))),
style: TextStyle(),
),
),],),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(children: <Widget>[
Expanded(child: Text('Category')),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5))),
style: TextStyle(),
),
),],),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(children: <Widget>[
Expanded(child: Text('Based')),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5))),
style: TextStyle(),
),
),],),
),
Divider(
height: 0.0,
),
ButtonBar(
alignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 125,
child: RaisedButton(
color: Colors.redAccent,
child: Text(
'Cancel',
style: TextStyle(color: Colors.white),
),
onPressed: () {},
),
),
Container(
width: 125,
child: RaisedButton(
color: Colors.lightBlue,
child: Text(
'Find Now!',
style: TextStyle(color: Colors.white),
),
onPressed: () {},
),
),
],
),
]),
));
});
}
}
Has anybody found solutions to solve it?
Thanks!

Please use the following code
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: PlaceYourChildWidget(),
));
});

add resizeToAvoidBottomInset: true, to your scaffold widget ,
add isScrollControlled: true to your showModalBottomSheet method ,
and wrap all your widgets inside a Padding our animated Padding and set padding to:
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom)
return Scaffold(
resizeToAvoidBottomInset: true,
backgroundColor: Color(0xFFFCFCFC),
appBar: AppBar()
....
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
isScrollControlled: true,
builder: (context) {
return AnimatedPadding(
duration: Duration(milliseconds: 150),
curve: Curves.easeOut,
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
...

use isScrollControlled: true, in showModalBottomSheet

import 'dart:async';
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bootstrap/flutter_bootstrap.dart';
/*
TextEditingController txtname = TextEditingController();
showModalBottomSheet(
context: context,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
builder: (context) => SingleChildScrollView(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom),
child: new AddItem(
tektk: 'Category',
tektd: 'Add',
txtname: txtname,
ismultik:false,
onPressed: () {}),
),
);
*/
class AddItem extends StatelessWidget {
const AddItem(
{Key? key,
required this.ismultik,
required this.tektd,
required this.tektk,
required this.txtname,
required this.onPressed})
: super(key: key);
final bool ismultik;
final String tektk;
final String tektd;
final VoidCallback? onPressed;
final TextEditingController txtname;
#override
Widget build(BuildContext context) {
final MediaQueryData mediaQueryData = MediaQuery.of(context);
bootstrapGridParameters(gutterSize: 10);
return Padding(
padding: mediaQueryData.viewInsets,
child: Container(
padding: EdgeInsets.only(bottom: 90.0, left: 10.0, right: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ListTile(
trailing: SizedBox.fromSize(
size: Size(35, 35),
child: ClipOval(
child: Material(
color: Colors.indigo,
child: InkWell(
splashColor: Colors.white,
onTap: () {
Navigator.pop(context);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.close, color: Colors.white),
],
),
),
),
),
),
),
BootstrapRow(height: 0, children: [
BootstrapCol(
sizes: 'col-md-12',
child: TextField(
style: TextStyle(color: Colors.black),
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(color: Colors.white)),
labelText: tektk,
),
keyboardType: ismultik == true
? TextInputType.multiline
: TextInputType.text,
maxLines: null,
minLines: 1,
controller: txtname,
),
),
BootstrapCol(
sizes: 'col-md-12',
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.green, // background
onPrimary: Colors.white, // foreground
),
onPressed: onPressed,
child: Text(tektd)),
),
]),
],
),
),
);
}
}

Related

Flutter - show items in a list view with just the necessary length and borders

In my list view in a Flutter project, I need to show items i.e. pieces of text that are stored in a List variable. Each item (i.e. piece of text) will have rounded borders but the length of each item will vary according to the number of characters in the text. And on tapping each of the list item i.e. the piece of text, some action will take place.
Following is an image showing how the output should be:
Currently each list item takes the maximum size of the horizontally available space and text is aligned in the middle. But I want the background of each list item to be just containing the piece of text and not to be the full size horizontally and then text should be in the middle of the background. Current result is in the following image.
Code:
final List<String> names = <String>['Topic 1', 'Topic 2 ', 'Topic 3', 'Topic 4', 'Topic 5'];
ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
margin: EdgeInsets.all(2),
// color: msgCount[index]>=10? Colors.blue[400] msgCount[index]>3? Colors.blue[100]: Colors.grey,
child: Container(
child: Padding(
padding:EdgeInsets.fromLTRB(3, 0,0,0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[
Expanded(
child: TextButton(
onPressed: () {
print("Do something!");
},
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize:MaterialStateProperty.all(Size(double.infinity, 14)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40.0)),
),
backgroundColor:
MaterialStateProperty.all(
Colors.white
)),
child:Text('${names[index]} ',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
),
]
),
),
),
);
}
)
How can I achieve the list items to be as in the 1st screenshot ?
EDIT:
The above list view is inside the following code i.e. the following code should be appended to the above code and necessary brackets should be suffixed.
SingleChildScrollView(
// child: Container(
// padding: const EdgeInsets.only(top: 80, left: 24, right: 24),
child:Container(
height: MediaQuery.of(context).size.height, // or something simular :)
child: Column(
children: [
Text('Select a Topich000'),
EDIT2:
I am pasting the full code (i.e. not only the list view related code as the list view is inside other code snippet) from my application below.
So when you post answer, make sure that you use the format of my full code below:
final List<String> names = <String>['Topic 1', 'Topic 2 ', 'Topic 3', 'Topic 4', 'Topic 5'];
return Scaffold(
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
title: const Text('Topics'),
),
body: SingleChildScrollView(
child:Container(
height: MediaQuery.of(context).size.height, // or something simular :)
child: Column(
children: [
Text('Select a Topic'),
Expanded(
child: ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
margin: EdgeInsets.all(2),
child: Container(
child: Padding(
padding:EdgeInsets.fromLTRB(3, 0,0,0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[
Expanded(
child: TextButton(
onPressed: () {
print("Do something !");
Navigator.of(context).pushNamed("/subtopicScreen", arguments: {'index_found': index+1,
'uploadable_image_path':uploadable_image_path });
},
// );
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize:MaterialStateProperty.all(Size(double.infinity, 14)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40.0)),
),
backgroundColor:
MaterialStateProperty.all(
//Colors.green[900]
Colors.white
)),
child:Text('${names[index]} ',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
),
]
),
),
),
);
}
)
)
],
),
),
// ),
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 35.0,
width: double.maxFinite,
/*decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),*/
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
//IconButton(icon: Icon(Icons.chat), onPressed: (){ },),
InkWell(
onTap: () {
//Navigator.pushNamed(context, "YourRoute");
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => topicScreen(),
),
);
},
child: TextButton(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
child: Text('..',
style: TextStyle(
color: Colors.white,
// backgroundColor: Colors.blue,
fontSize: 14,
fontWeight: FontWeight.w500)),
),
style: TextButton.styleFrom(
primary: Colors.teal,
backgroundColor: Colors.blue,
onSurface: Colors.yellow,
side: BorderSide(color: Colors.teal, width: 2),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25))),
),
onPressed: () {
print('Pressed');
},
),
),
],
),
),
),
);
}
Try removing the Expanded widget and remove minimumSize:MaterialStateProperty.all(Size(double.infinity, 14)) from your TextButton Widget.
Code:
ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
margin: EdgeInsets.all(2),
// color: msgCount[index]>=10? Colors.blue[400] msgCount[index]>3? Colors.blue[100]: Colors.grey,
child: Container(
child: Padding(
padding: EdgeInsets.fromLTRB(3, 0, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(
onPressed: () {
print("Do something!");
},
style: ButtonStyle(
tapTargetSize:
MaterialTapTargetSize.shrinkWrap,
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(40.0)),
),
backgroundColor: MaterialStateProperty.all(
Colors.white)),
child: Text(
'${names[index]} ',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
]),
),
),
);
})
Try below code and used UnconstrainedBox.
UnconstrainedBox means render at its natural size.
Your List:
List list = [
'Science',
'Mathematics',
'English',
'Mental Ability',
];
Your Widget:
ListView.builder(
itemCount: list.length,
itemBuilder: (BuildContext context, int index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
UnconstrainedBox(
child: Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: InkWell(
onTap: () {
print('You Tapped on ${list[index]} subject');
},
child: Text(
list[index],
),
),
),
),
],
);
},
);
Result Screen->
You should try giving the widget in the builder method of the ListView.builder widget a height, specifically to your Container.
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
width: <your width here> <<<<<------
EDIT:
Working code.
final names = <String>[
'Topic 1',
'Topic 2 ',
'Topic 3',
'Topic 4',
'Topic 5'
];
return Scaffold(
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
title: const Text('Topics'),
),
body: SingleChildScrollView(
child: SizedBox(
height: MediaQuery.of(context).size.height, // or something simular :)
child: Column(
children: [
const Text('Select a Topic'),
Expanded(
child: ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: names.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
width: 100,
margin: const EdgeInsets.all(2),
padding: const EdgeInsets.fromLTRB(3, 0, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
print("Do something !");
// Navigator.of(context).pushNamed("/subtopicScreen", arguments: {'index_found': index+1,
// 'uploadable_image_path':uploadable_image_path });
},
// );
style: ButtonStyle(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: MaterialStateProperty.all(
const Size.fromWidth(100),
),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
40,
),
),
),
backgroundColor: MaterialStateProperty.all(
//Colors.green[900]
Colors.white,
),
),
child: Text(
'${names[index]} ',
style: const TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
],
),
);
},
),
)
],
),
),
// ),
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 35.0,
width: double.maxFinite,
/*decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),*/
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
//IconButton(icon: Icon(Icons.chat), onPressed: (){ },),
InkWell(
onTap: () {
//Navigator.pushNamed(context, "YourRoute");
},
child: TextButton(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
child: Text('..',
style: TextStyle(
color: Colors.white,
// backgroundColor: Colors.blue,
fontSize: 14,
fontWeight: FontWeight.w500)),
),
style: TextButton.styleFrom(
primary: Colors.teal,
backgroundColor: Colors.blue,
onSurface: Colors.yellow,
side: BorderSide(color: Colors.teal, width: 2),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25))),
),
onPressed: () {
print('Pressed');
},
),
),
],
),
),
),
);

when using SingleChildScrollView can't drag down botttom sheet

I've created an app with bottomsheet and listview builder.In the bottom, there is a text button when I drag it up bottom sheet must appear. There is a form in that bottom sheet. I wrap bottom sheet with SingleChildScrollView. But when I click TextFormField key board appear and I can scroll the bottom sheet. But I can't drag it down and close the bottom sheet. Even when I press back arrow in the phone to get rid of the key board.
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
const Home({Key key}) : super(key: key);
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
var width = MediaQuery.of(context).size.width;
return Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
children: [
ListView.builder(
itemCount: 1,
itemBuilder: (context, index) {
return Card(
);
}),
Positioned(
bottom: 0,
child: GestureDetector(
onPanEnd: (details) {
if (details.velocity.pixelsPerSecond.dy < 10) {
//Bottom Sheet.................................................................................................................
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(25)),
),
backgroundColor: Colors.green,
context: context,
builder: (context) {
return SingleChildScrollView(
child: Container(
padding: EdgeInsets.all(10),
child: Form(
child: Column(
children: [
Icon(Icons.arrow_drop_down),
Text("Drag down to Close"),
Container(
color: Colors.red,
child: Column(
children: [
Row(
children: [
Expanded(
child: TextFormField(
decoration: InputDecoration(
labelText: "Current amount",
),
),
),
],
),
Row(
children: [
Expanded(
child: TextButton(
onPressed: () {},
child: Text("Submit"))),
],
),
],
),
),
],
)),
),
);
});
// Bottom Sheet Ends ......................................................................................................................................................
}
},
child: Container(
color: Colors.blue,
width: width,
padding: EdgeInsets.all(10),
child: Column(
children: [
Icon(Icons.arrow_drop_up),
Text("Drag up to Enter an Account"),
],
),
),
),
)
]),
);
}
}
brother create your model bottom sheet in seprate widget its will open when you click and sceond wrap singlechild scroll view with bottom model sheet.
showModalBottomSheet(
enableDrag: true,
isDismissible: false,
isScrollControlled: true,
)
and complete example of bottom sheet
Widget updatebottomSheet()
{
Size size = MediaQuery.of(context).size;
showModalBottomSheet(
enableDrag: false,
isDismissible: false,
isScrollControlled: true,
context: context,
builder:(context)
{
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom+10),
// height: size.height*0.6,
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(25.0),
child: Container(
decoration: BoxDecoration(
//color: Colors.red,
borderRadius: BorderRadius.circular(20),
),
height: size.height*0.5,
width: double.infinity,
child: Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
NameField(
name:sectionname,
controller: null,
icon: Icons.person,
hintText: "Please enter section name",
text: "you not enter Smaster",
onchanged: (value)
{
setState(() {
Administrative.instance.SectionName=value;
});
},
),
NameField(
controller:null,
name:smaster,
icon: Icons.vpn_key_outlined,
hintText: "Please enter Section Smaster",
text: "your enter empty Smaster",
onchanged: (value)
{
setState(() {
Administrative.instance.Smaster=value;
});
},
),
],
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
child: Container(
width: double.infinity,
height: 60,
child: FlatButton(
color: Colors.black,
onPressed: (){
if(!_formKey.currentState.validate()){
return;
}
else
{
_formKey.currentState.save();
// signupauth.instance.addstudent();
if(Administrative.instance.SectionName==null)
{
Administrative.instance.SectionName=sectionname;
}
else if(Administrative.instance.Smaster==null)
{
Administrative.instance.Smaster=smaster;
}
print("hello"+ids);
FirebaseFirestore.instance
.collection("Section")
.doc(ids).update({
"SectionName":Administrative.instance.SectionName,
"Smaster":Administrative.instance.Smaster,
});
Fluttertoast.showToast(
msg: "Section is added",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.grey,
textColor: Colors.white,
fontSize: 16.0
);
Navigator.pop(context);
}
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text("Save",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
child: Container(
width: double.infinity,
height: 60,
child: FlatButton(
color: Colors.black,
onPressed: (){
Navigator.pop(context);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text("Cancel",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
),
),
),
],
),
),
),
);
}
);
}

Flutter: How to align textfield to bottom center in a column?

I am building a chat app.
I have 2 items on the column. First one is information card which is on top of page,
I also have a textfield but I cant figure out how to place it on bottom center.
Here is the main code with the problem:
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
resizeToAvoidBottomPadding: true,
appBar: userMessageChatAppBar(context),
body: SingleChildScrollView(
child: Column(
children: [
userMessageChatInformationCard(context),
Positioned(
bottom: 20,
child: userMessageChatTextField())
],
),
),
);
TextField where chatting will occur:
Padding userMessageChatTextField() {
return Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
decoration: InputDecoration(
suffixIcon: RaisedButton.icon(
onPressed: () {},
icon: Icon(
Icons.send,
color: Colors.white,
),
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
label: Text(
"19.99₺",
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
hintText: "Bir şeyler yaz",
border: new OutlineInputBorder(
borderSide: new BorderSide(color: Colors.teal)),
)),
);}
Information Card where user first sees:
Align userMessageChatInformationCard(BuildContext context) {
return Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
decoration: new BoxDecoration(
boxShadow: [
new BoxShadow(
color: Colors.grey,
blurRadius: 10.0,
),
],
),
child: Card(
clipBehavior: Clip.antiAlias,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'fernando muslera mesajını bekliyor',textAlign: TextAlign.center,
style: TextStyle(fontSize: 20.0, color: Colors.blueGrey),
),
),
Padding(
padding: const EdgeInsets.only(left: 20,right: 20,bottom: 20),
child: Text(
'280 karakterlik mesaj için ödeme yaparsın ünlünün mesajı alabilmesi uzun sürebilir',
textAlign: TextAlign.center, style: TextStyle(
color: Colors.black.withOpacity(0.6)),
),
),
],
),
),
)));
}
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
resizeToAvoidBottomPadding: true,
appBar: userMessageChatAppBar(context),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
userMessageChatInformationCard(context),
userMessageChatTextField()
],
),
);
}

Flutter: Deleting widget with delete icon from a list view in flutter

I have a form builder application, I have stateless widgets which get added to list view, each widget has a delete icon, I want to delete the widget and update the list view.
one of the code widget code is this
class HeaderTextWidget extends StatelessWidget {
final VoidCallback onDelete;
HeaderTextWidget({Key key, this.onDelete}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: 12.0),
decoration: BoxDecoration(
color: Colors.blueGrey,
borderRadius: BorderRadius.only(
topRight: Radius.circular(15.0),
topLeft: Radius.circular(15.0),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(6.0),
child: Text(
'Header',
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
),
),
),
Card(
elevation: 5.0,
color: Colors.blueGrey.shade50,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15.0),
topRight: Radius.circular(15.0),
),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 10.0, 8.0, 10.0),
child: TextField(
textCapitalization: TextCapitalization.words,
keyboardType: TextInputType.text,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
decoration: InputDecoration(
hintText: 'untitled header',
hintStyle: TextStyle(
color: Colors.grey,
fontStyle: FontStyle.italic,
fontSize: 14.0,
),
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 20.0),
child: TextField(
textCapitalization: TextCapitalization.words,
keyboardType: TextInputType.text,
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.normal,
),
decoration: InputDecoration(
hintText: 'Description (optional)',
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 14.0,
),
),
),
),
Divider(
indent: 4.0,
endIndent: 4.0,
thickness: 2.0,
),
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(
icon: Icon(Icons.content_copy),
iconSize: 24.0,
color: Colors.blue,
onPressed: () {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('COpy'),
),
);
},
),
IconButton(
icon: Icon(Icons.delete),
iconSize: 24.0,
color: Colors.red,
onPressed: this.onDelete,
),
VerticalDivider(
thickness: 2.0,
endIndent: 6.0,
indent: 4.0,
),
Padding(
padding: const EdgeInsets.only(right: 12.0),
child: SwitchWidget(),
),
],
),
),
],
),
),
],
),
);
}
}
This is my Listview builder
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
FormBuilder(
key: widget.fbKey,
autovalidate: true,
child: Expanded(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView.builder(
itemCount: widget.data.widgets.length,
controller: _scrollController,
itemBuilder: (context, index) {
return widget.data.widgets[index];
},
),
),
)),
],
),
);
This is how the widget is being added the view is getting changed from selected the widget to List view builder page, when clicked on that particular icon. Where should be the delete function be added, in the List view or in the widget itself ?
Scaffold(
appBar: AppBar(
title: Text('Form Widgets'),
),
body: LayoutBuilder(
builder:
(BuildContext context, BoxConstraints viewPointConstrainsts) {
return SingleChildScrollView(
padding: EdgeInsets.all(12.0),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewPointConstrainsts.maxHeight,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FormWidget(
key: UniqueKey(),
iconData: Icons.title,
widgetTxT: 'Header',
onTap: () {
setState(() {
widget.data.widgets.add(HeaderTextWidget());
widget.pickWidgetsView = false;
});
},
),
Try the following approach:
Store only the data, not the Widget itself in the list
List<DataModel> data = []
Create list view item using createListViewItem() which should return widget as the following
ListView.builder(
itemCount: widget.dataList.length,
controller: _scrollController,
itemBuilder: (context, index) {
return createListViewItem(index);
},
),
Now inside createListViewItem(index) you can create data as per widget.dataList[index] and delete the list item on click of delete icon
setState(){
widget.dataList.deleteAt(index);
}
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
DropdownButton(
items: _Mothe.map(
(String dropdownMenuItem) {
return DropdownMenuItem<String>(
value: dropdownMenuItem,
child: Text(dropdownMenuItem),
);
},
).toList(),
onChanged: (String? value) {
setState(
() {
name == value!;
},
);
},
value: name,
isExpanded: true,
icon: SizedBox(),
),
],
),
);
}

How to bottom align Button in the popup?

How to bottom align button in the popup ?
here is my tried code, but its giving some space from bottom.
I have used listview to build up popup
onPressed: () {
// Navigator.of(context).pushNamed(homePageTag);
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Form(
key: _formKey,
child: ListView(
shrinkWrap: true,//This tells items to be put in center
children: <Widget>[
FlatButton(
//padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
color: appGreenColor,
child: Text("UPDATE", style: TextStyle(color: Colors.white)),
onPressed: () {
},
),
],
),
),
);
});
},
Looking for this- https://ibb.co/19k2ty7
& getting this - https://ibb.co/h7KwXbn
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
Color myColor = Color(0xff00bfa5);
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Rounde Alert Box",
home: Scaffold(
appBar: AppBar(
backgroundColor: myColor,
title: Text("Rounded Alert Box"),
),
body: RoundedAlertBox(),
),
);
}
}
class RoundedAlertBox extends StatefulWidget {
#override
_RoundedAlertBoxState createState() => _RoundedAlertBoxState();
}
class _RoundedAlertBoxState extends State<RoundedAlertBox> {
#override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
onPressed: openAlertBox,
color: myColor,
child: Text(
"Open Alert Box",
style: TextStyle(color: Colors.white),
),
),
);
}
openAlertBox() {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0))),
contentPadding: EdgeInsets.only(top: 10.0),
content: Container(
width: 300.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
"Rate",
style: TextStyle(fontSize: 24.0),
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(
Icons.star_border,
color: myColor,
size: 30.0,
),
Icon(
Icons.star_border,
color: myColor,
size: 30.0,
),
Icon(
Icons.star_border,
color: myColor,
size: 30.0,
),
Icon(
Icons.star_border,
color: myColor,
size: 30.0,
),
Icon(
Icons.star_border,
color: myColor,
size: 30.0,
),
],
),
],
),
SizedBox(
height: 5.0,
),
Divider(
color: Colors.grey,
height: 4.0,
),
Padding(
padding: EdgeInsets.only(left: 30.0, right: 30.0),
child: TextField(
decoration: InputDecoration(
hintText: "Add Review",
border: InputBorder.none,
),
maxLines: 8,
),
),
InkWell(
child: Container(
padding: EdgeInsets.only(top: 20.0, bottom: 20.0),
decoration: BoxDecoration(
color: myColor,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(32.0),
bottomRight: Radius.circular(32.0)),
),
child: Text(
"Rate Product",
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
),
),
],
),
),
);
});
}
}