I want to add an icon to the appBar of my flutter app but I get this error:
A RenderFlex overflowed by 399 pixels on the right.
I used AppIcon.com to create the different versions of the icon and AppIcon.com put the icons in the mipmap folder. I then copied those folders into my Flutter project.
Then, I copied the smallest version which is 72×72 to the directory where I point the appBar code to. Here is the appBar code:
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: Colors.blue,
automaticallyImplyLeading: false, // removes the back button in appbar
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset('lib/assets/images/dd_logo_building.png',
fit: BoxFit.cover, height: 56),
const Text(' Deal Diligence'),
],
),
actions: [
IconButton(
color: Colors.black,
onPressed: () {
signOut();
Navigator.push(context,
MaterialPageRoute(builder: (context) => const LoginScreen()));
},
icon: const Icon(Icons.logout),
)
],
);
}
}
Here is the entire error message:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 399 pixels on the right.
The relevant error-causing widget was:
Row Row:file:///C:/deal_diligence/deal_diligence/lib/screens/widgets/my_appbar.dart:29:14
To inspect this widget in Flutter DevTools, visit:
http://127.0.0.1:9100/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A53395%2Fg2EuruVAEB8%3D%2F&inspectorRef=inspector-7
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#317c3 relayoutBoundary=up14 OVERFLOWING:
creator: Row ← _AppBarTitleBox ← Semantics ← DefaultTextStyle ← MediaQuery ←
LayoutId-[<_ToolbarSlot.middle>] ← CustomMultiChildLayout ← NavigationToolbar ← DefaultTextStyle ←
IconTheme ← Builder ← CustomSingleChildLayout ← ⋯
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=312.7, 0.0<=h<=Infinity)
size: Size(312.7, 54.0)
direction: horizontal
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Reloaded 1 of 1519 libraries in 3,684ms (compile: 1922 ms, reload: 352 ms, reassemble: 703 ms).
D/EGL_emulation( 7691): app_time_stats: avg=1490.61ms min=1490.61ms max=1490.61ms count=1
Another exception was thrown: Unable to load asset: "lib/assets/images/dd_logo_building.png".
I have an older icon that is 72×72 that works so why won’t this icon work or how do I make it work?
Thanks
2
Answers
To avoid an overflow, just wrap the
Image.asset
with aFlexible
widget:You can try this if you want a more space in your appbar.