mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Part of https://github.com/flutter/flutter/issues/168787 Add the ability to customize the inner radius of the `Radio` button https://github.com/user-attachments/assets/234fffda-f42f-463f-bc97-284c160c86ef <img width="274" alt="Screenshot 2025-06-28 at 6 23 11 PM" src="https://github.com/user-attachments/assets/45a0525d-ff94-4fb3-85d3-0d2353b39e98" /> ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
108 lines
3.2 KiB
Dart
108 lines
3.2 KiB
Dart
// 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] to showcase how to customize radio style.
|
|
|
|
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 RadioType { fillColor, backgroundColor, side, innerRadius }
|
|
|
|
class RadioExample extends StatefulWidget {
|
|
const RadioExample({super.key});
|
|
|
|
@override
|
|
State<RadioExample> createState() => _RadioExampleState();
|
|
}
|
|
|
|
class _RadioExampleState extends State<RadioExample> {
|
|
RadioType? _radioType = RadioType.fillColor;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return RadioGroup<RadioType>(
|
|
groupValue: _radioType,
|
|
onChanged: (RadioType? value) {
|
|
setState(() {
|
|
_radioType = value;
|
|
});
|
|
},
|
|
child: Column(
|
|
children: <Widget>[
|
|
ListTile(
|
|
title: const Text('Fill color'),
|
|
leading: Radio<RadioType>(
|
|
value: RadioType.fillColor,
|
|
fillColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
|
|
if (states.contains(WidgetState.selected)) {
|
|
return Colors.deepPurple;
|
|
} else {
|
|
return Colors.deepPurple.shade200;
|
|
}
|
|
}),
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text('Background color'),
|
|
leading: Radio<RadioType>(
|
|
value: RadioType.backgroundColor,
|
|
backgroundColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
|
|
if (states.contains(WidgetState.selected)) {
|
|
return Colors.greenAccent.withOpacity(0.5);
|
|
} else {
|
|
return Colors.grey.shade300.withOpacity(0.3);
|
|
}
|
|
}),
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text('Side'),
|
|
leading: Radio<RadioType>(
|
|
value: RadioType.side,
|
|
side: WidgetStateBorderSide.resolveWith((Set<WidgetState> states) {
|
|
if (states.contains(MaterialState.selected)) {
|
|
return const BorderSide(
|
|
color: Colors.red,
|
|
width: 4,
|
|
strokeAlign: BorderSide.strokeAlignCenter,
|
|
);
|
|
} else {
|
|
return const BorderSide(
|
|
color: Colors.grey,
|
|
width: 1.5,
|
|
strokeAlign: BorderSide.strokeAlignCenter,
|
|
);
|
|
}
|
|
}),
|
|
),
|
|
),
|
|
|
|
const ListTile(
|
|
title: Text('Inner radius'),
|
|
leading: Radio<RadioType>(
|
|
value: RadioType.innerRadius,
|
|
innerRadius: WidgetStatePropertyAll<double>(6),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|