Arrange Buttons in a Row With ToggleButtons Flutter Widget

Arrange Buttons in a Row With ToggleButtons Flutter Widget

Discover Flutter

I don’t know about you, but I love having shortcuts on my phone that give me quick access to some action.

I was thinking in the direction of whether there is a widget that will provide such a look in your app and discovered the ToggleButtons widget.

Image for post

Example of using ToggleButtons

Goal 1. Create Toggle Buttons

To create a toggle button, it is necessary to call ToggleButtons’s constructor. The first step in discovering a new widget is its mandatory arguments. There are two required arguments for this widget:

  • children (List<Widget>) — Each widget in children represents a button and in our case, it would be an Icon.
  • isSelected (List<bool>) — a List of bool containing the state of each button, whether it's selected (if the value is true) or not (if the value is false)

Note: The length of children and isSelected must be the same.

Our goal is to have four toggle buttons, which means that we will create a state variable that will store the state of these four buttons, i.e., whether they are selected or not. We set the initial state of all buttons to false.

Note: Initialize this state variable inside the Stateful widget.

List<bool> _buttonsState = List.generate(4, (index) => false);

The next step is to call the constructor and pass the required parameters.

child: ToggleButtons(
  children: [
  isSelected: _buttonsState

If we run our project, we’ll see the four disabled buttons.

Image for post

Toggle buttons

programming flutter

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

What is Flutter and why you should learn it?

Flutter is an open-source UI toolkit for mobile developers, so they can use it to build native-looking Android and iOS applications from the same code base for both platforms. Flutter is also working to make Flutter apps for Web, PWA (progressive Web-App) and Desktop platform (Windows,macOS,Linux).

Adobe XD plugin for Flutter with CodePen Tutorial

Recently Adobe XD releases a new version of the plugin that you can use to export designs directly into flutter widgets or screens.

Flutter - How to Add AdMob Real Ads in Flutter App | Flutter AdMob Tutorial

Hello Whats is up Everyone So, Today I am going to show u How to Add Admob Real ads in Flutter apps which are very Easy Implement After watching this video u...

Flutter App Development Company India, Flutter App Developers for Hire

IndianAppDevelopers offers Flutter app development services in India for Android and iOS, Hire our flutter developers to create native experience apps for the end-users.