What is the difference between double.INFINITY and MediaQuery?

Technology CommunityCategory: FlutterWhat is the difference between double.INFINITY and MediaQuery?
VietMX Staff asked 3 years ago

The difference can be summarised into:

  • I want to be as big as my parent allows (double.INFINITY)
  • I want to be as big as the screen (MediaQuery).

Usually, you’ll want to use double.infinity, but it’s not always possible. Some Widgets allow their children to be as big as they want to be (ColumnListViewOverflowBox…). In that situation using double.infinity creates a paradox:

  • The parent allows any size
  • The child wants the biggest size allowed by the parent