<p>Usually, when you add a container inside another container, the boundaries are not restricted. So, let's find out how to restrict its boundaries by adding a container inside another container. Here is an example of what you are going to achieve in this example.</p> <p>);</p> <p>class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); }</p> <p>class _MyAppState extends State { double padValue = 1; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text("Container inside another Container"), ), body: Column( children: [ Expanded( child: Center( child: MyFillingContainer( progress: padValue / 10, size: 200, backgroundColor: Colors.grey, progressColor: Colors.blue, ), ), ), Text('Fill Value: $padValue'), ButtonBar( alignment: MainAxisAlignment.center, children: [ RaisedButton( child: Text('Fill'), onPressed: () { setState(() { padValue = padValue + 1; }); }, ), RaisedButton( child: Text('Unfill'), onPressed: () { setState(() { if (padValue != 0) { padValue = padValue - 1; } }); }, ) ], ), ], ), ), ); } }</p> <p>class MyFillingContainer extends StatelessWidget { final double progress; final double size; final Color backgroundColor; final Color progressColor;</p> <p>const MyFillingContainer( {Key key, this.progress, this.size, this.backgroundColor, this.progressColor}) : super(key: key);</p> <p>@override Widget build(BuildContext context) { return ClipRRect( child: SizedBox( height: size, width: size, child: Stack(<br /> children: [ Container( color: backgroundColor, ), Center( child: Container( height: size * progress, width: size * progress, color: progressColor, ), ) ]), ), ); } } Hope this is useful. Thanks, Srikanth</p>
How to add a Container inside another Container?
This Article is posted by seven.srikanth at 3/29/2020 5:21:45 AM
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter
Tags: Container inside another Container; restrict boundaries based on outside container;
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter