0

I'm trying to create a Button in Flutter, that has an image in the background and Containers above, but i want the Container to have a individual shape. The image below is just an example. I want to make a couple of these buttons.

I figured, that I might want to use a Stack and a GestureDetector to achieve this, but how am I going to "reshape" the orange and grey Containers above the image?

I would really appreciate a hint on how to achieve this. Thank you in advange guys .

enter image description here

5 Answers 5

1

You can Ink widget like this with container

Container(
      height: 100,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20),
      ),
      child: Ink(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
          image: DecorationImage(
            image: AssetImage(
              'images/car_poster.png',
            ),
            fit: BoxFit.cover,
          ),
        ),
        child: InkWell(
          borderRadius: BorderRadius.circular(20),
          onTap: () {},
          child: Center(
            child: Text(
              'title',
              style: TextStyle(
                  color: Colors.white,
                  fontSize: 30,
                  fontWeight: FontWeight.bold),
            ),
          ),
        ),
      ),
    );
Sign up to request clarification or add additional context in comments.

Comments

1

yeah you are right you have to use stack and gesture detector but also you need to use Custom Paint flutter widget in order to draw the orange and grey shape if you want to know how to draw shapes in flutter visit this site Drawing shapes in Flutter with CustomPaint and Shape Maker

1 Comment

Yesss thats what i was looking for. Thank you very much!
0

Try to below code hope it help to you

Container(
          width: 100.0,
          height: 50.0,
          decoration: BoxDecoration(
            border: Border.all(color: Colors.black87),
            image: DecorationImage(
              image: NetworkImage(
                'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png',
              ),
            ),
            shape: BoxShape.rectangle,
          ),
          child: TextButton(
            onPressed: () {
              print('Pressed');
            },
            child: Icon(Icons.check, color: Colors.black),
          ),
        ),

Screen-> enter image description here

Comments

0

There are multiple ways to do this. Here is an example:

    Container(
        height: 200,
        width: 300,
        color: Colors.grey,
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(20.0),
            child: Material(
              child: InkWell(
                onTap: () {
                  //Here you can call your own animation for animate the Image
                },
                // Add Your Own Image
                child: Image.network(
                  'https://images.pexels.com/photos/75973/pexels-photo-75973.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
                  height: 200,
                  width: 300,
                  fit: BoxFit.fill,
                ),
              ),
            ),
          ),
        ),
      ),

enter image description here

Comments

0

To make any widget clickable, wrap it with a InkWell widget

InkWell(
    onTap: () {
    toggle();
    },
    child: Container(
    decoration: BoxDecoration(
    image: DecorationImage( 
       Image: NetworkImage(ImageURL)    //or AssetImage(ImageURL)
    BoxFit.Cover)),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.