Keyboard hides textfield on Flutter - flutter

I have an app that has a bottomappbar with a textformfield, but when the user tries to insert data there the keyboard hides the text being typed.
I tried "resizeToAvoidBottomInset: true" and didnt worked, also tried to put a SingleChildScrollView on the body of the app and got "RenderBox was not laid out: RenderRepaintBoundary#32f0a relayoutBoundary=up1 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1785 pos 12: 'hasSize'".
I need a way to make the bottom part "expand" to the top of the keyboard when the user is typing or a way to show in the screen the text that is being typed.
How can I solve that? I have tried many ways and nothing seems to work.
The structure of my app is:
The code:
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text(
"xx",
),
//+ produtosList1[0].cod_produto),
actions: <Widget>[
Padding(
padding: EdgeInsets.only(right: 20.0),
child: GestureDetector(
onTap: () {
showDialog(
//dialog content
);
},
child: Icon(
Icons.search,
size: 26.0,
),
)),
],
),
drawer: Drawer(
elevation: 20.0,
child: ListView(padding: EdgeInsets.zero, children: <Widget>[
]
//appbar content
)),
body: Column(
children: [
Container(
color: Colors.blue,
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Column(
children: [
Row(children: [
Text(
"xxx",
style: TextStyle(
color: Colors.white,
),
overflow: TextOverflow.ellipsis),
]),
Row(children: [
Text(
"xxxx",
style: TextStyle(color: Colors.white),
)
])
],
)),
),
Container(
color: Colors.blue,
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 8.0, 0, 8.0),
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Text("xxxx",
style: TextStyle(fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis),
),
Expanded(
flex: 1,
child: Text(
"xxxxx",
style: TextStyle(fontWeight: FontWeight.bold),
)),
Expanded(
flex: 4,
child: Text(
"xxxx",
style: TextStyle(fontWeight: FontWeight.bold),
)),
Expanded(
flex: 4,
child: Text(
"xxxx",
style: TextStyle(fontWeight: FontWeight.bold),
)),
],
)),
),
Divider(
height: 5.0,
),
Expanded(
child: ListView.builder(
itemCount: produtosList1.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.fromLTRB(0.0, 4.0, 0.0, 4.0),
child: Row(
children: <Widget>[
Expanded(
flex: 2,
child: Text(
"xxxx"
),
),
Expanded(
flex: 1,
child: Text(
"xxxxx",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Expanded(
flex: 4,
child: Text(
"xxxx",
style: TextStyle(fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis),
),
Expanded(
flex: 4,
child: Text(
"xxxxx",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 12),
overflow: TextOverflow.ellipsis),
),
],
),
);
}),
)
],
),
bottomNavigationBar: BottomAppBar(
child: Form(
child: Container(
height: 180.0,
color: Colors.blue[400],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(children: [
Container(
height: 50,
decoration: BoxDecoration(
color: Colors.white,
),
child: DropdownButtonFormField(
hint: Text('Choose '),
onChanged: (value) {
//dropdown values
},
items: newFuncionariosList,
),
),
Divider(
height: 6.0,
),
Row(
children: [
Expanded(
flex: 2,
child: TextFormField(
controller: _codprodController,
decoration: InputDecoration(
icon: Icon(Icons.add),
),
),
),
Expanded(
flex: 1,
child: ElevatedButton(
//button content
),
)
],
),
Divider(
height: 8.0,
),
Row(
children: [
Expanded(
flex: 6,
child: Text(produtoDesc == null ? "- - -" : produtoDesc,
overflow: TextOverflow.ellipsis)),
Expanded(
flex: 2,
child: TextFormField(
keyboardType: TextInputType.number,
controller: _qtdController,
decoration: InputDecoration(hintText: "qtd"),
),
),
Expanded(
flex: 2,
child: ElevatedButton(
//button content
))
],
)
]),
),
),
),
),
);
}

use MediaQuery.of(context).viewInsets.bottom and add it to your bottom navigation height
child: Form(
child: Container(
height: 180.0 + MediaQuery.of(context).viewInsets.bottom,
color: Colors.blue[400],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(children: [
Container(
height: 50,
decoration: BoxDecoration(
color: Colors.white,
),
),```

Fixed problem textfield was hidden by keyboard
new Scaffold(
appBar: new AppBar(
...
resizeToAvoidBottomPadding: true,
....

Related

Wrapping a Row of Texts with Colored Rounded Box

Based on the code below, how does one wrap around a row of texts in a container? (as shown in the image). And also, how to make the container slightly rounded as shown in the image?
When I wrap it in a container, why does it takes up the full width of the app from left to right, which is not what I am trying to achieve.
Thank you in advance.
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Container(
child: Expanded(
child: PageView(
controller: _pageController,
onPageChanged: (page) {
setState(() {
currentIndex = page;
});
},
children: [
SingleChildScrollView(
child: Column(
children: [
Container(
padding: EdgeInsets.only(
top: 0, left: 220, right: 30, bottom: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(
flex: 7,
child: Text(
'187,177.33',
style: GoogleFonts.openSans(
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.w500),
textAlign: TextAlign.right,
),
),
SizedBox(width: 10),
Expanded(
flex: 4,
child: Text(
'82',
style: GoogleFonts.openSans(
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.w500),
textAlign: TextAlign.right,
),
),
],
),
),
],
),
),
],
),
),
),
],
),
);
}
Use decoration on Container. Also reduce the padding,
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(12)),
child: Row(
return Scaffold(
body: Column(
children: [
Container(
child: Expanded(
child: PageView(
// controller: _pageController,
onPageChanged: (page) {
setState(() {
// currentIndex = page;
});
},
children: [
SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(12)),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(
flex: 7,
child: Text(
'187,177.33',
style: GoogleFonts.openSans(
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.w500),
textAlign: TextAlign.right,
),
),
SizedBox(width: 10),
Expanded(
flex: 4,
child: Text(
'82',
style: GoogleFonts.openSans(
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.w500),
textAlign: TextAlign.right,
),
),
],
),
),
),
],
),
),
],
),
),
),
],
),
);
}
More information about Container and layout
Container has property which called decoration, It would does the job for you, Try this:
Container(
margin: EdgeInsets.all(16),
padding:
EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'187,177.33',
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w500),
textAlign: TextAlign.right,
),
SizedBox(width: 10),
Text(
'82',
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w500),
textAlign: TextAlign.right,
),
],
),
)

Flutter error 'RenderAspectRatio has unbounded constraints' when row of containers are inside a wrapped Expanded column

In Flutter, I'm attempting to build rows of containers that are inside the Expanded wrapped column which is also inside a row. for some reason, it errors on 'RenderAspectRatio has unbounded constraints'. I've attempted to move the Expanded widget to different places on the code but it continues to error sometimes it will throw,
"RenderFlex children have non-zero flex but incoming height constraints are unbounded"
I've tried many things and I read many Q&A on the issues here in StackOverflow and elsewhere but to no avail, I still haven't solved the problem.
here's the code:
Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0, color: Colors.black45),
),
),
),
),
),
GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0, color: Colors.black45),
),
),
),
),
),
GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0, color: Colors.black45),
),
),
),
),
),
GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0, color: Colors.black45),
),
),
),
),
),
],
),
],
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
//Expanded(
//child:
GestureDetector(
onTap: () {
print('Just clicked on 8');
},
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.cyan,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'8',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0, color: Colors.black45),
),
),
),
),
],
),
),
],
),
],
),
),
),
);
}
I'm attempting to create something that looks like this:
I didn't get the whole idea from the image but from what I understood, I have implemented it like this.
Since there is a lot of repetition and there is a pattern, I use GridView and ListView respectively.
class NumbersGridView extends StatelessWidget {
const NumbersGridView({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
childAspectRatio: 3 / 2,
crossAxisSpacing: 10,
mainAxisSpacing: 20,
),
itemCount: 30,
itemBuilder: (buildContext, index) {
return InkWell(
onTap: () {
print(index);
},
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.cyan,
margin: const EdgeInsets.all(1.0),
child: AutoSizeText(
index.toString(),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 300.0, color: Colors.black45),
),
),
),
);
}),
),
Container(width: 20.0, child: VerticalDivider(color: Colors.red)),
Flexible(
child: SizedBox(
width: 50.0,
child: ListView.builder(
itemCount: 5,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (buildContext, index) {
return Container(
height: 40.0,
width: 40.0,
alignment: Alignment.center,
color: Colors.cyan,
child: AutoSizeText(
index.toString(),
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.black45),
),
);
}),
),
)
],
);
}
}
If you want to implement it as you originally tried, here's is the code without the specified error.
Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0,
color: Colors.black45),
),
),
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0,
color: Colors.black45),
),
),
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0,
color: Colors.black45),
),
),
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
print('Just clicked on 7');
},
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.yellow,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'7',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0,
color: Colors.black45),
),
),
),
),
),
),
],
),
],
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//Expanded(
//child:
GestureDetector(
onTap: () {
print('Just clicked on 8');
},
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.cyan,
margin: const EdgeInsets.all(1.0),
child: const AutoSizeText(
'8',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 300.0, color: Colors.black45),
),
),
),
),
],
),
),
],
)

What is the most effective way to keep titles above a ListView aligned with the data in the ListView?

I'm kinda a loser when it comes to formatting and I've come to the conclusion I need a little guidance/advice. I have a ListView populated with cards that display data in them. Above this ListView I have the titles for the data in the ListView. Along with a search bar, but that shouldn't affect much. I'm having issues making the titles stay aligned with the data in the cards below, especially when switching between different devices since the screen size changes. What is the best way to do this? Any help and/or advice is highly appreciated!
This is an image of how it looks currently
This is the current code. I'm using a combination of flex and expanded for most of my formatting for moving the data & titles around.
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: PreferredSize(
preferredSize: Size.fromHeight(95.0),
child: AppBar(
automaticallyImplyLeading: false, // hides leading widget
flexibleSpace: DataAppBar(onChanged: (newValue) {
setState(() {
newValue = newValue;
});
}),
),
),
body: StreamBuilder<dynamic>(
stream: DataDBProvider.dataDB.getData(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
List data = snapshot.data;
return Column(children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * .45,
height: MediaQuery.of(context).size.height * .05,
child: TextField(
controller: editingController,
decoration: InputDecoration(
labelText: "Search",
hintText: "Search",
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(25.0)))),
),)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 3,
child: Container(
child: Text(
"Date",
style: TextStyle(
color: Colors.green, fontFamily: 'Montserrat'),
),
)),
Flexible(
flex: 2,
child: Container(
alignment: Alignment.centerLeft,
child: Text(
"Item",
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.green, fontFamily: 'Montserrat'),
),
),
),
Flexible(
flex: 2,
child: Container(
alignment: Alignment.center,
child: Text(
"Amount",
maxLines: 1,
style: TextStyle(
color: Colors.green, fontFamily: 'Montserrat'),
),
),
),
]),
Expanded(
child: ListView.builder(
itemCount: data.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.symmetric(
vertical: 1.0, horizontal: 4.0),
child: InkWell(
onLongPress: () =>
_openUpdateDrawer(data[index]),
child: Card(
color: (index % 2 == 0) ? greycolor : Colors.white,
child: Container(
height: 60,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Flexible(
flex: 2,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(
left: 5, top: 13),
child: AutoSizeText(
data[index].date,
maxFontSize: 12,
minFontSize: 7,
style: TextStyle(
color: Colors.black),
textAlign: TextAlign.left),
),
],
),
),
Flexible(
flex: 4,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
top: 13, left: 10),
child: Text(
data[index].title,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.black,
fontFamily: 'Montserrat'),
),
),
Row(
children: [
Flexible(
child: Padding(
padding:
EdgeInsets.only(left: 8),
child: AutoSizeText(
'${data[index].description}',
maxLines: 1,
style: TextStyle(
color: Colors.black,
fontStyle:
FontStyle.italic),
),
))
],
),
],
),
),
Expanded(
child: Row(
mainAxisAlignment:
MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerLeft,
child: AutoSizeText(
'\$${data[index].amount}',
maxLines: 1,
style: TextStyle(
color: Colors.black),
textAlign: TextAlign.left),
)
],
),
)
],
)),
),
));
},
))
]);
}));
}
So you are adding extra padding in your elements in the listview that you need to add to the titles:
padding:
EdgeInsets.only(left: 6), // add margin to accomplish offsetting the labels the same as the items
So now in the titles you can add either padding or margin for 8 to the left. This only applies to the first two though. So for the final one you can do this:
Flexible(
flex: 2,
child: Container(
alignment: Alignment.end, // changed from center to end
margin: EdgeInsets.only(right:8), // add the right margin
child: Text(
"Amount",
maxLines: 1,
style: TextStyle(
color: Colors.green, fontFamily: 'Montserrat'),
also just a friendly piece of advice is that you are making this a whole lot more complicated on your self than needed. The above answers your question but I would consider trying to clean up your code so future questions/problems are easier to identify.

Flutter layout: how to expand widget vertically

I am struggling to understand how to layout my widget so that they are occupying the entire yellow space. More specifically I would like that the "hero' and the "boss" widget expand to occupy the available space on screen (excluding the keyboard)
My current code achieve the following result
I would like to get the following result below
Here is my code. I have used resizeToAvoidBottomInset: true to ensure the widget is resized with the keyboard popping up
Widget build(BuildContext context) {
return Container(
child: Scaffold(
resizeToAvoidBottomInset: true,
backgroundColor: kColorPrimary,
appBar: AppBar(
backgroundColor: kColorPrimaryLight,
title: Text('Time to Spell'),
),
body: ModalProgressHUD(
inAsyncCall: showSpinner,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
height: 100,
color: Colors.amberAccent,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
color: Colors.blue,
child: Text(
result,
textAlign: TextAlign.center,
style: kTitleTextStyle,
),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.blue,
child: Text(
'Timer: 2:00',
textAlign: TextAlign.center,
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: Container(
height: 279,
color: Colors.purple,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.white,
child: Text(
'Hero',
textAlign: TextAlign.center,
),
),
),
),
),
Expanded(
child: Container(
height: 279,
color: Colors.greenAccent,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.white,
child: Text(
'Boss',
textAlign: TextAlign.center,
),
),
),
),
),
],
),
],
),
),
),
],
),
),
))));
}
Try this. I have added comments as well. Feel free to comment if anything is not clear.
#override
Widget build(BuildContext context) {
return SafeArea(
child: Container(
color: Colors.amberAccent,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
color: Colors.blue,
child: Text(
"Click start",
textAlign: TextAlign.center,
),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.blue,
child: Text(
'Timer: 2:00',
textAlign: TextAlign.center,
),
),
),
],
),
Expanded(
child: Row(
children: <Widget>[
//child 1 of row takes half of the space
Expanded(
child: Column(
children: <Widget>[
//expanding the container to the bottom
Expanded(
child: Container(
//maximizing the width of the container
width: double.infinity,
color: Colors.purple,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.white,
child: Text(
'Hero',
textAlign: TextAlign.center,
),
),
),
),
),
],
),
),
//child 2 of row takes half of the space
Expanded(
child: Column(
children: <Widget>[
//expanding the container to the bottom
Expanded(
child: Container(
//maximizing the width of the container
width: double.infinity,
color: Colors.greenAccent,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.white,
child: Text(
'Boss',
textAlign: TextAlign.center,
),
),
),
),
),
],
),
),
],
),
),
],
),
),
);
}

Flutter Dropdownbutton widget not opening

I've added a dropdownbutton widget to my view and when I top on the control, it doesn't open to display the available values.
I've even tried to use sample code and it's still not showing. This widget is within a SingleChildScrollView. I changed it to container to see if it was a scroll issue, but that didn't even work.
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: DropdownButton(
elevation: 2,
value: 'One',
onChanged: (val){
print(val);
},
hint: Text(
"Select the leach",
style: TextStyle(
color: Colors.black,
),
),
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
})
.toList()
)
),
When clicking/tapping on the control, it should show up, but I'm not sure what I'm missing that would cause it to not show the values.
I'm not seeing any errors in the logs (at least the logs i'm familiar with)
UPDATED WITH MORE CODE:
SafeArea(
child: Scaffold(
appBar: AppBar(
title: Hero(
tag: widget.film.title + widget.film.number,
child: Material(
type: MaterialType.transparency,
child: Text(
widget.film.title,
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold,
),
),
),
),
),
body:
Container(
//color: Colors.white,
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
physics: new AlwaysScrollableScrollPhysics(),
controller: _controller,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Stack(
overflow: Overflow.visible,
children: <Widget>[
MeetNetworkImage(
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
imageUrl: widget.film.backdrop != null ? "https://image.tmdb.org/t/p/w400/" + widget.film.backdrop : "",
loadingBuilder: (context) => Center(
child: CircularProgressIndicator(),
),
errorBuilder: (context, e) => Center(
child: FadeInImage(
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
image: AssetImage('assets/images/placeholder.png'),
placeholder:
AssetImage('assets/images/placeholder.png'),
),
),
),
Positioned(
left: MediaQuery.of(context).size.width-60,
top: 10,
child: Container(
height: 40.0,
width: 50.0,
color: Colors.transparent,
child: new Container(
decoration: new BoxDecoration(
color: widget.film.checkedoutby == null ? Colors.green : Colors.red,
borderRadius: new BorderRadius.all(Radius.circular(10))),
child: new Center(
child: new Text(widget.film.number, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0),),
)),
),
),
Positioned(
top: 180,
left: 15,
child: Container(
height: 200.0,
//color: Colors.grey[200],
child: MeetNetworkImage(
fit: BoxFit.contain,
imageUrl: widget.film.poster != null
? "https://image.tmdb.org/t/p/w200/" + widget.film.poster
: "",
loadingBuilder: (context) => Center(
child: CircularProgressIndicator(),
),
errorBuilder: (context, e) => Center(
child: FadeInImage(
fit: BoxFit.fill,
width: MediaQuery.of(context).size.width,
image:
AssetImage('assets/images/placeholder.png'),
placeholder:
AssetImage('assets/images/placeholder.png'),
),
),
),
),
),
Positioned(
left: 155,
top: 225,
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Text(
'Check Out',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: widget.users != null ?
DropdownButton(
elevation: 2,
value: widget.film.checkedoutby != null ? widget.film.checkedoutby : null,
onChanged: (val){
print(val);
},
hint: Text(
"Select the leach",
style: TextStyle(
color: Colors.black,
),
),
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
})
.toList())
),
],
),
),
Container(
padding: EdgeInsets.all(8.0),
alignment: FractionalOffset.centerLeft,
child: Wrap(
children: <Widget>[
Text(
'Rating -',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Text(
widget.film.rating,
style: TextStyle(
fontFamily: Constant.fontRegular,
color: Colors.grey[500]),
),
),
],
),
),
Container(
padding: EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Text(
'Duration -',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Text(
widget.film.runtime == null ? "" : widget.film.runtime,
style: TextStyle(
fontFamily: Constant.fontRegular,
color: Colors.grey[500]),
),
),
],
),
),
Container(
padding: EdgeInsets.all(8.0),
alignment: FractionalOffset.centerLeft,
child: Wrap(
children: <Widget>[
Text(
'Released -',
style: TextStyle(
fontFamily: Constant.fontRegular,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Wrap(
alignment: WrapAlignment.start,
children: <Widget>[
Text(
widget.film.released ?? "",
style: TextStyle(
fontFamily: Constant.fontRegular,
color: Colors.grey[500]),
)
],
),
)
],
),
),
],
),
),
Positioned(
top: 395,
left: 10,
width: MediaQuery.of(context).size.width-10,
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(child: Text(widget.film.plot)),
],
),
Divider(),
Wrap(
children: widget.film.genre
.split(',')
.map<Widget>(
(f) => Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Chip(
labelPadding:
EdgeInsets.symmetric(horizontal: 8.0),
label: Text(f,
style: TextStyle(
color: Colors.white,
fontFamily: Constant.fontMedium,
)),
backgroundColor:
Theme.of(context).primaryColor,
),
),
).toList(),
),
],
),
),
],
),
],
),
),
),
),
);
Not exactly sure why there is a difference in what I posted above and what the solution ended up being, but here's what I've changed the view to in order to get the dropdown popover to display.
As I was debugging, I broke it down bit by bit and noticed that when I added a container with a height to take up half the view, the popover would show, but clear at the bottom of that container, essentially pushing the top location of the dropdown's list, to the bottom of the container it was in. So I'm assuming the the popover that displays the list is 'showing', but below the container so it appears to not be working. Not sure why it would attach to the 'outside' of the main parent container, but that looks like this is what it is doing.
So....I changed the setup of the scaffolds body: property to be this instead:
SingleChildScrollView(
physics: new AlwaysScrollableScrollPhysics(),
controller: _controller,
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(
height: MediaQuery.of(context).size.height,
),
child: Stack(
.....