Better Programming

Advice for programmers.

Follow publication

Member-only story

Arrange Buttons in a Row With ToggleButtons Flutter Widget

Jelena Jovanoski
Better Programming
Published in
4 min readNov 17, 2020
person sail-gliding in steep mountains
Photo by Leonardo Yip on Unsplash

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.

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.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Jelena Jovanoski
Jelena Jovanoski

Written by Jelena Jovanoski

On my journey to become a Flutter dev I will be sharing knowledge by writing short texts about what new know-how’s I’ve learned, in the next 30 weeks.

No responses yet

Write a response