{"id":7382,"date":"2021-08-04T11:26:47","date_gmt":"2021-08-04T11:26:47","guid":{"rendered":"https:\/\/www.getwidget.dev\/blogs\/flutter-toggle-widget\/"},"modified":"2024-11-21T11:45:54","modified_gmt":"2024-11-21T11:45:54","slug":"flutter-toggle-widget","status":"publish","type":"post","link":"https:\/\/www.getwidget.dev\/blog\/flutter-toggle-widget\/","title":{"rendered":"Flutter Toggle &#8211; A switch widget that toggles\/switches between true and false states"},"content":{"rendered":"<p><a href=\"https:\/\/docs.getwidget.dev\/gf-toggle\/\" target=\"_blank\" rel=\"noopener\"><strong>Flutter Toggle<\/strong><\/a> is a switch that has two state user interface elements to choose between checked or unchecked states.\u200c\u200c\u200c\u200c This also rejuvenates the content.<\/p>\n<p>So, are you ready to make use of this widget package in the Flutter application? If so, then let&#8217;s quickly jump into the usage and the ways a toggle can be modified and used to make user-friendly apps. Here I am going to use an open-source UI Library known as GetWidget to build this toggle widget in Flutter.<\/p>\n<h3 id=\"%E2%80%8Cflutter-toggle-widget-in-getwidget-library\">\u200cFlutter Toggle Widget in GetWidget Library<\/h3>\n<p><a href=\"https:\/\/docs.getwidget.dev\/gf-toggle\/\" target=\"_blank\" rel=\"noopener\"><strong>GFToggle<\/strong><\/a> is a <strong>Flutter Toggle <\/strong>that typically has a button with a thumb slider where the user can use it to drag back and forth corresponding to the state. Its functionalities are as similar as the house electricity switches.<\/p>\n<p>In Flutter, we can define toggle in any of the widgets. By using its customization properties we can mold it according to our requirements.<\/p>\n<p>GFToggle allows you to speed up your <a href=\"https:\/\/www.getwidget.dev\/hire-flutter-developer\">Flutter app development<\/a> by 20-30%. It has almost all the <a href=\"https:\/\/www.getwidget.dev\/blog\/what-is-widget-in-flutter\/\" data-wpil-monitor-id=\"220\">widget<\/a> that allows you to enhance your Flutter UI design and speed up Flutter development with fully customizable features.<\/p>\n<blockquote><p><em>Now here is i am going to talk about what is <strong>GetWidget<\/strong> Toggle widget and how we implement this on Flutter app to build awesome Flutter Toggle widget for an app.<\/em><\/p><\/blockquote>\n<h3 id=\"how-to-start\">How to Start:<\/h3>\n<p>Now here is the guide about how we should start developing the <strong>GFToggle <\/strong>Widget with the use of the <a href=\"https:\/\/www.getwidget.dev\/\"><strong>GetWidget UI Library<\/strong><\/a>.<\/p>\n<p>First, Let go with<strong> <a href=\"https:\/\/docs.getwidget.dev\/getting-started\/\" target=\"_blank\" rel=\"noopener\"><strong>Getting started<\/strong><\/a><\/strong>, It will guide you on how to start building a beautiful <a href=\"https:\/\/market.getwidget.dev\/products\/\" target=\"_blank\" rel=\"noopener\">flutter application UI<\/a> with the <strong>GetWidget<\/strong> UI library. Now, we have to install the <strong>GetWidget<\/strong> package from the <strong>pub.dev<\/strong> and use our 1000+ inbuilt Widget. To import the package in your Flutter project follow the below guide.<\/p>\n<blockquote><p><em>Install Package from pub.dev :<\/em><\/p><\/blockquote>\n<p><a href=\"https:\/\/pub.dev\/packages\/getwidget\/\" target=\"_blank\" rel=\"noopener\"><strong>https:\/\/pub.dev\/packages\/getwidget<\/strong><\/a><strong> &#8211; Check the details about GetWidget Package.<\/strong><\/p>\n<h3 id=\"import-full-package\">Import full package:<\/h3>\n<p>import &#8216;package:getwidget\/getwidget.dart&#8217;;<\/p>\n<p><strong>Note: dependencies: getwidget: ^ 4.0.0<\/strong><\/p>\n<blockquote><p><em>Keep playing with the pre-built UI components.<\/em><\/p><\/blockquote>\n<p><strong>GetWidget Toggle<\/strong> shows us the two states of a component, between them we have to choose one as per our convenience as it is a yes\/no option. It simply toggles between yes and no values It can be of four types as android, ios, square, and custom.<\/p>\n<h3 id=\"simple-flutter-toggle-button-with-gftoggle-widget\">Simple Flutter Toggle Button with GFToggle Widget<\/h3>\n<p>This is basically of type android that triggers between yes and no options. Below is the given code to show a basic GFToggle. \u200c\u200c\u200c<\/p>\n<pre><code class=\"language-javascript\"> import 'package:getwidget\/getwidget.dart';\n\n GFToggle(\n    onChanged: (val){},\n    value: true,\n )<\/code><\/pre>\n<h3 id=\"flutter-ios-switch-toggle-design-with-gftoggle-widget\">Flutter IOS Switch Toggle Design with GFToggle Widget<\/h3>\n<p>IOS GFToggle is having rounded corners as shown in the image below and also has yes and no switches options. This is of type ios, we can use this in our android applications also. Here is the code to display the ios GFToggle.\u200c\u200c\u200c<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" class=\"kg-image lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--104-.png\" alt=\"\" width=\"725\" height=\"266\" \/><noscript><img decoding=\"async\" class=\"kg-image lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--104-.png\" alt=\"\" width=\"725\" height=\"266\" \/><\/noscript><\/figure>\n<figure class=\"kg-card kg-code-card\">\n<pre><code class=\"language-javascript\"> import 'package:getwidget\/getwidget.dart';\n \n GFToggle(\n    onChanged: (val){},\n    value: true,\n    enabledThumbColor:Colors.red,\n    type: GFToggleType.ios,\n )<\/code><\/pre><figcaption><span style=\"white-space: pre-wrap;\">Flutter IOS Switch Toggle\u00a0<\/span><\/p>\n<\/figcaption><\/figure>\n<h3 id=\"flutter-square-switch-toggle-button\">Flutter Square Switch Toggle Button<\/h3>\n<p>This is of type <strong>square<\/strong>. The tumb and the track of the switch will be of square shape without any border-radius as shown in the below image. Here is the code to develop the square type GFToggle.\u200c\u200c\u200c<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" class=\"kg-image lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--105-.png\" alt=\"\" width=\"725\" height=\"267\" \/><noscript><img decoding=\"async\" class=\"kg-image lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--105-.png\" alt=\"\" width=\"725\" height=\"267\" \/><\/noscript><\/figure>\n<figure class=\"kg-card kg-code-card\">\n<pre><code class=\"language-javascript\"> import 'package:getwidget\/getwidget.dart';\n \nGFToggle(\n    onChanged: (val){},\n    value: true,\n    disabledThumbColor:Colors.black,\n    type: GFToggleType.square,\n )<\/code><\/pre><figcaption><span style=\"white-space: pre-wrap;\">Flutter Square Switch Toggle Button\u00a0<\/span><\/p>\n<\/figcaption><\/figure>\n<h3 id=\"custom-flutter-switch-toggle-button-design\">Custom Flutter Switch Toggle Button Design<\/h3>\n<p>In this<strong> custom type GFToggle<\/strong>, we can use text to show the states as shown in the below image. In enabled or disabled states the text will be <strong>ON<\/strong> or <strong>OFF <\/strong>or it can even be <strong>yes<\/strong> or <strong>no<\/strong> depending upon the requirement. We can customize it by using its properties. The below code is used to get a custom GFToggle<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" class=\"kg-image lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--106-.png\" alt=\"\" width=\"725\" height=\"199\" \/><noscript><img decoding=\"async\" class=\"kg-image lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--106-.png\" alt=\"\" width=\"725\" height=\"199\" \/><\/noscript><\/figure>\n<figure class=\"kg-card kg-code-card\">\n<pre><code class=\"language-javascript\">import 'package:getwidget\/getwidget.dart';\n\nGFToggle(\n   onChanged: null,\n   value: true,\n   enabledThumbColor:Colors.black,\n   enabledTrackColor:Colors.black38,\n   type: GFToggleType.custom,\n ),<\/code><\/pre><figcaption><span style=\"white-space: pre-wrap;\">Custom Flutter Switch Toggle Button<\/span><\/p>\n<\/figcaption><\/figure>\n<h3 id=\"custom-properties\">Custom Properties<\/h3>\n<p>Check out the custom properties list of Flutter <strong>GFToggle Widge<\/strong>t listed below.<\/p>\n<table>\n<thead>\n<tr>\n<th><\/th>\n<th><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>enabledText<\/strong><\/td>\n<td>type of [String] used to add custom text i.e, ON, ENABLE<\/td>\n<\/tr>\n<tr>\n<td><strong>disabledText<\/strong><\/td>\n<td>type of [String] used to add custom text i.e, OFF, DISABLE<\/td>\n<\/tr>\n<tr>\n<td><strong>enabledTextStyle<\/strong><\/td>\n<td>type of [TextStyle] used to define the style properties of enabled text<\/td>\n<\/tr>\n<tr>\n<td><strong>disabledTextStyle<\/strong><\/td>\n<td>type of [TextStyle] used to define the style properties of disabled text<\/td>\n<\/tr>\n<tr>\n<td><strong>enabledThumbColor<\/strong><\/td>\n<td>color used for the active thumb color<\/td>\n<\/tr>\n<tr>\n<td><strong>disabledThumnbColor<\/strong><\/td>\n<td>color used for the disabled thumb color<\/td>\n<\/tr>\n<tr>\n<td><strong>enabledTrackColor<\/strong><\/td>\n<td>color used for the active track color<\/td>\n<\/tr>\n<tr>\n<td><strong>disabledTrackColor<\/strong><\/td>\n<td>color used for the disabled track color<\/td>\n<\/tr>\n<tr>\n<td><strong>boxShape<\/strong><\/td>\n<td>type of [BoxShape] ie ,\u00a0<code style=\"font-family: source-code-pro, Menlo, Monaco, Consolas,;\">circle<\/code>,\u00a0<code style=\"font-family: source-code-pro, Menlo, Monaco, Consolas,;\">rectangle<\/code>\u00a0used to change the shape of the thumb, default shape is\u00a0<code style=\"font-family: source-code-pro, Menlo, Monaco, Consolas,;\">circle<\/code><\/td>\n<\/tr>\n<tr>\n<td><strong>borderRadius<\/strong><\/td>\n<td>borderRadius should be given zero for a\u00a0<strong>ios<\/strong>\u00a0toggle to make it a\u00a0<strong>square<\/strong>\u00a0toggle with\u00a0<strong>boxshape<\/strong>\u00a0as\u00a0<code style=\"font-family: source-code-pro, Menlo, Monaco, Consolas,;\">rectangle<\/code><\/td>\n<\/tr>\n<tr>\n<td><strong>duration<\/strong><\/td>\n<td>animation duration called when the switch animates during the specific time elapse<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"can-we-use-ios-type-toggle-in-android-applications\"><strong>Can we use IOS type toggle in android applications?<\/strong><\/h3>\n<p>Yes, as it is a type so we can use all types of toggles in android and ios applications.\u200c<\/p>\n<p><strong>Also read &#8211; <a href=\"https:\/\/www.getwidget.dev\/blog\/what-is-a-flutter-developer\/\">The Ultimate Guide to Flutter Developer: Hiring and Becoming a Developer, Advantages of Flutter for Mobile App Development<\/a><\/strong><\/p>\n<h3 id=\"how-can-we-add-styles-to-text-widgets-used-in-it\">How Can we add styles to text widgets used in it?<\/h3>\n<p>We can customize it according to the property given. For example, enabledText and its style, disabledText and its style can be used here.\u200c<\/p>\n<h3 id=\"what-is-the-use-of-duration-property-here\">What is the use of duration property here?<\/h3>\n<p>Duration is the animation duration. The animation will last up to the given duration time.<\/p>\n<p><a href=\"https:\/\/docs.getwidget.dev\/\" target=\"_blank\" rel=\"noopener\"><strong>Flutter Get Widget Docs<\/strong><\/a><\/p>\n<figure class=\"kg-card kg-bookmark-card\">\n<div class=\"kg-bookmark-content\">\n<div class=\"kg-bookmark-title\">Flutter GetWidget Docs<\/div>\n<div class=\"kg-bookmark-description\">Get Widget is one of the largest Flutter open-source UI Kit libraries for mobile or web apps. It has more than 1000+ pre-built reusable widgets.<\/div>\n<div class=\"kg-bookmark-metadata\"><img decoding=\"async\" class=\"kg-bookmark-icon lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/favicon_QkjfdlGz1.png\" alt=\"\" \/><noscript><img decoding=\"async\" class=\"kg-bookmark-icon lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/favicon_QkjfdlGz1.png\" alt=\"\" \/><\/noscript><span class=\"kg-bookmark-author\">getwidget<\/span><span class=\"kg-bookmark-publisher\">getwidget<\/span><\/div>\n<\/div>\n<div class=\"kg-bookmark-thumbnail\"><img decoding=\"async\" class=\"lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/docs\/tr:dpr-auto,tr:w-auto\/link-share_aT-cHzGY9.png\" alt=\"\" \/><noscript><img decoding=\"async\" class=\"lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/docs\/tr:dpr-auto,tr:w-auto\/link-share_aT-cHzGY9.png\" alt=\"\" \/><\/noscript><\/div>\n<\/figure>\n<p><a href=\"https:\/\/github.com\/ionicfirebaseapp\/getwidget\/\" target=\"_blank\" rel=\"noopener\"><strong>GitHub Repository<\/strong><\/a>: Please do appreciate our work through Github start<\/p>\n<p><strong>Also Read &#8211; <a href=\"https:\/\/www.getwidget.dev\/blog\/top-10-best-flutter-toggle-widgets-list\/\" rel=\"noreferrer\"><strong>Top 10 Best Flutter Toggle Widgets List<\/strong><\/a><\/strong><\/p>\n<h3 id=\"conclusion\">Conclusion:<\/h3>\n<p>Here we discuss, what<a href=\"https:\/\/docs.getwidget.dev\/gf-toggle\/\" target=\"_blank\" rel=\"noopener\"> <strong>Flutter Toggle<\/strong><\/a> Widget is? And how we can use and implement it into our Flutter app through the <strong>GetWidget<\/strong> Toggle component. Here, there are options to customize and use other types of Toggle.<\/p>\n<h3 id=\"about-our-team\">About Our Team:<\/h3>\n<p>We have been working on Flutter since Flutter launched in beta version in 2017. And our team have been putting hundreds and hundreds of hour to experiment and implementation of Flutter. As well as after successful delivery of enterprise and SAAS applications that have been used by more than 500+ businesses around the 119+ countries. Now we are in love with Flutter development and we are very passionate about Flutter development. Now it is something we are trying to give a small contribution to the <a href=\"https:\/\/forum.getwidget.dev\/\" target=\"_blank\" rel=\"noopener\">Flutter Dev Community<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"Flutter Toggle is a switch that has two state user interface elements to choose between checked or unchecked&hellip;","protected":false},"author":1,"featured_media":5234,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":"","footnotes":""},"categories":[139],"tags":[],"class_list":{"0":"post-7382","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-flutter","8":"cs-entry"},"_links":{"self":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts\/7382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/comments?post=7382"}],"version-history":[{"count":3,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts\/7382\/revisions"}],"predecessor-version":[{"id":8451,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts\/7382\/revisions\/8451"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/media\/5234"}],"wp:attachment":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/media?parent=7382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/categories?post=7382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/tags?post=7382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}