Kinda Code
Home/Flutter/Flutter: SizedOverflowBox example

Flutter: SizedOverflowBox example

Last updated: October 06, 2022

The SizedOverflowBox widget in Flutter, as its name describes itself, is used to create a box with certain width and height but lets its child overflow. You can implement a SizedOverFlow box as follows:

SizedOverflowBox({
  Key? key, 
  required Size size, // Size(double width, double height)
  AlignmentGeometry alignment = Alignment.center, 
  Widget? child
})

Where:

  • size: The size this widget should attempt to be
  • alignment: Align the child widget
  • child: The child widget

Example

This example displays 2 widgets. The parent widget is purple in color and the child widget is amber. Here’s the screenshot:

The code:

Center(
        child: Container(
          color: Colors.purple,
          child: SizedOverflowBox(
            size: const Size(300, 200),
            alignment: Alignment.bottomCenter,
            child: Container(
              width: 150,
              height: 400,
              color: Colors.amber,
              child: const Center(
                child: Text(
                  'Child',
                  style: TextStyle(fontSize: 30),
                ),
              ),
            ),
          ),
        ),
      ),

Further reading:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.