Flutter snackbar throws render overflow error when displaying multiple lines of text
361
Remove Expanded
and wrap Text
with Flexible
,
content: Row(
children: [
const Icon(
Icons.warning,
color: Colors.red,
size: 22,
),
const SizedBox(
width: 7,
),
Flexible(
child: Text(
errorMessage,
style: const TextStyle(
fontWeight: FontWeight.normal,
fontSize: 17,
color: Colors.red),
),
),
],
),
Author by
Sumchans
Updated on January 03, 2023Comments
-
Sumchans over 1 year
Is there a way to display multiple lines of text on a snackbar without it throwing a renderflex error?
I tried wrapping it with Flexible and Expanded widgets but both didn't help, I still get the error. The errorMessage received by the below method could be long sometimes.
void displayMessage(context, errorMessage) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Expanded( child: Row( children: [ const Icon( Icons.warning, color: Colors.red, size: 22, ), const SizedBox( width: 7, ), Text( errorMessage, style: const TextStyle( fontWeight: FontWeight.normal, fontSize: 17, color: Colors.red), ), ], ), ), backgroundColor: Colors.black, padding: const EdgeInsets.all(20), duration: const Duration(milliseconds: 5000), behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), ) ); }
-
Yeasin Sheikh over 2 yearsCan you include a demo image ? Removing
Expanded
works fine. -
Sumchans over 2 years@YeasinSheikh just added the image
-
-
Sumchans over 2 yearsI am still getting the same error after the modification
-
Yeasin Sheikh over 2 yearscheck update answer