chichi
chichi

Reputation: 3301

Flutter - how to get the height and width of the AspectRatio widget?

AspectRatio(
        aspectRatio: 1,
        child: Container(
          color: Colors.blue,
        ),
      ),

I am trying to hand over AspectRatio's width and height to its child Container. I am trying to use this info to create the responsive Text widget. Is there any way that I can get the height and width of the AspectRatio?

Upvotes: 0

Views: 3120

Answers (1)

Ariel
Ariel

Reputation: 2752

You can use LayoutBuilder to get the height and width of the AspectRatio. It is returned in terms of maxWidth and maxHeight of constraint.

AspectRatio(
        aspectRatio: 1,
        child: LayoutBuilder(
               builder: (context, constraints) {

                  debugPrint(constraints.toString());
                  return Container(
                     color: Colors.blue,
                  );
               }
          ),
      ),


Upvotes: 1

Related Questions