Reputation:
Widgets like ListView
, GridView
, SingleChildScrollView
etc are scrollable widgets while Container
, SizedBox
, Column
are not.
Is there any way to check if the Widget
is scrollable, using something like
Widget widget = SomeWidget();
bool scrollable = widget.isScrollable(): // any property like this?
Upvotes: 3
Views: 1979
Reputation: 3703
When you write something like this:
Widget widget = SomeWidget();
then you are basically Downcasting your widget to Widget
class, which is the parent of all classes. If you check the Widget class in doc you should see only 3 methods exposed. Which are:
createElement
debugFillProperties
toStringShort
bool scrollable = widget.isScrollable(): // any property like this?
So no, this is not possible.
However, you know that the widget has to be a subclass of ScrollView or is of type SingleChildScrollView so you can write a utility method for yourself. Like
bool isScrollable(Widget widget) => widget is ScrollView || widget is SingleChildScrollView;
Upvotes: 1