Flutter app expanding behind navigation bar - flutter

After hours of trial and error, I gave up.
Can somebody tell me why my app is expanding behind the virtual navigation buttons?
I tried swiching and inserting SafeArea, Flex, Expanded and so on but have not found which Widget is creating this behaviour.
My Code:
Widget build(BuildContext context) {
return Scaffold(
body: Column(
// direction: Axis.vertical,
children: [
Expanded(
flex: 1,
// child:Text("test text", style: TextStyle(backgroundColor: Colors.blue),)
child: Container(
// color: Colors.red,
alignment: Alignment.centerRight,
// padding: EdgeInsets.all(0),
child: TextField(
controller: _input_controller,
decoration: const InputDecoration(
focusedBorder: InputBorder.none,
border: InputBorder.none,
),
style: TextStyle(fontSize: _font_size),
textAlign: TextAlign.right,
showCursor: false,
readOnly: true,
// decoration: InputDecoration(labelText: "Enter your number"),
// keyboardType: TextInputType.number,
// inputFormatters: [
// // FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
// // FilteringTextInputFormatter.allow(RegExp(r"[.,']")),
// CardFormatter
// ], // Only numbers can be entered
)),
),
Expanded(
flex: 1,
// child:Text("test text", style: TextStyle(backgroundColor: Colors.blue),)
child: Container(
// color: Colors.red,
alignment: Alignment.centerRight,
// padding: EdgeInsets.all(0),
child: TextField(
controller: _answer_controller,
decoration: const InputDecoration(
focusedBorder: InputBorder.none,
border: InputBorder.none,
),
style: TextStyle(fontSize: _font_size),
textAlign: TextAlign.right,
showCursor: false,
readOnly: true,
// decoration: InputDecoration(labelText: "Enter your number"),
// keyboardType: TextInputType.number,
// inputFormatters: [
// // FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
// // FilteringTextInputFormatter.allow(RegExp(r"[.,']")),
// CardFormatter
// ], // Only numbers can be entered
)),
),
Expanded(
flex: 4,
// child:Text("test text", style: TextStyle(backgroundColor: Colors.green),)
child: GridView.count(
crossAxisCount: 4,
// padding: const EdgeInsets.all(0.2),
mainAxisSpacing: 0,
crossAxisSpacing: 0,
children: List.generate(
20,
(i) => Container(
child: TextButton(
onPressed: () {
print(i);
},
child: Text(i.toString()),
),
))),
)
],
),
);
} crossAxisSpacing: 0,
children: List.generate(
20,
(i) => Container(
child: TextButton(
onPressed: () {
print(i);
},
child: Text(i.toString()),
),
)),
),
)
],
),
),
),
),
);
}

The issue is your screen height doesn't cover the Full widget height. That's why the GridView is behind the screen. If you scroll down, you will get the rest of the button. You can play with childAspectRatio to reduce the height.
If you like to have everything in withing screen, you can use Stack and LayoutBuilder to measure the screen size. But it is nice to have scroll-effect for small screen but I will prefer full scroll body, In that case you can use SingleChildScrollView on body and NeverScrollableScrollPhysics() on gridView.
You can check my repo I was testing year ago.

As always, when you ask, you get the answer shortly after by yourself (with a hint from Chance)
Putting GridView inside Expanded causes this behaviour, if you put GridView inside a Container you get an assertion error, add shrinkWrap: true to the Constructor of GridView and everything works as expected:
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(flex: 1, child: Text("Text1")),
Expanded(flex: 1, child: Text("Text1")),
Container(
child: GridView.count(
crossAxisCount: 4,
mainAxisSpacing: 0,
crossAxisSpacing: 0,
shrinkWrap: true,
children: List.generate(
20,
(i) => Container(
child: TextButton(
onPressed: () {
print(i);
},
child: Text(i.toString()),
),
))),
)
],
));
}

Related

flutter textfield with tags overflow issue

I am trying to create a textfield in which on text change I render a list of items if I click on any of the item I am adding it in front of textfield but if I add multiple tags it gives overflow error I want to increase the size of textfiled vertically. Here is the piece of code :
///TEXTFIELD
SliverToBoxAdapter(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: AppColor.medGrey, width: 1.5))),
child: Row(
children: [
Obx(
() => symptomsController.addedSymptoms.isEmpty
? Container()
: Container(
padding:
EdgeInsets.symmetric(horizontal: 10),
child: Wrap(
runAlignment: WrapAlignment.start,
crossAxisAlignment:
WrapCrossAlignment.start,
spacing: 3.0,
children: List.generate(
symptomsController
.addedSymptoms.length,
(index) => Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(20),
color: Colors.brown
.withOpacity(0.95)),
margin: EdgeInsets.symmetric(
vertical: 2),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
///SYMPTOM NAME
Container(
child: Text(
"${symptomsController.addedSymptoms[index].commonName}",
overflow: TextOverflow
.ellipsis,
maxLines: 1,
style: AppTextStyle
.h6Bright),
),
///SPACE
SizedBox(
width: 4,
),
InkWell(
onTap: () {
symptomsController
.searchedList
.add(symptomsController
.addedSymptoms[
index]);
symptomsController
.addedSymptoms
.removeAt(index);
},
child: Icon(
Icons
.remove_circle_outline,
color: Colors.white,
size: 16,
),
)
],
),
),
),
),
),
),
),
Expanded(
child: TextField(
controller:
symptomsController.searchQuery.value,
cursorColor: AppColor.highMedGrey,
onChanged: (String query) {
symptomsController.searchString.value =
query;
},
onSubmitted: (String query) {
if (symptomsController
.searchQuery.value.text.length ==
0) {
///CLEAR LIST OF SYMPTOMS
// symptomsController.searchedList.clear();
return;
} else {
///CLEAR PREVIOUS LIST OF SYMPTOMS
symptomsController.searchedList.clear();
///START LOADING
symptomsController.loading.value = true;
///SEARCH
symptomsController.searchSymptom();
}
},
textInputAction: TextInputAction.search,
style: AppTextStyle.h4,
maxLines: 1,
maxLength: 25,
decoration: InputDecoration(
border: InputBorder.none,
counterText: "",
hintText: "Search",
hintStyle: AppTextStyle.h4,
)),
),
],
)),
),
Something like added image.. I want to increase the size vertically...Thanks in advance
Have you tried increasing the maximum row name for the TextField(). Make sur for it

