Flutter Web: Overflow issue in bottom - flutter

Code: Basically I have a simple app with three images aligned. I have 1 column and two rows. First row has two images and second row has 1 image aligned. Its the structure of the app. It just aligns perfectly when run below code in device but the moment I run on WEB there is this overflow. I try resizing the browser window only then it begins to become pretty again. Is there a workaround for Flutter Web please on how should I do the alignments here? Below code is inside body and inside Scaffold. I am attaching pics from device where there is no issue and from Flutter web where there is overflow issue.
return Column(
mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: FlatButton(
child: Image.asset('images/image1.png'),
),
),
Expanded(
child: FlatButton(
child: Image.asset('images/image1.png'),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: Image.asset('images/image1.png'),
),
],
),
],
);
}
Error:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ The
following assertion was thrown during layout: A RenderFlex overflowed
by 1238 pixels on the bottom.
The relevant error-causing widget was: Column
file:///C:/Users/1025632/Documents/GitHub/flutter-course/diceylips/lib/main.dart:43:12
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#1ad1e
relayoutBoundary=up1 OVERFLOWING: creator: Column ← DicePage ←
_BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ←
CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#cb60e ink renderer] ← NotificationListener ←
PhysicalModel ← ⋯ parentData: offset=Offset(0.0, 56.0); id=_ScaffoldSlot.body (can use size) constraints:
BoxConstraints(0.0<=w<=1280.0, 0.0<=h<=554.0) size: Size(1280.0,
554.0)
direction: vertical
mainAxisAlignment: center
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
Image with no issue in device
Image with overflow issue in chrome

Wrap the column with a sized box or container with defined height and width
SizedBox(
height:200,
width:200,
child: your column goes here,
)

Add below code inside Container
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
....
....
)
This is the generic way to define full width and height to your Container

If you don't try to fit your widget in screen and scroll is an option for you, you can use listview or a similar widget.
ListView(
children: <Widget>[
Column(
Otherwise, wrapping Container with MediaQuery.of(context).size.width and MediaQuery.of(context).size.height will work but there is just one catch here, if you use an appbar this height should be "MediaQuery.of(context).size.height - AppBar().preferredSize.height"

Related

ListView and Expanded not work in flutter

I need help to solve this problem. The expanded renders the child but does not expand.
return Scaffold(
body: ListView(
children: [
_HomeBody(child: child,)
],
)
);
_HomeBody
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height
child: Column(
children: [
AppBarMenu(),
Expanded(child: child), // A RenderFlex overflowed by 1246 pixels on the bottom.
Footer()
],
),
);
Error Output
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 1246 pixels on the bottom.
The relevant error-causing widget was:
Column
lib\…\views\home_view.dart:19
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#90f9f OVERFLOWING:
needs compositing
creator: Column ← ConstrainedBox ← Container ← HomeView ← Builder ←
RepaintBoundary-[GlobalKey#97a2c] ← IgnorePointer ← AnimatedBuilder ← FractionalTranslation ←
SlideTransition ← AnimatedBuilder ← RepaintBoundary ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(w=966.0, h=840.0)
size: Size(966.0, 840.0)
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: start
textDirection: ltr
verticalDirection: down
HomeLayout code
child code
You can't have Expanded inside of a scrolling view (SignleChildScrollView, ListView, etc..)
cause like this you are telling the child of the expanded to take of the whole vertical space allowed to you, and the scroll view can allow infinite vertical space, so in a nutshell, you are telling the child of the Expanded take the size of infinity. hope this clarifies the error

Flutter/Dart - A RenderFlex overflowed by 99804 pixels on the bottom

Can anybody see why I'm getting this error on the first child: Column? I'm using a stack in my build. and tried wrapping each widget in a Flexible widget but can't figure out where the code is overflowing. The screen flashes the telltale yellow/black renderflex lines for just a second but then seems to render just fine. The messages in the console are annoying though as is the little yellow/black flash at the beginning.
A RenderFlex overflowed by 99804 pixels on the bottom.
The relevant error-causing widget was:
Column file:///E:/FlutterProjects/myproject/lib/builders/CustomPageView.dart:47:26
Here's the code. Line 47 is the first child: column.
class _CustomPageViewState extends State<CustomPageView> {
Widget build(context) {
return PageView.builder(
itemCount: widget.speakcrafts.length,
itemBuilder: (context, int currentIndex) {
return createViewItem(widget.speakcrafts[currentIndex], context);
},
);
}
Widget createViewItem(SpeakContent speakcraft, BuildContext context) {
var contsize = MediaQuery.of(context).size.width * 0.60;
var contHeightsize = MediaQuery.of(context).size.height;
return Stack(
children: <Widget>[
Container(
color: Colors.black12,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.network(
speakcraft.gavatar,
height: contsize,
width: contsize,
),
PlayerWidget2(url: kUrl),
],
),
),
],
),
),
],
);
And here's the full error code with chunhunghan's ConstrainedBox suggestion;
A RenderFlex overflowed by 99325 pixels on the right.
The relevant error-causing widget was:
Row file:///E:/FlutterProjects/speakoholic/lib/builders/CustomPageView.dart:121:25
The specific RenderFlex in question is: RenderFlex#d5393 relayoutBoundary=up8 OVERFLOWING
parentData: offset=Offset(0.0, 556.9); flex=null; fit=null (can use size)
constraints: BoxConstraints(0.0<=w<=674.9, 0.0<=h<=Infinity)
size: Size(674.9, 100000.0)
direction: horizontal
mainAxisAlignment: center
mainAxisSize: max
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
child 1: RenderErrorBox#d3900
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(unconstrained)
size: Size(100000.0, 100000.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════════════════════════
A RenderFlex overflowed by 100385 pixels on the bottom.
The relevant error-causing widget was:
Column file:///E:/FlutterProjects/speakoholic/lib/builders/CustomPageView.dart:49:28
It turns out I had to follow the error further down the widget tree of this widget;
child: PlayerWidget2(url: kUrl))
Within PlayerWidget2 was a path that was null prior to a PageViewBuilder being built. This threw a null path error which lead to the renderflex error. Once built, the null was filled in with a path. So in order to get rid of the errors I simply added a default path to the widget to fill in the null until the PageViewBuilder was built.
you can wrap your whole body content as a child of SingleChildScrollView SinglechildScrollView widget which may help you to overcome from this issue,or you can also make use of listview which can arrange list of widgets properly ListView

