Clermoe
Clermoe

Reputation: 101

How to make customize switch button with image ? Flutter

I want to know how to customize a switch in Flutter to look like this :

switch button

I don't want to know how to make the shape etc. But how to put an image in the track. I know there are :

inactiveThumbImage
activeThumbImage

But it is not what I want. Maybe something like activeTrackImage, but I didn't find anything in the doc.

Upvotes: 0

Views: 848

Answers (1)

Danny
Danny

Reputation: 506

you can use this package which adds the functionality to add an image to a switch widget..

AdvancedSwitch(
          controller: _controller,
          activeColor: Colors.green,
          inactiveColor: Colors.grey,
          activeImage: const AssetImage('assets/images/on.png'),
          inactiveImage: const AssetImage('assets/images/off.png'),
          borderRadius: const BorderRadius.all(Radius.circular(15)),
          width: 100.0,
          height: 30.0,
          enabled: true,
          disabledOpacity: 0.5,
        )

which gives the following result

OFF

Off

ON

On

Upvotes: 2

Related Questions