SizedBox Widget in Flutter

A box with a specified size. If either the width or height is null, this widget will try to size itself to match the child's size in that dimension. If the child's size depends on the size of its parent, the height and width must be provided.

 

Properties

 

  • child
  • height
  • width

 

Example 1:

 

import 'package:flutter/material.dart';


void main() {

  runApp(

    MaterialApp(

      home: Scaffold(

        appBar: AppBar(

          title: const Text(

            'Sample App',

          ),

        ),

        body: const SizedBox(

          child: Card(),

          height: 200,

          width: 200,

        ),

      ),

    ),

  );

}

 

Example 2:

 

SizedBox(

          child: Card(

            color: Colors.orange,

            child: Center(

              child: Text('Hello'),

            ),

          ),

          height: 200,

          width: 200,

        ),

 

Example 3:

 

SizedBox(

          child: Card(

            color: Colors.orange,

            child: Center(

              child: Text('Hello'),

            ),

          ),

          height: double.infinity,

          width: double.infinity,

        ),

 

SizedBox.expand

 

SizedBox.expand(

          child: Card(

            color: Colors.orange,

            child: Center(

              child: Text('Hello'),

            ),

          ),

        ),

 

SizedBox.shrink

 

SizedBox.shrink(

          child: Card(

            color: Colors.orange,

            child: Center(

              child: Text('Hello'),

            ),

          ),

        ),

 

SizedBox.fromSize

 

SizedBox.fromSize(

          size: const Size(150, 150),

          child: const Card(

            color: Colors.orange,

            child: Center(

              child: Text('Hello'),

            ),

          ),

        ),


Video Link:

 
Post a Comment (0)
Previous Post Next Post