I have wrapped 3 Text in Row, but get exceptions. How can I make them displayed multiple line ?
Row(children: [
Text("this is text 1 bla bla bla"),
Text("this is text 2 bla bla bla"),
Text("this is text 3 bla bla bla"),
],),
Error
════════ Exception caught by rendering library ═════════════════════════════════
A RenderFlex overflowed by 26 pixels on the right.
The relevant error-causing widget was
Row
You can use Flexible to solve this
Row(children: [
Flexible(child: Text("this is text 1 bla bla bla")),
Flexible(child: Text("this is text 2 bla bla bla")),
Flexible(child: Text("this is text 3 bla bla bla")),
])
Or you can use Wrap to show as a grid
Wrap(children: [
Text("this is text 1 bla bla bla"),
Text("this is text 2 bla bla bla"),
Text("this is text 3 bla bla bla"),
])
Related
Link to the printscreen of the figma model
I want to place the VerticalDivider widget right in the middle of the Row with the other 2 Columns that contain "Objetivo: Recomendação médica" and "Nível do aluno: intermediário" and I want both of these Columns in the middle of the space left for each one.
Use Expanded to split remaining spaces in a Flex (like Row or Column).
For example:
Row(
children: [
Expanded(child: Container(color: Colors.blue)),
VerticalDivider(),
Expanded(child: Container(color: Colors.orange)),
],
)
Here is my code:
AlertDialog alert = AlertDialog(
content: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image(
image: correct
? AssetImage('assets/images/correct.png')
: AssetImage('assets/images/wrong.png')),
Padding(padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0)),
Text(message)
],
),
),
actions: [
okButton,
],
);
So, it almost works as expected. When I call the alert dialog, it appears correctly with the image and the text. But, for a split second, something overflows.
Here is the stack:
════════ Exception caught by rendering library
═════════════════════════════════════════════════════ The following
assertion was thrown during layout: A RenderFlex overflowed by 102
pixels on the bottom.
The relevant error-causing widget was: Column
file:///Users/path/to/file/blabla.dart:61:16
: To inspect this widget in Flutter DevTools, visit:
http://127.0.0.1:9100/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A55261%2FDahKsJWBhm4%3D%2F&inspectorRef=inspector-863
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#117f5
relayoutBoundary=up9 OVERFLOWING ... parentData: offset=Offset(24.0,
20.0) (can use size) ... constraints: BoxConstraints(w=192.0, 0.0<=h<=120.0) ... size: Size(192.0, 120.0) ... direction: vertical ... mainAxisAlignment: start ... mainAxisSize: min ...
crossAxisAlignment: center ... verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
Any idea what might cause this? Thx!
Wrapping your Column with SingleChildScrollView might fix the problem:
AlertDialog alert = AlertDialog(
content: Container(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image(
image: correct
? AssetImage('assets/images/correct.png')
: AssetImage('assets/images/wrong.png')),
Padding(padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0)),
Text(message)
],
),
),
),
actions: [
okButton,
],
);
some times when I'm coding with flutter, in the Text widget when I use long text, some times I get overflow message, and some times the message work right and be in many lines, why that's happen with me? please explain to me how to avoid this problem.
there are some key property in Text Widgt:
softWrap // if overflow then can wrap new line
overflow // if overflow the overed text style
maxLines // max lines
and if the parent container of Text Widgt has a width less or eq than device width then text overflowed will wrap to multiple lines, or Text will throw overflow error if text is too long
give a width to parent container
for example:
// overflow error
Container(
child: Column(
children: <Widget>[
Text("hellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohello"),
Text("dd")
],
),
)
give parent container fix width
// overflow will change to multiple lines, notice padding and margin's effect
Container(
width: 100,
child: Column(
children: <Widget>[
Text("hellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohello"),
Text("dd")
],
),
)
or let Text fill parant container using Expended or Flexible
Expanded(
child: Column(
children: <Widget>[
Text("hellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohello"),
Text("dd")
],
),
)
// or
Flexible(
child: Column(
children: <Widget>[
Text("hellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohellohellohellohe" +
"llohellohellohellohellohellohello"),
Text("dd")
],
),
)
i am trying to pass different parameters in ListTile widget using function, but i don't know how to do it,
here i how i am trying it,
Passing Parameter from widget;
Widget listSection =Container(
child: Row(
children: [
_listSectionMethod("TITLE 1", "hello i am subtitle two"),
_listSectionMethod("TITLE 2", "hello i am subtitle two"),
],
),
);
Method to use those parameters in listtile;
Card _listSectionMethod(String title,String subtitle){
return Card(
child:ListTile(
title:Text(title),
subtitle:Text(subtitle),
),
);
}
Expected result:
i am trying to show list tile with title and subtitle, on a card.
Error: RenderBox was not laid out
#Fayakon, i think you need to use Column (for vertical widgets) instead of Row (for horizontal widgets) to get get the desired result,
child: Column(
children: <Widget>[
_listSectionMethod("TITLE 1", "hello i am subtitle two"),
_listSectionMethod("TITLE 2", "hello i am subtitle two"),
],
)
Screenshot:
Hope this helps. Learn more about Flutter layouts here - https://flutter.dev/docs/development/ui/layout
I am trying to build a project, with none scrollable header and scrollable body. SliverAppbar is the choice first but if I move body than I lost the header. Also I can use Slidabele Tile. The SliverPersistentHeader is my second choice but I can use Slidabele Tile. My problem is shown below picture. The main.dart Header must not scroll and body must contains hard coded Slidable Tile. How can make none scrollable header and scrollable body in flutter?
You should use appBar: AppBar(... inside of you Scaffold.
so MaterialApp->Scaffold->(AppBar and listview).
Exaple code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("This is the title"),
),
body: ListView(
children: <Widget>[
Text("This is text 1"),
Text("This is text 2"),
Text("This is text 3"),
Text("This is text 4"),
Text("This is text 5"),
Text("This is text 6"),
Text("This is text 7"),
Text("This is text 8"),
Text("This is text 9"),
Text("This is text 10"),
Text("This is text 11"),
Text("This is text 12"),
Text("This is text 13"),
Text("This is text 14"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
Text("This is text 15"),
],
),
),
);
}
}