What is the difference between ...
What is the difference between ...
The main differences between double.infinity
and MediaQuery
in Flutter are:
double.infinity
is used to make a widget occupy the entire available width or height of its parent, regardless of the parent's actual size. It creates a paradox for widgets that have a limited size, like OverflowBox
, SizedBox
, etc.[1][2]
MediaQuery.of(context).size.width
and MediaQuery.of(context).size.height
return the actual width and height of the screen or the widget's parent, based on the provided context
. This allows the widget to size itself according to the available space.[1][4]
double.infinity
is useful for widgets that can grow to fill the available space, like Column
, ListView
, etc. But it should be avoided for widgets with limited size, as it can lead to layout issues.[1][2]
MediaQuery
is commonly used in the build
method of widgets to determine the screen size and orientation, and adapt the UI accordingly. It provides a way to create responsive and adaptive...
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào