Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to include Multiple Children inside a Container?

This is full code:

class Application extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
       body: new Container(
         color: Color(0xff258DED),
         height: 400.0,
         alignment: Alignment.center,
         child: new Container(
           height: 200.0,
           width: 200.0,
           decoration: new BoxDecoration(
             image: DecorationImage(
                 image: new AssetImage('assets/logo.png'),
             fit: BoxFit.fill
             ),
             shape: BoxShape.circle
           ),
         ),
         child: new Container(
          child: new Text('Welcome to Prime Message',
            textAlign: TextAlign.center,
            style: TextStyle(
                fontFamily: 'Aleo',
                fontStyle: FontStyle.normal,
                fontWeight: FontWeight.bold,
                fontSize: 25.0,
                color: Colors.white
            ),
          ),
         ),
        ),
      ),
    );
  }
}

I tried to add a Container on top and then added two children inside it. First child works fine, but second child giving me error like "the argument for the named parameter 'child' was already specified".

like image 452
Ranto Berk Avatar asked Aug 19 '19 09:08

Ranto Berk


People also ask

Can a container have multiple children Flutter?

Column is a layout widget in flutter which aligns its children vertically. It can have multiple child widgets.

What are Flutter kids?

child. The child contained by the container. If null, and if the constraints are unbounded or also null, the container will expand to fill all available space in its parent, unless the parent provides unbounded constraints, in which case the container will attempt to be as small as possible.

How do you center a child in a container?

In Flutter, to vertically center a child widget inside a Container, you can wrap the child widget with Column and add mainAxisAlignment: MainAxisAlignment. center to it.

How to put more than one child in a container?

You have to use mutichild widget like Column , Row , Stack.... It deepends on how you want to lay your widgets If you try to put more than one child in a container, you want to look as Row () or Column () class for linear ones. Stack () is used if you want to have floating children on top of each other.

How do I connect multiple containers to a single process?

You can connect multiple containers using user-defined networks and shared volumes. The container’s main process is responsible for managing all processes that it starts. In some cases, the main process isn’t well-designed, and doesn’t handle “reaping” (stopping) child processes gracefully when the container exits.

What is a container?

A container is a sandbox for an application. Containers are a modern way to run apps on your laptop, package your own apps, and even run apps in data centers. In short, they’re a super flexible way to share and run applications.

How do I create a container?

A container is usually created from an image. You can think of an image like a template or blueprint for creating containers. You can create hundreds (or millions) of containers from the same image. Images can be stored on your local machine, and you can share them with others. Most applications need libraries and system utilities to run.


1 Answers

If you try to put more than one child in a container, you want to look as Row() or Column() class for linear ones. Stack() is used if you want to have floating children on top of each other.

Eg:

class Application extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
            home: new Scaffold(
                body: new Container(
                    color: Color(0xff258DED),
                    height: 400.0,
                    alignment: Alignment.center,
                    child: new Column(
                        children: [
                            new Container(
                                height: 200.0,
                                width: 200.0,
                                decoration: new BoxDecoration(
                                    image: DecorationImage(
                                        image: new AssetImage('assets/logo.png'),
                                        fit: BoxFit.fill
                                    ),
                                    shape: BoxShape.circle
                                ),
                            ),
                            new Container(
                                child: new Text('Welcome to Prime Message',
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontFamily: 'Aleo',
                                        fontStyle: FontStyle.normal,
                                        fontWeight: FontWeight.bold,
                                        fontSize: 25.0,
                                        color: Colors.white
                                    ),
                                ),
                            ),
                        ],
                    ),
                ),
            ),
        );
    }
}
like image 189
Adlan Arif Zakaria Avatar answered Oct 16 '22 03:10

Adlan Arif Zakaria