1

I have an image like this image

and i need to add widgets upon this image. It should look like the contents are just on the mobile screen. I tried searching for a way but i dint get any. I tried using stack like this:

Container(
    child: Stack(
      children: <Widget>[
        Positioned(
          child: Container(
            padding: EdgeInsets.fromLTRB(60, 110, 60, 90),
            //body
          ),
        ),
        Container(width: 1000,
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage('Assets/Images/transparentMobile.png'),
                  fit: BoxFit.fill)),
        ),
      ],
    ),
  ),

It worked correctly on my phone: image

but on other phone it looks very different. How do i write a single code for multiple screens?

12
  • 1
    Did Stack help you get your answer? Commented Aug 10, 2020 at 15:31
  • 1
    thnx, i think i should try it Commented Aug 10, 2020 at 15:43
  • 1
    Duplicate of stackoverflow.com/questions/49838021/… Commented Aug 10, 2020 at 15:44
  • 1
    I am kind of feeling to point a layout for you. I hope that should work. Will that do @Bensal ? If yes, than I will map a layout for you Commented Aug 10, 2020 at 15:49
  • 1
    Great job @Bensal. The problem is normal, not every phone will be of same size, hence Positioned will not be same of every mobile image. We might wanna dig deeper to find the solution Commented Aug 11, 2020 at 6:32

1 Answer 1

1

Finally i got a way to do it. Instead of working hard on the code, i just cropped the image into 3 parts :

top : top

body: body

bottom: bottom

and added them to columns like this:

AspectRatio(
      aspectRatio: 1/2,
      child: Container(
        padding: EdgeInsets.all(20),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
        Expanded(
          child: Container(
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage('Assets/Images/Mobile/mobileTop.png'),
                    fit: BoxFit.fill
                )
            ),
          ),
        ),
            Expanded(
              flex: 7,
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 20),
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage('Assets/Images/Mobile/mobileBody.png',),
                    fit: BoxFit.fill
                  )
                ),
                height: 100,
                child: Scaffold(
                    appBar: AppBar(
                      backgroundColor: Colors.blue,
                      automaticallyImplyLeading: false,
                      title: Text('My Application'),
                    ),
                    body: Center(
                      child: Text(
                        'Hello World!',
                        style: TextStyle(color: Colors.black),
                      ),
                    ),
                    backgroundColor: Colors.white,
                  ),
              ),
            ),
            Expanded(
              child: Container(
                decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage('Assets/Images/Mobile/mobileBottom.png'),
                        fit: BoxFit.fill
                    )
                ),
              ),
            ),

          ],
        ),
      ),
    ),

and the image now looks much similar on most of the devices now: image

Thanks for your help!

Sign up to request clarification or add additional context in comments.

1 Comment

Well done Bensal! My upvote for your effrots :) I am saving your answer, so that I can take benefit from it in the future :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.