skip to Main Content

can anyone tell me how to do this

i’ve tried like this but it is not appearing like what i want

Container(
  height: 900,
  width: double.maxFinite,
  color: const Color(0xff070540),
  child: Stack(
    children: [
      Padding(
        padding: EdgeInsets.only(left: 15, right: 15, top: 15),
        child: Container(
          height: 30,
          color: Color(0xff2147AF),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Icon(Icons.arrow_back),
              Text(
                'Details of Athlete',
                style: TextStyle(fontSize: 15),
              ),
              Icon(Icons.thumb_up_sharp),
            ],
          ),
        ),
      ),
      Row(
        children: [
          Container(
            height: 150,
            width: 80,
            decoration: const BoxDecoration(
              color: Color(0xff2147AF),
              borderRadius:
                BorderRadius.only(bottomRight: Radius.circular(20)),
            )
          ),
          Container(
            height: 150,
            width: 80,
            decoration: const BoxDecoration(
              color: Color(0xff2147AF),
              borderRadius:
                BorderRadius.only(bottomLeft: Radius.circular(20)),
            )
          )
        ],
      )
    ],
  )
);

2

Answers


  1. First thing, the order of children inside a Stack (Stack Class) is that the Last Child should come upfront, which means that in your code the last Row with the Containers would cover the first Row with the text.
    For the lighter blue box you can use only one container with bottom border radius instead of aligning two container with a corner radius.
    I’m no expert, so maybe this isn’t the best approach, but I would use a Stack with one container for the background elements and a column for the foreground elements (text and image).

    Some tips:

    • When developing I recommend you use a lot of colors (red, amber, pink) for your elements so it is easier to understand what’s happening on screen and the limits of each component.
    • You can put codes in a Stack Question using “`your code here“` so it’s easier for people to understand and help you.

    Here’s a widget I created using your image as reference, I hope it helps you:

    import 'package:flutter/material.dart';
    
    class Teste extends StatelessWidget {
      const Teste({super.key});
    
    // I'm setting the colors here so it's easier to reference then and change later if needed;
      final Color blue = const Color(0xff070540);
      final Color lighterBlue = const Color(0xff2147AF);
      final Color white = Colors.white;
    
      @override
      Widget build(BuildContext context) {
        // The MediaQuery.sizeOf(context) returns the dimensions of the screen so you can
        //be sure everything is gonna fit on the device.
        final double width = MediaQuery.sizeOf(context).width;
        final double height = MediaQuery.sizeOf(context).height;
        return Scaffold(
          body: Stack(
            children: [
              // First container with the blue background elements
              Container(
                width: width,
                height: height,
                //  You need to specify the alignment of the Parent Container so the Child Container
                // does not grow to the size of parent.
                alignment: Alignment.topCenter,
                color: blue,
                child: Container(
                  width: width,
                  height: height * 0.5,
                  decoration: BoxDecoration(
                      // Here we set the border radius of the bottom part of the Container
                      borderRadius: const BorderRadius.vertical(
                        bottom: Radius.circular(30),
                      ),
                      color: lighterBlue),
                ),
              ),
              // This column is the foreground element with the Text and Image
              Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Padding(
                    padding: EdgeInsets.fromLTRB(
                        width * 0.1, height * 0.1, width * 0.1, 25),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Icon(
                          Icons.arrow_back_ios,
                          color: white,
                          size: 34,
                        ),
                        Text(
                          "Some Text",
                          style: TextStyle(
                              fontSize: 24,
                              fontWeight: FontWeight.w500,
                              color: white),
                        ),
                        Icon(
                          Icons.thumb_up,
                          color: white,
                          size: 34,
                        )
                      ],
                    ),
                  ),
                  Text(
                    "TITLE",
                    style: TextStyle(color: white, fontSize: 40),
                  ),
                  Text(
                    "subtitle",
                    style: TextStyle(color: Colors.grey[400], fontSize: 20),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 20),
                    child: Container(
                      width: width * 0.6,
                      height: width * 0.6,
                      decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        border: Border.all(
                            color: blue,
                            strokeAlign: BorderSide.strokeAlignOutside,
                            width: 10),
                        // Here you can chaneg the Image.network link to your image, or use some
                        //  other widget to display the image you want;
                        image: DecorationImage(
                            image: Image.network("https://picsum.photos/300/300")
                                .image),
                      ),
                    ),
                  )
                ],
              )
            ],
          ),
        );
      }
    }
    
    Login or Signup to reply.
  2. Problem solved.

    Try using this code snippet; it should be helpful in achieving the desired output.

    Builder(
            builder: (context) {
              return SafeArea(
                child: Scaffold(
                  backgroundColor: const Color(0xff070540),
                  body: Stack(
                    clipBehavior: Clip.none,
                    alignment: AlignmentDirectional.center,
                    fit: StackFit.loose,
                    children: [
                      Container(
                        height: MediaQuery.of(context).size.height * 0.4,
                        padding: const EdgeInsets.symmetric(horizontal: 20),
                        width: double.infinity,
                        decoration: const BoxDecoration(
                          color: Color(0xff2147AF),
                          borderRadius: BorderRadius.only(
                            bottomRight: Radius.circular(20),
                            bottomLeft: Radius.circular(20),
                          ),
                        ),
                        child: Column(
                          children: [
                            const SizedBox(height: 60),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: const [
                                Icon(
                                  Icons.arrow_back,
                                  color: Colors.white,
                                ),
                                Text(
                                  'Your content',
                                  style: TextStyle(
                                    fontSize: 20,
                                    color: Colors.white,
                                  ),
                                ),
                                Icon(
                                  Icons.thumb_up_sharp,
                                  color: Colors.white,
                                ),
                              ],
                            ),
                            const SizedBox(height: 16),
                            const Text(
                              'Your Name',
                              style: TextStyle(
                                fontSize: 28,
                                color: Colors.white,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                            const SizedBox(height: 16),
                            Text(
                              'Your Position',
                              style: TextStyle(
                                fontSize: 20,
                                color: Colors.white.withOpacity(0.5),
                              ),
                            ),
                            const SizedBox(height: 16),
                          ],
                        ),
                      ),
                      Positioned(
                        top: MediaQuery.of(context).size.height * 0.3,
                        child: Container(
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            border: Border.all(
                              color: const Color(0xff070540),
                              width: 5.0, // Choose the border width
                            ),
                          ),
                          child: const CircleAvatar(
                            radius: 80,
                            backgroundColor: Colors.white,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              );
            },
          ),
    

    Click here to check output

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search