![]() |
VOOZH | about |
RadioListTile is a widget that combines a radio button with a list tile. It is often used in scenarios where you need to present a list of mutually exclusive options, and the user can select one option from the list. Each RadioListTile represents a single option in the list and consists of a title, a subtitle, an optional leading or trailing widget, and a radio button.
In this article, we are going to implement the RadioListTile widget and explore some of it. A demo video is given below to get an idea of what we are going to do in this article.
To build this app, you need the following items installed on your machine:
Create a new Flutter application using the command Prompt. To create a new app, write the following command and run it.
flutter create app_nameTo know more about it refer this article: Creating a Simple Application in Flutter.
First of all, import material.dart file.
import 'package:flutter/material.dart';Call the runApp() method in the main() method to start the app.
In this class, we are going to implement the MaterialApp, Here, we are also setting the Theme of our App.
In this class, we are going to implement the RadioListTileExample widget that helps to create a Radio Button with a ListTile.
RadioListTile(
title: Text('Option 1'), // Display the title for option 1
subtitle: Text('Subtitle for Option 1'), // Display a subtitle for option 1
value: 1, // Assign a value of 1 to this option
groupValue:
_selectedValue, // Use _selectedValue to track the selected option
onChanged: (value) {
setState(() {
_selectedValue = value!; // Update _selectedValue when option 1 is selected
});
},
),
Code:
main.dart: