How To Use Intrinsic Width Widget Using Flutter App

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

A widget that sizes its child to the child's maximum intrinsic width.This class is useful, for example, when unlimited width is available and you would like a child that would otherwise attempt to expand infinitely to instead size itself to a more reasonable width.The constraints that this widget passes to its child will adhere to the parent's constraints, so if the constraints are not large enough to satisfy the child's maximum intrinsic width, then the child will get less width than it otherwise would. Likewise, if the minimum width constraint is larger than the child's maximum intrinsic width, the child will be given more width than it otherwise would.If stepWidth is non-null, the child's width will be snapped to a multiple of the stepWidth. Similarly, if stepHeight is non-null, the child's height will be snapped to a multiple of the stepHeight.

How To Use Intrinsic Width Widget Using Flutter App

Intrinsic Width Widget 
Complete Code For Intrinsic Width Widget  In Flutter
main.dart

import 'package:flutter/material.dart';
void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.pink,
          title: Text("IntrinsicWidth Widget")),
      body: Center(
        child: IntrinsicWidth(
          child: Container(
            height: 50.0,
            width: 290.0,
            color: Colors.pink[900],
            child: Container(color: Colors.orange, width: 80.0),
          ),
        ),
      ),
    );
  }
}

Related Post