i want when the user click to float action button, then a bottom sheet opened. the bottom sheet includes input text field and three radios. when i click on input text field, this error occurs:
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be
seen. If the content is legitimately bigger than the available space, consider clipping it with a
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#86450 OVERFLOWING:
needs compositing
creator: Column ← DecoratedBox ← ConstrainedBox ← Container ←
NotificationListener ← DefaultTextStyle ←
AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#39284 ink renderer] ←
NotificationListener ← PhysicalModel ← AnimatedPhysicalModel ←
Material-[GlobalKey#6e766 BottomSheet child] ← ⋯
parentData: (can use size)
constraints: BoxConstraints(w=360.0, h=185.0)
size: Size(360.0, 185.0)
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
the code is:
floatingActionButton: InkWell(
onTap: () {
// Sizer
// Navigator.of(context).
// Navigator.of(context)
// .push(MaterialPageRoute(builder: (context) => const AddNote()));
// scaffoldKey.currentState!.showBottomSheet((context) => null)
_scaffoldKey.currentState!.showBottomSheet(
(context) => Container(
height: 70.h,
width: double.infinity,
// Sizer
decoration: const BoxDecoration(
// shape: BoxShape.rectangle,
color: Color(pagesBackgroundColor),
boxShadow: [BoxShadow(color: Color(pagesBackgroundColor))],
borderRadius: BorderRadius.only(
topRight: Radius.circular(15),
topLeft: Radius.circular(15),
),
),
// DraggableScrollableSheet(
// builder: (context,scrollableController) {
// return
child: Column(
children: [
Container(
width: 15.w,
// clipBehavior: Clip.antiAliasWithSaveLayer,
height: 1.5.w,
margin: EdgeInsets.only(top: 2.h),
decoration: const BoxDecoration(
// shape: BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular(2.0)),
color: Color(greyColor),
// boxShadow:[ BoxShadow(color: )],
),
// child: const Divider(
// thickness: 3,
// ),
),
Padding(
padding: EdgeInsets.only(left: 2.w),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(
"Add new note",
style: Theme.of(context).textTheme.headline1,
// strutStyle: ,
),
),
),
],
),
),
//TODO make note text
//max line == 4
//using package AutoSizeText
SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 1.h),
child: AutoSizeTextField(
textAlign: TextAlign.justify,
cursorRadius: Radius.circular(2.w),
// scrollPadding: EdgeInsets.all(0),
cursorColor: const Color(accentColor),
controller: _textEditingController,
minLines: 1,
maxLength: 150,
maxLines: 4,
// smartDashesType: ,
// wrapWords: true,
),
),
ListTile(
title:
Text(AppLocalizations.of(context)!.homeTodayTap),
leading: Radio(
value: 1,
groupValue: 1,
onChanged: (value) {
// setState(() {
// _site = value;
// });
},
),
),
ListTile(
title: Text(
AppLocalizations.of(context)!.homeTomorowTap),
leading: Radio(
value: 2,
groupValue: 1,
onChanged: (value) {
// setState(() {
// _site = value;
// });
},
),
),
ListTile(
title: Text(
AppLocalizations.of(context)!.homeSomeDayTap),
leading: Radio(
value: 2,
groupValue: 1,
onChanged: (value) {
// setState(() {
// _site = value;
// });
},
),
),
],
),
),
// ],
// );
// }
]),
),
);
},
// for icon shape
child: Container(
clipBehavior: Clip.antiAliasWithSaveLayer,
height: 11.h,
width: 10.h,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(1.w)),
color: const Color(accentColor),
),
// add note icone
child: Icon(
Icons.add,
color: Colors.white,
size: 9.h,
),
),
),
Put SingleChildScrollView under Expanded widget
return Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
TextFormField(...),
],
),
),
),
],
);
Related
My app works fine in debug mode but shows a grey screen in release mode. It is an E-Commerce app and the page that is getting me in trouble is my products Detail page . I have provided two images for you so that you can get the actual idea of what the error is.
Here is the Image of Debug ModeDebug Mode Image
Here is the Image of Release ModeRelease Mode Image
Here is My Error Log:-
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically, Flexible widgets are placed directly inside Flex widgets.
The offending Flexible is currently placed inside a ConstrainedBox widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
RepaintBoundary ← NotificationListener<ScrollNotification> ← GlowingOverscrollIndicator ← Scrollable ← PrimaryScrollController ← SingleChildScrollView ← Flexible ← ConstrainedBox ← Container ← _BodyBuilder ← ⋯
Here is my Code For You:-
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_application_1/pages/home.dart';
import 'package:flutter_application_1/products.dart';
class HomeDetailPage extends StatefulWidget {
const HomeDetailPage({
Key? key,
required this.singleitem,
}) : super(key: key);
final Item singleitem;
#override
State<HomeDetailPage> createState() => _HomeDetailPageState();
}
class _HomeDetailPageState extends State<HomeDetailPage> {
Future<bool> _previousroute() {
// important trick to handle backbutton press;
return Future(() => Navigator.canPop(context));
}
#override
Widget build(BuildContext context) {
// Variables for getting the height and width of the screen
double h = MediaQuery.of(context).size.height;
double w = MediaQuery.of(context).size.width;
return WillPopScope(
onWillPop: () => _previousroute(),
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
shadowColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
color: Colors.black,
onPressed: () {
Navigator.pop(context);
},
)),
// key: ProductsModel.scaffoldKey,
body: Container(
height: h,
child: Flexible(
fit: FlexFit.tight,
child: SingleChildScrollView(
padding: EdgeInsets.all(0.0),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipPath(
clipper: Clipper(),
child: Container(
decoration: BoxDecoration(
color: Color.fromARGB(255, 240, 240, 245),
),
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Hero(
tag: Key(widget.singleitem.id.toString()),
child: Image.network(widget.singleitem.image)),
),
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.singleitem.name,
style: TextStyle(
color: Colors.black,
fontSize: 30,
fontWeight: FontWeight.bold),
),
],
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
widget.singleitem.desc,
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.normal),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(left: 4.0, right: 4.0),
child: Container(
width: w,
// box decoration does not work with button
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(32.0)),
child: ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return Container(
child: AlertDialog(
actions: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Your Order Is On The Way",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold),
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
// Used to create ok button
Navigator.of(context).pop();
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(
Color.fromRGBO(
0,
0,
0,
1,
)),
shape: MaterialStateProperty
.all(RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(
16.0)))),
child: Text(
"Ok",
style: TextStyle(
fontSize: 20,
fontWeight:
FontWeight.bold),
),
),
)
],
)
],
));
});
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Color.fromRGBO(
0,
0,
0,
1,
)),
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
))),
child: Text(
"Buy",
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
),
),
),
),
)
],
),
),
),
),
),
);
}
}
class Clipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
// TODO: implement getClip
var path = new Path();
// fixed or unchanged points of the container
path.lineTo(0, 0);
path.lineTo(size.width, 0);
path.lineTo(size.width, size.height - 20);
path.quadraticBezierTo(
//point creating the curve radius
size.width / 2,
size.height + 20,
// starting point of the curve
0,
size.height - 20);
return path;
}
#override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
// TODO: implement shouldReclip
return false;
}
}
it's because you are using fixable as a child of container and it should be used with columns row ...etc your code will work in debug mode but in release it won't work so try my solution it will work
I'd like to have a listtile where the leading widget is simply a half-transparent white container. Let me clarify it with an example
I managed to create the layout above (2 ListTile's). But as you can see, when the title property contains a large text as it is doing in the first (the green) tile, the height of the leading widget is not following as it should. The below code returns a ListTile given a Label which is a class of my own that simply contains text, textcolor and backgroundcolor.
ListTile(
contentPadding: EdgeInsets.zero,
dense: true,
minLeadingWidth: 15,
tileColor: label.bgColor,
textColor: label.textColor,
horizontalTitleGap: 0,
minVerticalPadding: 0,
trailing: getPopUpMenuButton(label),
leading: Container(
height: double.maxFinite,
width: 15,
color: Colors.white54,
),
title: Padding(
padding: EdgeInsets.all(4),
child: Text(
label.title,
),
),
)
So to summarize: how to make the leading height follow the height of the ListTile?
ListTile provide the UI with specific rules. As for leading this Size is defined within the source code as
final BoxConstraints maxIconHeightConstraint = BoxConstraints(
//...
maxHeight: (isDense ? 48.0 : 56.0) + densityAdjustment.dy,
);
final BoxConstraints looseConstraints = constraints.loosen();
final BoxConstraints iconConstraints = looseConstraints.enforce(maxIconHeightConstraint);
final double tileWidth = looseConstraints.maxWidth;
final Size leadingSize = _layoutBox(leading, iconConstraints);
final Size trailingSize = _layoutBox(trailing, iconConstraints);
The height is coming from
maxHeight: (isDense ? 48.0 : 56.0) + densityAdjustment.dy,
We can create the custom widget using rows and column,
body: Center(
child: ListView.builder(
itemCount: 33,
itemBuilder: (context, index) => Padding( //use separate builder to and remove the padding
padding: const EdgeInsets.all(8.0),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.green,
borderRadius:
BorderRadius.circular(defaultBorderRadiusCircular),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 20,
),
Expanded(
child: Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.cyanAccent,
borderRadius: BorderRadius.only(
bottomRight:
Radius.circular(defaultBorderRadiusCircular),
topRight:
Radius.circular(defaultBorderRadiusCircular),
)),
child: Row(
children: [
Expanded(
child: Text(
"I managed to create the layout above (2 ListTile's). But as you can see, when the title property contains a large text as it is doing in the first (the green) tile, the height of the leading widget is not following as it should. The below code returns a ListTile given a Label which is a class of my own that simply contains text, textcolor and backgroundcolor.",
softWrap: true,
maxLines: 13,
style: TextStyle(),
),
),
Icon(Icons.menu),
],
),
),
),
],
),
),
),
),
),
I am trying to create a gridview starting from the second column. The first card is just a static card with a button in it. So the second card starting should be dynamic.
All the cards have the same width and height. So basically they all should look like the first card (Add a new dog)
But it's not filling out the space as I expected it would.
Here is part of my code from the body section:
body: Stack(fit: StackFit.expand, children: [
//bg image
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(Images.bgYellow), fit: BoxFit.cover)),
),
//content
SafeArea(
bottom: false,
left: true,
right: true,
top: false,
child: Padding(
padding: EdgeInsets.all(3 * SizeConfig.safeBlockHorizontal),
child: GridView.count(
crossAxisCount: 2,
children: [
//add card
Container(
margin: EdgeInsets.symmetric(
vertical: 1 * SizeConfig.blockSizeVertical,
horizontal: 2 * SizeConfig.blockSizeHorizontal),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 8,
offset: Offset(
0, 2), // changes position of shadow
),
],
),
child: FlatButton(
onPressed: null,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
const IconData(0xe901,
fontFamily: 'icDog'),
color: muddyBrown,
size: 20 * SizeConfig.safeBlockHorizontal,
),
SizedBox(height: 5),
Text(
"ADD A NEW DOG",
style: TextStyle(
color: muddyBrown,
fontWeight: FontWeight.bold,
fontSize: 4 *
SizeConfig.safeBlockHorizontal),
)
],
)),
),
//dynamic content
StateBuilder<PetState>(
observe: () => _petStateRM,
builder: (context, model) {
return Column(
children: [
...model.state.pets.map((pet) =>
GestureDetector(
onTap: () {
Navigator.pushNamed(
context, petDetailRoute);
},
child: Container(
margin: EdgeInsets.symmetric(
vertical: 1 *
SizeConfig
.blockSizeVertical,
horizontal: 2 *
SizeConfig
.blockSizeHorizontal),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(30),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey
.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 8,
offset: Offset(0,
2), // changes position of shadow
),
],
),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
//dynamic data => Photo + Name
children: [
Container(
width: 100.0,
height: 100.0,
decoration: new BoxDecoration(
color:
const Color(0xff7c94b6),
image: new DecorationImage(
image: new NetworkImage(
"${pet.photo}"),
fit: BoxFit.cover,
),
borderRadius:
new BorderRadius.all(
new Radius.circular(
50.0)),
border: new Border.all(
color: muddyBrown,
width: 4.0,
),
),
),
SizedBox(height: 5),
Text(
"${pet.name}",
style: TextStyle(
fontSize: 4 *
SizeConfig
.safeBlockHorizontal,
color: muddyBrown,
fontWeight:
FontWeight.bold),
)
],
),
),
))
],
);
}),
],
)
)),
]));
What about simply adding the 'static' card to the 'dynamic' ones and then build one GridView with all of them together?
Widget newDogButton = Card(...);
//dynamic content
StateBuilder<PetState>(
observe: () => _petStateRM,
builder: (context, model) {
return Column(
children: [
newDogButton,
...model.state.pets.map((pet) => // ...
That should take care of most of your layout issues automatically.
Because StateBuilder return a widget. How about moving the Whole GridView inside it?
...
child: Padding(
padding: EdgeInsets.all(3 * SizeConfig.safeBlockHorizontal),
child: StateBuilder<PetState>(
observe: () => _petStateRM,
builder: (context, model) {
return GridView.count(
crossAxisCount: 2,
children: [
// The button "ADD A NEW DOG" here,
Container(...),
//dynamic content here
...model.state.pets.map((pet) =>
...
).toList(),
},
),
),
Every grid item in GridView will have same height and width, if you want different dynamic height or width for different items, use flutter_staggered_grid_view, in your case:
StaggeredGridView.countBuilder(
crossAxisCount: 2,
itemCount: 2,
itemBuilder: (BuildContext context, int index) => new Container(
color: Colors.green,
child: new Center(
child: new CircleAvatar(
backgroundColor: Colors.white,
child: new Text('$index'),
),
)),
staggeredTileBuilder: (int index) =>
new StaggeredTile.count(1, index.isEven ? 2 : 1),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
)
The situation:
To me, this problem is not coming from your Dynamic content but from the height allowed to it to display it's content. Inside the GridView.count constructor, the default childAspectRatio value is 1.0, meaning that the default max height of each child of the GridView is deviceWidth / crossAxisCount (2 in your case).
The problem:
In order for each child to display correctly, it's height must not exceed this ratio (causing your overflowed error).
My opinion:
To solve this problem, I will either replace the dynamic content StateBuilder<PetState> with a static Widget which height will not exceed the ratio OR wrap the dynamic content StateBuilder<PetState> in a SingleChildScrollView to ensure that the overflowed error will not happen and the wrapper can produce the scroll effect to see the entire dynamic content.
i have the following AlertDialog widget that behaves as following :
and here is my code :
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
title: Text(
"Information sur le client $code",
),
content: Container(
height: mobileHeight * 0.75,
width: mobileWidth * 0.9,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: IconButton(
icon: Icon(
Icons.edit,
color: Colors.blue,
size: mobileWidth * 0.05,
),
onPressed: () {
setState(() => modifyNom = !modifyNom);
_textNameController.text = snapshot.data.nom;
},
),
),
modifyNom
? Flexible(
child: TextField(
textAlign: TextAlign.center,
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
controller: _textNameController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.nom}',
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
),
),
],
),
Row(
children: [
Container(
child: IconButton(
onPressed: () {
setState(() => modifyContact = !modifyContact);
_textContactController.text = snapshot.data.contact;
},
),
),
Text(
'Contact : ',
),
modifyContact
? Flexible(
child: TextField(
textAlign: TextAlign.center,
controller: _textContactController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.contact}',
),
),
],
),
],
),
),
actions: [
FlatButton(
child: Text("Annuler"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
),
],
);
},
);
the issue is when i edit the TextField and the keyboard is shown i get this error :
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 211 pixels on the bottom.
The relevant error-causing widget was:
Column file:///C:/Users/asmou/AndroidStudioProjects/flutter_app/lib/Alerts/showAlertInfo.dart:49:28
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be
seen. If the content is legitimately bigger than the available space, consider clipping it with a
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#a3d43 OVERFLOWING:
needs compositing
creator: Column ← FutureBuilder<Client> ← ConstrainedBox ← Container ← DefaultTextStyle ← Padding ←
Flexible ← Column ← IntrinsicWidth ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#50b4d ink renderer] ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(w=283.4, h=173.1)
size: Size(283.4, 173.1)
direction: vertical
mainAxisAlignment: spaceBetween
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
Wrap the Container Widget with ListView or SingleChildScrollView.
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
title: Text(
"Information sur le client $code",
),
content: SingleChildScrollView(
child: Container(
height: mobileHeight * 0.75,
width: mobileWidth * 0.9,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: IconButton(
icon: Icon(
Icons.edit,
color: Colors.blue,
size: mobileWidth * 0.05,
),
onPressed: () {
setState(() => modifyNom = !modifyNom);
_textNameController.text = snapshot.data.nom;
},
),
),
modifyNom
? Flexible(
child: TextField(
textAlign: TextAlign.center,
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
controller: _textNameController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.nom}',
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
),
),
],
),
Row(
children: [
Container(
child: IconButton(
onPressed: () {
setState(() => modifyContact = !modifyContact);
_textContactController.text = snapshot.data.contact;
},
),
),
Text(
'Contact : ',
),
modifyContact
? Flexible(
child: TextField(
textAlign: TextAlign.center,
controller: _textContactController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.contact}',
),
),
],
),
],
),
),
),
actions: [
FlatButton(
child: Text("Annuler"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
),
],
);
},
);
My whole scaffold body was a Column widget, and I had a similar render overflow error when using AlertDialogs;
Based on the flutter error message ...or using a scrollable container rather than a Flex, like a ListView - I replaced Column for ListView and now I get no render overflow errors when using AlertDialog.
Inside build();
return Scaffold(
body: ListView( // formerly a Column()
// your remaining UI
),
),
I'm trying to make a UI where there are some text fields inside a container and there are some icon buttons which are always going to stay at the bottom.
Here is the code minimal code
Center(
child: Container(
// width: 1006,
constraints: BoxConstraints(
maxWidth: 1006,
maxHeight: sizingInformation.screenSize.height,
),
margin: EdgeInsets.only(
left: isMobile ? 0 : 34,
),
child: Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Flex(
// rest of the widgets
),
Expanded(
child: Container(
padding: EdgeInsets.all(isMobile ? 15 : 34),
margin: EdgeInsets.only(
top: isMobile ? 15 : 27,
),
constraints: BoxConstraints(
maxWidth: 1006,
),
height: 750,
decoration: BoxDecoration(
color: CARD_DARK_PURPLE,
borderRadius: BorderRadius.circular(8),
),
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Wrap(
direction: Axis.horizontal,
children: <Widget>[
Wrap(
direction: Axis.horizontal,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Pošiljalac",
style: TextStyle(
color: WHITE,
fontSize: isMobileTablet ? 22 : 24,
fontWeight: BOLD,
),
),
SizedBox(
height: 20,
),
_phoneInfo(widget.order.senderPhoneNumber, isMobile),
_emailInfo(widget.order.senderEmail, isMobile),
_fullNameInfo(widget.order.senderFirstName,
widget.order.senderLastName, isMobile, isMobileTablet),
_addressInfo(widget.order.senderStreetNumber, isMobile),
_zipCodeInfo(widget.order.senderZipCode, isMobile),
_cityInfo(widget.order.senderCity, isMobile),
SizedBox(
height: isDesktopLaptop ? 14 : 0,
),
_payeeInfo(isMobile, isMobileTablet),
],
),
SizedBox(
width: 34,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: isDesktopLaptop ? 482 : 10,
),
_weightInfo(isMobile, isMobileTablet),
_noteSmall(isMobile, isMobileTablet),
],
),
],
),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(height: 10),
Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(width: 20),
Material(
color: DIVIDER,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
child: Center(
child: Ink(
decoration: const ShapeDecoration(
color: DIVIDER,
shape: CircleBorder(),
),
child: IconButton(
splashColor: DARK_PURPLE.withOpacity(0.3),
icon: Image.asset(
'assets/images/inter-note-icon.png',
width: 20,
height: 24,
),
onPressed: () {
if (widget.order.operatorNote == "/") {
_dialogs.internNoteDialog(
context,
widget.order.id,
"order",
widget.order.operatorNote);
} else {
_dialogs.changeInternNoteDialog(
context,
widget.order.id,
"order",
widget.order.operatorNote);
}
},
),
),
),
),
SizedBox(width: 20),
Material(
color: DIVIDER,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
child: Center(
child: Ink(
decoration: const ShapeDecoration(
color: DIVIDER,
shape: CircleBorder(),
),
child: IconButton(
splashColor: DARK_PURPLE.withOpacity(0.3),
icon: Image.asset(
'assets/images/trash-icon.png',
width: 28,
height: 28,
),
onPressed: () {
_dialogs.deleteOrderDialog(
context, widget.order.id, isMobile);
},
),
),
),
),
],
),
],
),
),
],
),
),
),
),
),
),
)
This is the UI that I'm trying to achieve(the box highlighted on the right side specifically)
There is SingleChildScrollView parent which has Wrap as its child. SingleChildScrollView is taking the full height available but Wrap isn't spanning to that full height. I want to make the Wrap span full height so that the icons can stay at the bottom always.
So, I placed it inside Expanded as I thought it would make it expand to the full available height. But I got this error.
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a _SingleChildViewport widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Wrap ← Expanded ← _SingleChildViewport ← IgnorePointer-[GlobalKey#01401] ← Semantics ← _PointerListener ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#7427b] ← _PointerListener ← ⋯
When the exception was thrown, this was the stack
dart:sdk_internal 4461:11 throw_
packages/flutter/src/widgets/widget_span.dart.lib.js 12339:23 <fn>
packages/flutter/src/widgets/widget_span.dart.lib.js 12355:24 [_updateParentData]
packages/flutter/src/widgets/widget_span.dart.lib.js 12372:61 attachRenderObject
packages/flutter/src/widgets/widget_span.dart.lib.js 12184:12 mount
...
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
So, Expanded is not the answer to this. But I don't know what else is. I'm new to Flutter and having a hard time understanding the Flutter layout system. Any help would be great. Thanks for your time.
What if you make your Wrap widget the child of a container the size of the screen ?
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Wrap(
children: [],
))),
);
}
}