skip to Main Content

This code is that I have tried.

Container(
  height: 250,
  decoration: BoxDecoration(
    borderRadius: BorderRadius.circular(12),
  ),
  child: Stack(
    children: [
      Positioned.fill(
        child: Image.asset(
          'assets/images/background.png',
          fit: BoxFit.cover,
        ),
      ),
      Positioned.fill(
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(12),
            color: Colors.black.withOpacity(0.35),
          ),
        ),
      ),
      Center(
        child: ClipRRect(
          borderRadius: BorderRadius.circular(12),
          child: Container(
            padding: const EdgeInsets.all(20),
            color: Colors.transparent,
            child: const  Text(
              'Scrollable Component at the Top',
              style: TextStyle(
                fontSize: 20,
                color: Colors.white,
              ),
            ),
          ),
        ),
      ),
    ],
  ),
),

I tried to fix it by using ClipRRect widget but it didn’t work for me.

2

Answers


  1. Wrapping the Container with ClipRRect should work. Make sure your image fills the full height so the ClipRRect doesn’t clip the border in the extra empty space.

    ClipRRect(
      borderRadius: BorderRadius.circular(12),
      child: Container(
        // ...
      ),
    )
    

    Result:

    Screenshot

    Login or Signup to reply.
  2. i’m trying to figure out what exactly your problem is. your possible needs will found in the following code

    here are some of done work:

    • making the image rounded because it’s the background for the whole
      content.
    • making the container which uses ClipRRect rounded and it’s proved
      by shpe of its borders

    , try to remove border property of the BoxDeconration of that container.

    here’s the code:

    SizedBox(
            height: 250,
            child: Stack(
              children: [
                Positioned.fill(
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(12),
                      child: Image.asset('images/1.jpg', fit: BoxFit.cover)
                  ),
                ),
                Positioned.fill(
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12),
                      color: Colors.black.withOpacity(0.35),
                    ),
                  ),
                ),
                Center(
                  child: Container(
                    padding: const EdgeInsets.all(20),
                    decoration: BoxDecoration(
                      // you can remove borders.
                      border: Border.all(color: Colors.white, width: 1),
                      // i'm setting border to show you it's rounded
                      color: Colors.transparent,
                      borderRadius: BorderRadius.circular(12),
                    ),
                  
                    child: const Text(
                      'Scrollable Component at the Top',
                      style: TextStyle(
                        fontSize: 20,
                        color: Colors.white,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
    

    here’s the result:

    enter image description here

    you can remove the white borders of the container just by removing border property from BoxDecoration.

    hope it helps you.

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