| 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'package:flutter/material.dart'; |
| 6 | |
| 7 | /// Flutter code sample for [RadioListTile.toggleable]. |
| 8 | |
| 9 | void main() => runApp(const RadioListTileApp()); |
| 10 | |
| 11 | class RadioListTileApp extends StatelessWidget { |
| 12 | const RadioListTileApp({super.key}); |
| 13 | |
| 14 | @override |
| 15 | Widget build(BuildContext context) { |
| 16 | return MaterialApp( |
| 17 | home: Scaffold( |
| 18 | appBar: AppBar(title: const Text('RadioListTile.toggleable Sample' )), |
| 19 | body: const RadioListTileExample(), |
| 20 | ), |
| 21 | ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | class RadioListTileExample extends StatefulWidget { |
| 26 | const RadioListTileExample({super.key}); |
| 27 | |
| 28 | @override |
| 29 | State<RadioListTileExample> createState() => _RadioListTileExampleState(); |
| 30 | } |
| 31 | |
| 32 | class _RadioListTileExampleState extends State<RadioListTileExample> { |
| 33 | int? groupValue; |
| 34 | static const List<String> selections = <String>[ |
| 35 | 'Hercules Mulligan' , |
| 36 | 'Eliza Hamilton' , |
| 37 | 'Philip Schuyler' , |
| 38 | 'Maria Reynolds' , |
| 39 | 'Samuel Seabury' , |
| 40 | ]; |
| 41 | |
| 42 | @override |
| 43 | Widget build(BuildContext context) { |
| 44 | return Scaffold( |
| 45 | body: RadioGroup<int>( |
| 46 | groupValue: groupValue, |
| 47 | onChanged: (int? value) { |
| 48 | setState(() { |
| 49 | groupValue = value; |
| 50 | }); |
| 51 | }, |
| 52 | child: ListView.builder( |
| 53 | itemBuilder: (BuildContext context, int index) { |
| 54 | return RadioListTile<int>( |
| 55 | value: index, |
| 56 | toggleable: true, |
| 57 | title: Text(selections[index]), |
| 58 | ); |
| 59 | }, |
| 60 | itemCount: selections.length, |
| 61 | ), |
| 62 | ), |
| 63 | ); |
| 64 | } |
| 65 | } |
| 66 | |