Flutter drawer test errors with "A RenderFlex overflowed by 188 pixels on the right."

I am writing some tests for my app. Currently I am stuck on testing the drawer. On emulators of various sizes it runs without a problem (from 240x432 to 1440x2960) but when I try to run a simple test the following error is thrown:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 188 pixels on the right.
The overflowing RenderFlex has an orientation of Axis.horizontal.
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#1ae2c relayoutBoundary=up17 OVERFLOWING:
creator: Row ← Center ← Padding ← Container ← IconTheme ← Builder ← Listener ← _GestureSemantics ←
RawGestureDetector ← GestureDetector ← Listener ← InkWell ← ⋯
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=256.0, 0.0<=h<=Infinity)
size: Size(256.0, 24.0)
direction: horizontal
mainAxisAlignment: start
mainAxisSize: min
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Within the code I have narrowed it down to some RaisedButtons. When the Row within is below a certain length, the error doesn't show.
When I comment out the following code, ALL tests run without an issue.
Padding(
padding: EdgeInsets.symmetric(vertical: 32, horizontal: 16),
child: Column(
children: [
FacebookSignInButton(
onPressed: _fbLogin,
),
GoogleSignInButton(
onPressed: _googleLogin,
)
],
crossAxisAlignment: CrossAxisAlignment.stretch,
))
Changing the text within ("Continue with Facebook", "Sign in with Google") to something shorter also fixes this.
The test (note I'm currently just trying to not error, asserts will be put in once I get this figured out)
testWidgets("Drawer",
(WidgetTester tester) async {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
BuildContext savedContext;
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
savedContext = context;
return Scaffold(
key: _scaffoldKey,
drawer: HomePageDrawer(),
body: Container(),
);
},
),
),
);
await tester.pump(); // no effect
_scaffoldKey.currentState.openDrawer();
await tester.pump();
});

Expand area of CupertinoNavigationBar leading

