Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

GaNeShKuMaRm
GaNeShKuMaRm

Posted on • Originally published atcodeburst.io

     

Minimal Switch in Flutter

In this article, we are going to create a minimal custom Switch Widget in Flutter. Flutter provides a built-inSwitch Widget which looks simple. We are going to create our ownFlat Style switch widget.

The switch has two parts:

  • The base

  • The knob

We will start writing code for the base and the knob separately.

Base

The base is nothing but the background of the switch which is in arounded rectangle shape.

Widget for Switch Base

  1. AnimatedContainervis used instead of the container because we are going to add animations when the switch is turned ON and OFF.

  2. widget.value holds eithertrue orfalse which represents whether a switch isON orOFF respectively

The Knob

The knob is thecircular button inside the base that we use to toggle the state of the switch.

Widget for Switch Knob

  1. AnimatedAlign is used to animate the movement of the switch when the user clicks it.

The final output looks as follows:

Final Output

Take a look at the below Gist to view the full code with functionality:

Wrapping Up

Well, that’s everything! It’s a short and sweet tutorial but I hope you found it helpful.

Linkedin|Github

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full Stack Engineer
  • Location
    Chennai
  • Education
    Bachelors of Technology (Information Technology)
  • Work
    Software Engineer at Optum
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp