Home > database >  Why Expanded widget can not add a child which is Text in Dart?
Why Expanded widget can not add a child which is Text in Dart?

Time:02-26

When I add a Expanded widget whose child is Text into a list,Android Studio throw a error message like this: Error: The argument type 'Expanded' can't be assigned to the parameter type 'Text'.

final List<Text> words = [];
words.add(Expanded(child: Text('hello')));

enter image description here

CodePudding user response:

Your list is a List of Text widget and you are trying to add an Expanded widget to it.

try this:

final List<Expanded> words = [];
words.add(Expanded(child: Text('hello')));

or:

final List<Text> words = [];
words.add(Text('hello'));

or:

final List<Widget> words = [];
words.add(Expanded(child: Text('hello')));

CodePudding user response:

Expanded is a widget that can be used with(inside) Row, Column and Flex. You can't add it to a list of type Text, just remove it.

  • Related