phuocding
phuocding

Reputation: 355

Flutter fix the same size with defferent images in FlatButton

ListView Tap Buntton

I want to fix the size of the image in the flat button. I have images of different size, Then in Listview, I added FlatButton with a background is an image. I try with ClipRRect but not yet. Code is here

child: ListView(
          scrollDirection: Axis.horizontal,
          children: <Widget>[
              child: FlatButton(
                child: Image.asset('assets/images/taixiu.png', scale: 1.25),
                onPressed: () {
                  Navigator.pushNamed(context, '/sicbo-game');
                },
              ),
              child: FlatButton(
                child: Image.asset('assets/images/poker.png', scale: 1.25),
                onPressed: () {
                  Navigator.pushNamed(context, '/sicbo-game');
                },
              ),
              child: FlatButton(
                child: Image.asset('assets/images/baucua.png', scale: 1.75),
                onPressed: () {
                  Navigator.pushNamed(context, '/sicbo-game');
                },
              ),
              child: FlatButton(
                child: Image.asset('assets/images/cangua.png', scale: 7.0),
                onPressed: () {
                  Navigator.pushNamed(context, '/sicbo-game');
                },
              ),
              child: FlatButton(
                child: Image.asset('assets/images/taixiu.png', scale: 1.25),
                onPressed: () {
                  Navigator.pushNamed(context, '/sicbo-game');
                },
              ),
            )
          ],
        ),

Upvotes: 0

Views: 827

Answers (1)

Snirjka
Snirjka

Reputation: 315

The way i would do it is set the button child like that -

Container(
 width: 200.0
 height: 200.0,
 decoration: BoxDecoration(
   image: DecorationImage(
   image: AssetImage('myimagepath'),
   repeat: ImageRepeat.repeat,
   fit: BoxFit.none,
   ),
 ),
)

Instead of the image itself i just use a container with the given width and height you want and the image as a background.

Upvotes: 3

Related Questions