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),
),
)
);
}
CodePudding user response:
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),
),
),
],
),

