Flutter: use "children: <Widget>" or "children:"?

Viewed 6799
3 Answers

both of them are true and worked but the difference is :

it`s like when you create a list, you can create lists like below

List<dynamic> list;
List<Widget> list;

when you pass the <Widget>[] you tell to compiler the input list type is Widget and all list child must be Widget not anything else

and if you use children: <Widget>[] your IDE can know the list type and if you add anything except Widget the IDE throw an error before you build the application and waste your time

In dart when you want to set type of items in List to do this:

e.g.:

var intList = <int>[1, 2, 3];

and type of var list become List<int>,

So the here in children is the same.

set <widget> before your widgets list, tell compiler, this list has items with widget type.

The first one computes the children in runtime, which might be a cause of very low percentage extra effect on UI rebuilding. Because, it allocates dynamic and in the run time it checks what is the type of my widgets!

On the other hand, Second one is compiled type, which means no extra work for this at the runtime. Which removes the extra pressure on UI rebuilding at the runtime!

Related