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),),
),
),
),
],
),
),
),
);
}
);
}
Related
Flutter & AlertDialog : How do I align it to bottom? How I make 2 Alert Dialogs like this pictures?Please have a lot at this picture.
showDialog(
context: context,
builder: (BuildContext context) {
double width =
MediaQuery.of(context).size.width;
double height =
MediaQuery.of(context).size.height;
return AlertDialog(
backgroundColor: Colors.transparent,
contentPadding: EdgeInsets.zero,
title: Center(
child: Text("Evaluation our APP")),
content: Container(
// What Should I write here?
)
},
);
Here is one of the solutions:
showDialog(
context: context,
builder: (BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return AlertDialog(
backgroundColor: Colors.transparent,
contentPadding: EdgeInsets.zero,
elevation: 0.0,
// title: Center(child: Text("Evaluation our APP")),
content: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
const BorderRadius.all(Radius.circular(10.0))),
child: Column(
children: [
Text("a"),
Divider(),
Text("b"),
Divider(),
Text("c"),
],
),
),
SizedBox(
height: 10,
),
Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
const BorderRadius.all(Radius.circular(10.0))),
child: Center(child: Text("d")),
)
],
));
},
);
here is my answer, pure widget without create AlertDialog:
final content = Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(10.0)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(onPressed: () {}, child: Text("a"),),
Divider(height: 1,),
TextButton(onPressed: () {}, child: Text("b"),),
Divider(height: 1,),
TextButton(onPressed: () {}, child: Text("c"),),
],
),
),
SizedBox(
height: 10,
),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
const BorderRadius.all(Radius.circular(10.0)),
),
child: TextButton(onPressed: () {}, child: Text("d"),),
),
SizedBox(
height: 40,
),
],
);
showDialog(
context: context,
builder: (ctx) {
return FractionallySizedBox(
widthFactor: 0.9,
child: Material(
type: MaterialType.transparency,
child: content,
),
);
}
);
have to add Material because of text drawing error.
I am stuck right now with the little app that I am trying to create.
The user when he will tap on an icon is supposed to get an alert dialog with 2 buttons (OK and Cancel), and in the body of the alert box, a Cupertino Picker. Below you will find the code. I am getting this error message.
Failed assertion: line 85 pos 15: 'children != null': is not true.
class Engage extends StatefulWidget {
Engage ({Key key}) : super(key:key);
#override
_EngageState createState() => _EngageState();
}
class _MyEngageState extends State<MyEngage> {
#override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[350])),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
// margin: const EdgeInsets.all(30.0),
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[350])
),
child : Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Column(
children: [
IconButton(
splashColor: Colors.lightGreenAccent,
icon : Image.asset('assets/icons/icon1',
height: iconHeighEngage,),
onPressed:(){
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('TEST'),
content: Container(
height: 350,
child: Column(
children: <Widget>[
CupertinoPicker(),
FlatButton(
child: Text("OK"),
onPressed: () {
Navigator.pop(context);
},
)
],
),
));
});
},
),
Text('TEST')],
),
),
Give it a try to this!
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
// margin: const EdgeInsets.all(30.0),
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[350])),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Column(
children: [
IconButton(
splashColor: Colors.lightGreenAccent,
icon: Icon(
Icons.add,
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext ctx) {
return AlertDialog(
title: Text('My Titile'),
content: Container(
height: 350,
width: 350.0,
child: Column(
children: <Widget>[
CupertinoPicker(
itemExtent: 200.0,
onSelectedItemChanged:
(int value) {
print("Test");
},
children: <Widget>[
FlatButton(
child: Container(
color:
Colors.orangeAccent,
width: 350.0,
height: 160.0,
child: Center(
child: Text(
"OK",
style: TextStyle(
fontSize: 20.0),
)),
),
onPressed: () {
Navigator.pop(context);
},
)
],
),
],
),
),
);
},
);
},
),
Text('TEST')
],
),
),
],
),
),
)
Note: The problem was, you weren't passing the parameters of CupertinoPicker()
EDIT :
First Initialize
int selected = 0;
and then:
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
padding: const EdgeInsets.all(10.0),
decoration:
BoxDecoration(border: Border.all(color: Colors.grey[350])),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Column(
children: [
IconButton(
splashColor: Colors.lightGreenAccent,
icon: Icon(
Icons.add,
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext ctx) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
backgroundColor: Colors.lightBlueAccent,
title: Text(
'My Dialog',
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
),
content: Container(
height: 350.0,
width: 350.0,
child: Column(
children: <Widget>[
Expanded(
child: CupertinoPicker(
useMagnifier: true,
magnification: 1.5,
backgroundColor: Colors.white,
itemExtent: 40.0,
onSelectedItemChanged: (int index) {
print(selected);
setState(() {
selected = index;
});
print(selected);
},
children: <Widget>[
Text(
"Text 1",
style: TextStyle(
color: selected == 0
? Colors.blue
: Colors.black,
fontSize: 22.0),
),
Text(
"Text 2",
style: TextStyle(
color: selected == 1
? Colors.blue
: Colors.black,
fontSize: 22.0),
),
Text(
"Text 3",
style: TextStyle(
color: selected == 2
? Colors.blue
: Colors.black,
fontSize: 22.0),
),
],
),
)
],
),
),
);
},
);
},
);
},
),
Text('Add')
],
),
),
],
),
),
),
The code is tested and working pretty fine now!
I am trying to create a page that consist of Search Bar, Infinite scroll product page and buttons (add product, remove product and notification). There is an error for the below statement...
The getter 'visible' was called on null,
Receiver : null,
Tried calling : null
please help me in rectifying this code.
class Inventory extends StatefulWidget {
#override
_InventoryState createState() => _InventoryState();
}
class _InventoryState extends State<Inventory> {
Color _color = Colors.white;
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: PreferredSize(
preferredSize: Size.fromHeight(70),
child: AppBar(
backgroundColor: Theme.Colors.darkBlue,
iconTheme: IconThemeData(size: 10, color: Colors.white),
elevation: 0,
title: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
AutoSizeText(
"Inventory ",
style: TextStyle(
fontSize: 35,
),
),
],
)),
),
drawer: MainDrawer(),
backgroundColor: Color(0xFF09182C),
body: Center(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 70,
width: width * 0.76,
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
hintText: 'Search Inventory',
hintStyle:
TextStyle(color: Color(0xFFE0E0E0), fontSize: 20),
suffixIcon: Icon(
Icons.search,
color: Colors.white,
size: 30,
)),
style: TextStyle(color: _color),
),
),
Container(
padding: EdgeInsets.only(bottom: 30.0),
child: IconButton(
onPressed: () {},
icon: Icon(Icons.filter_list,
size: 40, color: Color(0xFFFFAE40)),
),
),
],
),
LoadingPage(),
Spacer(),
Container(
margin: EdgeInsets.only(bottom: 70),
padding: EdgeInsets.only(left: 30, right: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Material(
type: MaterialType.transparency,
child: Ink(
decoration: BoxDecoration(
border:
Border.all(color: Color(0xFF57D0F4), width: 2.0),
color: Colors.transparent,
shape: BoxShape.circle,
),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddProduct()),
);
},
child: Padding(
padding: EdgeInsets.all(13.0),
child: Icon(
Icons.add,
size: 55.0,
color: Color(0xFF57D0F4),
),
),
),
),
),
Material(
type: MaterialType.transparency,
child: Ink(
decoration: BoxDecoration(
border:
Border.all(color: Color(0xFF57D0F4), width: 2.0),
color: Colors.transparent,
shape: BoxShape.circle,
),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RemoveProduct()),
);
},
child: Padding(
padding: EdgeInsets.all(13.0),
child: Icon(
Icons.delete_outline,
size: 55.0,
color: Color(0xFF57D0F4),
),
),
),
),
),
Material(
type: MaterialType.transparency,
child: Ink(
decoration: BoxDecoration(
border:
Border.all(color: Color(0xFF57D0F4), width: 2.0),
color: Colors.transparent,
shape: BoxShape.circle,
),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Notify()),
);
},
child: Padding(
padding: EdgeInsets.all(13.0),
child: Icon(
Icons.notifications_none,
size: 55.0,
color: Color(0xFF57D0F4),
),
),
),
),
),
],
),
)
],
),
));
}
}
class LoadingPage extends StatefulWidget {
#override
_LoadingPageState createState() => _LoadingPageState();
}
class _LoadingPageState extends State<LoadingPage> {
List prd;
ScrollController _scrollController = ScrollController();
int _currentMax = 10;
#override
void initState() {
super.initState();
prd = List.generate(10, (i) => "Product ${i + 1}");
_scrollController.addListener(() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
_getMoreData();
}
});
}
_getMoreData() {
for (int i = _currentMax; i < _currentMax + 10; i++) {
return prd.add("Product ${i + 1}");
}
_currentMax = _currentMax + 10;
setState(() {});
}
#override
Widget build(BuildContext context) {
return ListView.builder(
controller: _scrollController,
itemCount: prd.length + 1,
itemExtent: 70,
itemBuilder: (context, i) {
if (i == prd.length) {
return CupertinoActivityIndicator();
}
return ListTile(
title: AutoSizeText(prd[i]),
);
});
}
}
Thanks for your help #Mobina and #JohnJoe.
I wrapped the ListView.builder with Flexible which fixed the problem and added COntainer to put it inside a greyish background.
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
height: 450,
width: 350,
decoration: BoxDecoration(
color: Color(0xFF707070),
borderRadius: BorderRadius.all(
Radius.circular(
10.0,
),
)),
child: Flexible(
child: ListView.builder(
controller: _scrollController,
itemCount: prd.length + 1,
itemExtent: 42.5,
itemBuilder: (context, i) {
if (i == prd.length) {
return CupertinoActivityIndicator();
}
return ListTile(
title: AutoSizeText(prd[i]),
);
}),
),
);
}
Hello,
I'm creating an application from a T-Shirt designing. I need to change text color according to the user selection
The problem is that the text on the shirt is in draggable Widget(code attached) and when I select a color from BottomSheet(code attached) then the value is print but the text color is not changed until I touch the text on the screen. Is it possible to update the text color every time I change the color from bottom sheet.
Please help!!
showBottomSheet(
context: context,
builder: (context) {
return Container(
color: Colors.grey[200],
height: 300,
child: StatefulBuilder(builder: (BuildContext context,
StateSetter setStates /*You can rename this!*/) {
return Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
// Text("Select Text Color"),
InkWell(
onTap: () {
clr = Colors.grey;
setStates((){
color =clr;
});
print(clr);
Navigator.pop(context);
},
child: Container(
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(40),
),
child: Icon(Icons.brightness_1,
size: 60, color: Colors.grey),
)),
],
),
);
}),
);
});
Draggable(
feedback: Container(
padding: EdgeInsets.all(10),
child: Material(
type: MaterialType.transparency,
child: Text(
name,
style: TextStyle(fontSize: 30,color: color),
),
)),
child: Container(
padding: EdgeInsets.all(10),
child: Text(
name,
style: TextStyle(fontSize: 30,color: color),
)),
childWhenDragging: Container(),
onDragEnd: (DraggableDetails d) {
setState(() {
pos[0].setPosition(d.offset.dx, d.offset.dy);
});
},
),
Move your StatefulBuilder above in your widget tree, then passes the StateSetter to the function calling the showBottomSheet
for example :
Widget buildBody(context){
return Container(
child: StatefulBuilder( builder: (BuildContext context, StateSetter setstates){
return Column(
children: <Widget>[
FlatButton(
child: Text('open bottom sheet'),
onPressed: () {
showbt(context, setstates);
},
),
Draggable(
feedback: Container(
padding: EdgeInsets.all(10),
child: Material(
type: MaterialType.transparency,
child: Text(
'name',
style: TextStyle(fontSize: 30, color: color),
),
)),
child: Container(
padding: EdgeInsets.all(10),
child: Text(
'name',
style: TextStyle(fontSize: 30, color: color),
)),
childWhenDragging: Container(),
onDragEnd: (DraggableDetails d) {
setState(() {
//pos[0].setPosition(d.offset.dx, d.offset.dy);
});
},
),
],
);
},
),
);
}
the showbt code :
void showbt(context, setstates) {
showBottomSheet(
context: context,
builder: (context) {
return Container(
color: Colors.grey[200],
height: 300,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
// Text("Select Text Color"),
InkWell(
onTap: () {
setstates(() {
color = Colors.grey;
});
print('color : ');
print(color);
Navigator.pop(context);
},
child: Container(
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(40),
),
child: Icon(Icons.brightness_1,
size: 60, color: Colors.grey),
)),
],
),
),
);
});
}
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)),
),
]),
],
),
),
);
}
}