Develop a Custom Switch in a Flutter App

Sayurusadaru
2 min readApr 19, 2021

--

Introduction:

A switch is a widget that used to toggle the on & off state of an app. Flutter already comes with 2 prebuild switch such as Material design switch and Cupertino switch

Let’s Start:

The switch consists mainly of 2 parts that we need to consider. They are,

  • Thumb/Knob
  • Track

Thumb:

Thumb is the widget that places inside the track. when the user taps on the switch it toggles its alignment between CenterLeft and CenterRight.

How to Implement:

Track:

The track is the parent widget of the thumb and the track is wrapped around a GestureDetector . setState is called inside the onTap: property in the ` GestureDetector to change all the fields that need to change when the user taps in the Switch.

How to implement:

Final:

At last, all the fields should be defined in your private class(_ClassName) in your StatefulWidget .

How to implement:

Here is the link for the Github repository for this project.

Thanks for reading this article ❤️

--

--

Sayurusadaru
Sayurusadaru

Written by Sayurusadaru

UI designer, App developer, hobby photographer. working as a freelancer

No responses yet