Home > front end >  Flutter - how to get the height and width of the AspectRatio widget?
Flutter - how to get the height and width of the AspectRatio widget?

Time:08-12

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?

CodePudding user response:

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,
                  );
               }
          ),
      ),


  • Related