How To Use Constrained Box Widget Using Flutter App

admin_img Posted By Bajarangi soft , Posted On 02-11-2020

A widget that imposes additional constraints on its child.For example, if you wanted child to have a minimum height of 50.0 logical pixels, you could use const BoxConstraints(minHeight: 50.0) as the constraints.

How To Use Constrained Box Widget Using Flutter App

Constrained Box Widget
Complete Code For Constrained Box Widget In Flutter
main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.cyan[600],
          title: Text("ConstrainedBox Widget"
          )),
      body: Center(
        child: ConstrainedBox(
          constraints: BoxConstraints(maxHeight: 150.0, maxWidth: 150.0),
          child: Container(
            child: Center(child: Text('Flutter Tutorial',
              style: TextStyle(
                color: Colors.white,
                  fontSize: 14),
            )),
              height: 250.0,
              width: 250.0,
              color: Colors.cyan[700]
          ),
        ),

      ),
    );
  }
}

Related Post