How to align copy, paste tool tip in TypeAheadFormField

I have used TypeAheadFormField with enableInteractiveSelection is true. I tried to type multiple lines of text, then try to select and copy, I got the copy, paste tooltip going to the top of the screen. I am unable to control the tooltip alignment. How can I fix this?
Here I have attached the screen as well as the code.
Expanded(
child: Container(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: 25,
maxHeight: 100.0,
),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Padding(
padding: const EdgeInsets.only(
left: 5, bottom: 3),
child: TypeAheadFormField(
direction: AxisDirection.up,
textFieldConfiguration:
TextFieldConfiguration(
enableInteractiveSelection: true,
controller: txtController,
focusNode: txtFocus,
textInputAction:
TextInputAction.newline,
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration.collapsed(
hintText: "Type a message",
),
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter the message';
}
return null;
},
),
),
),
),
),
),

Placing the cursor at the top left of a vertically stretched TextField?

I'm trying to make a page through which the user can create a note for my Notes app. This is my build method so far:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add Note"),
actions: <Widget>[
FlatButton(
child: Icon(
Icons.save,
color: Colors.white,
),
)
],
),
body: Center(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
TextField (
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Title",
),
textCapitalization: TextCapitalization.words,
),
SizedBox(
height: 16,
),
Expanded(
child: Container(
child: TextField (
expands: true,
maxLines: 25,
decoration: InputDecoration(
border: OutlineInputBorder(),
),
),
),
)
],
),
),
)
);
}
This is how the page looks right now. How do I ensure that the cursor of the second TextField is placed at the top left and make said TextField stretch to fit the remaining height?
You should set the textAlign property of the TextField to start
textAlign: start
Edit:
based on #Andy_519's and community input please use the following
textAlignVertical: top

List menu scrolling without IgnorePointer

I created a menu list with GridView. But when I scroll, it fail because scroll inside listview hold parent element to scroll like this image
My issue is gone when I try to wrap my GridView inside IgnorePointer. But if I use IgnorePointer it is not allow me to click / tap my menu item.
How the best way to fix my issue?
My code (without IgnorePointer)
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 10.0, bottom: 10.0),
width: MediaQuery.of(context).size.width,
child: GridView.count(
shrinkWrap: true,
crossAxisCount: 4,
children: List.generate(
menuItems.length,
(index) {
return Column(
children: <Widget>[
InkWell(
onTap: () {
showShortToast("Menu clicked " + index.toString());
},
child: Container(
width: 70.0,
height: 70.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
border: Border.all(color: Colors.grey[300]),
),
child: Center(
child: Image.asset(menuItems[index]["image"]),
),
),
),
Expanded(
child: Text(
menuItems[index]["text"],
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 13.0,
),
),
),
],
);
},
),
),
);
}
If you want to disable the scroll in the grid view you can do as follows:
child: GridView.count(
physics: NeverScrollableScrollPhysics(), //Add physics
shrinkWrap: true,
crossAxisCount: 4,
...

Creating TextField list

I want to create a list that users want how many include TextField with initial count is two and buttons when pressed adding one more, another when clicked clearing all fields. Then, calculate standard deviation from inputs . What is the best way achieve this ? Make a custom Row widget ? With List widget or ListView.builder widget ?
children: <Widget>[
Flexible(
fit: FlexFit.tight,
flex: 5,
child: FractionallySizedBox(
widthFactor: 0.9,
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder()
),
controller: count,
),
),
),
Flexible(
fit: FlexFit.tight,
flex: 3,
child: FractionallySizedBox(
widthFactor: 0.9,
child: RaisedButton(
child: Text("Press here"),
padding: EdgeInsets.symmetric(vertical: 20),
onPressed: () {
fi = int.parse(count.text);
setState(() {});
},
),
),
),
],
),
),
fi == null
? Offstage()
: ListView.builder(
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.all(10),
shrinkWrap: true,
itemCount: fi,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: index.toString()
),
),
);
},
),
],
),
),
),
); }}
You can do like this whenever you want to render dynamic textfield then you have to follow like above code thanks