// 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'; import 'controls_constants.dart'; export 'controls_constants.dart'; /// A test page with a checkbox, three radio buttons, and a switch. class SelectionControlsPage extends StatefulWidget { const SelectionControlsPage({super.key}); @override State createState() => _SelectionControlsPageState(); } class _SelectionControlsPageState extends State { static const ValueKey checkbox1Key = ValueKey(checkboxKeyValue); static const ValueKey checkbox2Key = ValueKey(disabledCheckboxKeyValue); static const ValueKey radio1Key = ValueKey(radio1KeyValue); static const ValueKey radio2Key = ValueKey(radio2KeyValue); static const ValueKey radio3Key = ValueKey(radio3KeyValue); static const ValueKey switchKey = ValueKey(switchKeyValue); static const ValueKey labeledSwitchKey = ValueKey(labeledSwitchKeyValue); bool _isChecked = false; bool _isOn = false; bool _isLabeledOn = false; int _radio = 0; void _updateCheckbox(bool? newValue) { setState(() { _isChecked = newValue!; }); } void _updateRadio(int? newValue) { setState(() { _radio = newValue!; }); } void _updateSwitch(bool newValue) { setState(() { _isOn = newValue; }); } void _updateLabeledSwitch(bool newValue) { setState(() { _isLabeledOn = newValue; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(leading: const BackButton(key: ValueKey('back'))), body: Material( child: Column( children: [ Row( children: [ Checkbox(key: checkbox1Key, value: _isChecked, onChanged: _updateCheckbox), const Checkbox(key: checkbox2Key, value: false, onChanged: null), ], ), const Spacer(), Row( children: [ Radio(key: radio1Key, value: 0, groupValue: _radio, onChanged: _updateRadio), Radio(key: radio2Key, value: 1, groupValue: _radio, onChanged: _updateRadio), Radio(key: radio3Key, value: 2, groupValue: _radio, onChanged: _updateRadio), ], ), const Spacer(), Switch(key: switchKey, value: _isOn, onChanged: _updateSwitch), const Spacer(), MergeSemantics( child: Row( children: [ const Text(switchLabel), Switch( key: labeledSwitchKey, value: _isLabeledOn, onChanged: _updateLabeledSwitch, ), ], ), ), ], ), ), ); } }