Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

In this document https://flutter.dev/docs/development/ui/layout#nesting-rows-and-columns they use

children:

But in the Android Studio, and this doc https://api.flutter.dev/flutter/widgets/Row-class.html they use

children: &ltWidget&gt

So, what are the differences? Thank you

like image 949
Espanola Avatar asked Oct 19 '25 09:10

Espanola


1 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

like image 164
Amir Avatar answered Oct 21 '25 02:10

Amir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!