// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/material.dart'; /// Flutter code sample for [Radio]. void main() => runApp(const RadioExampleApp()); class RadioExampleApp extends StatelessWidget { const RadioExampleApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Radio Sample')), body: const Center( child: RadioExample(), ), ), ); } } enum SingingCharacter { lafayette, jefferson } class RadioExample extends StatefulWidget { const RadioExample({super.key}); @override State createState() => _RadioExampleState(); } class _RadioExampleState extends State { SingingCharacter? _character = SingingCharacter.lafayette; @override Widget build(BuildContext context) { return Column( children: [ ListTile( title: const Text('Lafayette'), leading: Radio( value: SingingCharacter.lafayette, groupValue: _character, onChanged: (SingingCharacter? value) { setState(() { _character = value; }); }, ), ), ListTile( title: const Text('Thomas Jefferson'), leading: Radio( value: SingingCharacter.jefferson, groupValue: _character, onChanged: (SingingCharacter? value) { setState(() { _character = value; }); }, ), ), ], ); } }