LimitedBox Widget

What is LimitedBox Widget?

The LimitedBox is to limits its size only when it's unconstrained.

Default Constructor

The default constructor creates a box that limits its size only when it's unconstrained.

LimitedBox(
    maxWidth : double.infinity, // default
    maxHeight : double.infinity, // default
    child:
)

Constructor Parameters

It contains many input parameters which can be configured to change its behavior and appearance.

The maxWidth parameter is to apply maximum width limit. Default to infinity

The maxHeight parameter is to apply maximum height limit. Default to infinity

The child parameter is to add the widget below the LimitedBox in a tree.

Code snippet

The following code snippet shows how to configure LimitedBox widget.

LimitedBox(
      maxWidth: 50,
      maxHeight: 50,
      child: Container(
        width: 70,
        height: 70,
        color: Colors.blue,
        child: Text('LimitedBox widget demo'),
      ),
    );

Demo Code

import 'package:flutter/material.dart';

class LimitedBoxDemo extends StatelessWidget {
  
  Widget build(BuildContext context) {
    return LimitedBox(
      maxWidth: 50,
      maxHeight: 50,
      child: Container(
        width: 70,
        height: 70,
        color: Colors.blue,
        child: Text('LimitedBox widget demo'),
      ),
    );
  }
}

class MyApp extends StatelessWidget {
  static const String _title = 'LimitedBox Demo';

  
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: LimitedBoxDemo(),
      ),
    );
  }
}

void main() => runApp(MyApp());