I am using CupertinoNavigationBar to make a layout expected like image below
In left side/leading area, I override default back button to create the layout, but instead I got an overflow
return CupertinoPageScaffold(
...
leading: Row(
children: <Widget>[
UtomoDeckNavigationBar.getDefaultBackButton(context: context, isLightTheme: true),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(widget.chat.name,
style: TextStyle(
color: CupertinoColors.black,
fontWeight: FontWeight.bold,
fontSize: 14.0)),
Text('Online',
style: TextStyle(color: CupertinoColors.black, fontSize: 12.0))
],
)
],
)
)
and the error
Performing hot reload...
Syncing files to device iPhone SE...
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during layout:
flutter: A RenderFlex overflowed by 34 pixels on the right.
flutter:
flutter: The overflowing RenderFlex has an orientation of Axis.horizontal.
flutter: The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
flutter: black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
flutter: Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
flutter: RenderFlex to fit within the available space instead of being sized to their natural size.
flutter: This is considered an error condition because it indicates that there is content that cannot be
flutter: seen. If the content is legitimately bigger than the available space, consider clipping it with a
flutter: ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
flutter: like a ListView.
flutter: The specific RenderFlex in question is: RenderFlex#d650f relayoutBoundary=up2 OVERFLOWING:
flutter: creator: Row ← IconTheme ← Builder ← Padding ← KeyedSubtree-[GlobalKey#fab21 Leading] ←
flutter: LayoutId-[<_ToolbarSlot.leading>] ← CustomMultiChildLayout ← NavigationToolbar ← Padding ←
flutter: MediaQuery ← Padding ← SafeArea ← ⋯
flutter: parentData: offset=Offset(16.0, 0.0) (can use size)
flutter: constraints: BoxConstraints(0.0<=w<=90.7, h=44.0)
flutter: size: Size(90.7, 44.0)
flutter: direction: horizontal
flutter: mainAxisAlignment: start
flutter: mainAxisSize: max
flutter: crossAxisAlignment: center
flutter: textDirection: ltr
flutter: verticalDirection: down
flutter: ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Reloaded 11 of 687 libraries in 407ms.
Can I expand the constraint of the leading area, or maybe there's a better approach to do this?
Thank you.
to solve this, I use Row with MainAxisAlignment.start inside middle instead of leading.
EDIT :
Use Container with infinity width instead of Row, its children will overflow if its children widgets are more than the parent (Row), and TextOverflow.ellipsis won't help
I will tell you what worked for me. First, You should wrap your Container in a Flexible to let your Column know that it's ok for the Container to be narrower than its intrinsic width. Second, add overflow: TextOverflow.ellipsis for the ... Triple point.

Flutter: Clip a Column or Row to prevent overflow

I have a layout structure in Flutter like this:
Inkwell
Card
ScopedModelDescendant
Column
Container[]
The number of containers in the column is variable.
The goal is that it should look like this:
But instead, it ends up doing this:
I've tried adding a clipBehavior property to the Card, and I've tried mixing in ClipRects anywhere in the structure, but nothing seems to work. My best guess is that a ClipRect above the Column doesn't help because the overflow happens within the column.
This is the error I'm getting:
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following message was thrown during layout:
flutter: A RenderFlex overflowed by 15 pixels on the bottom.
flutter:
flutter: The overflowing RenderFlex has an orientation of Axis.vertical.
flutter: The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
flutter: black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
flutter: Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
flutter: RenderFlex to fit within the available space instead of being sized to their natural size.
flutter: This is considered an error condition because it indicates that there is content that cannot be
flutter: seen. If the content is legitimately bigger than the available space, consider clipping it with a
flutter: ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
flutter: like a ListView.
flutter: The specific RenderFlex in question is:
flutter: RenderFlex#094c9 OVERFLOWING
flutter: creator: Column ← ScopedModelDescendant<EventModel> ← Semantics ← DefaultTextStyle ←
flutter: AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#5fe8b ink renderer] ←
flutter: NotificationListener<LayoutChangedNotification> ← CustomPaint ← _ShapeBorderPaint ← PhysicalShape
flutter: ← _MaterialInterior ← Material ← ⋯
flutter: parentData: <none> (can use size)
flutter: constraints: BoxConstraints(w=56.0, h=104.3)
flutter: size: Size(56.0, 104.3)
flutter: direction: vertical
flutter: mainAxisAlignment: start
flutter: mainAxisSize: max
flutter: crossAxisAlignment: stretch
flutter: verticalDirection: down
flutter: ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Wrap widget solves your problem. If there is not enough space to fit the child in a Column or Row, you can use Wrap. You can use alignment, directionality and spacing properties to customize it.
Here is the simple example:
class WrapExample extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
width: 200,
height: 180,
child: Card(
clipBehavior: Clip.antiAlias,
child: Wrap(
direction: Axis.horizontal,
spacing: 8.0, // gap between adjacent chips
runSpacing: 4.0, // gap between lines
children: <Widget>[
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('AH')),
label: Text('Hamilton'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('ML')),
label: Text('Lafayette'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('HM')),
label: Text('Mulligan'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('JL')),
label: Text('Laurens'),
),
],
),
),
);
}
}
And here is the output:
You can also just wrap the widget you want to allow overflowing in a Positioned inside a Stack widget and set the the Positioned parameter top: 0.
Works like charm for me