So, I am trying to put multiple objects into a body for which I used Dart’s Stack
function. While doing that I am getting this error. I am new to Dart and I am still learning about it’s data types.
I have two questions mainly –
- What are the data types that I can put inside the
Stack
function? - Is this an efficient way in Dart to add multiple objects in a
body:
?
For your reference I am attaching a code below –
body: Stack(
children: [Align(
alignment: Alignment(0, 0),
child: Text('Test?',
style: TextStyle(
fontSize: 28.0,
color: Colors.black87,
letterSpacing: 1.0,
fontFamily: 'Quicksand',
),//TextStle
),//Text
),//Align
Column(
children: <widget>[
Container(
padding: EdgeInsets.all(20),
color: Colors.cyan,
child: Text('What's up')
),//Container
],//<Widget>
),//Column
]
),
Error: 'widget' isn't a type.
children: <widget>[
^^^^^^
4
Answers
Try it without the
<widget>
more information about stack function – https://api.flutter.dev/flutter/widgets/Stack-class.html
Try below code just remove in column refer Stack widget here
Result of your screen:
you need not define it as a widget. Remove
<widget>
in Stack you should put widgets. or a function that returns a widget. the data type here is a widget.
for the body you have to add the widget to or a function that returns a widget. so the efficient way to add multiple items to the body is to use widgets that are able to take multiple children such as
stack
,column