Container

  • Usage

    Flutter Container widget center aligns its child widget within itself, along vertical and horizontal axes.

    Syntax

    
                      Container(
                        child: someWidget,
                      )
                      

    Properties

    
                      Container({Key key,  
                          AlignmentGeometry alignment,   
                          EdgeInsetsGeometry padding,   
                          Color color,   
                          double width,   
                          double height,  
                          Decoration decoration,   
                          Decoration foregroundDecoration,   
                          BoxConstraints constraints,   
                          Widget child,   
                          Clip clipBehavior: Clip.none  
                }); 
    
                

    Examples

    
                      import 'package:flutter/material.dart';
        
                   
                    void main() {
                    
                     
                      runApp(
                      
                        
                        Container(
                          color: Colors.green, // <-- change this
                        ),
                        
                      );
                    }
    
      
    
                    
    
                    import 'package:flutter/material.dart';
     
    void main() => runApp(const MyApp());
     
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
     
      static const String _title = 'Flutter Tutorial';
     
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: _title,
          home: Scaffold(
            appBar: AppBar(title: const Text(_title)),
            body: const MyStatefulWidget(),
          ),
        );
      }
    }
     
    class MyStatefulWidget extends StatefulWidget {
      const MyStatefulWidget({Key? key}) : super(key: key);
     
      @override
      State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
    }
     
    class _MyStatefulWidgetState extends State<MyStatefulWidget> {
      @override
      Widget build(BuildContext context) {
        return Center(
          child: Column(
            children: <Widget>[
              const SizedBox(height: 10,),
              Container(
                height: 150,
                width: 200,
                color: Colors.green,
                alignment: Alignment.center,
                child: const Text('Container'),
              ),
            ],
          ),
        );
      }
    }
                    
    Container()