From 4d5c0264d92eec5940b96fa30e0ed053d641ae8f Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Thu, 13 Jan 2022 02:10:12 -0600 Subject: [PATCH] MaterialStateProperty Docs (#96532) --- .../flutter/lib/src/material/checkbox.dart | 19 ++++++++++ packages/flutter/lib/src/material/radio.dart | 20 ++++++++++ packages/flutter/lib/src/material/switch.dart | 38 +++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/packages/flutter/lib/src/material/checkbox.dart b/packages/flutter/lib/src/material/checkbox.dart index d209dc1b1a..c1d21f0d5a 100644 --- a/packages/flutter/lib/src/material/checkbox.dart +++ b/packages/flutter/lib/src/material/checkbox.dart @@ -161,6 +161,25 @@ class Checkbox extends StatefulWidget { /// * [MaterialState.hovered]. /// * [MaterialState.focused]. /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [fillColor] based on the current [MaterialState] + /// of the [Checkbox], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Checkbox( + /// value: true, + /// onChanged: (_){}, + /// fillColor: MaterialStateProperty.resolveWith((states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.32); + /// } + /// return Colors.orange; + /// }) + /// ) + /// ``` + /// {@end-tool} /// {@endtemplate} /// /// If null, then the value of [activeColor] is used in the selected diff --git a/packages/flutter/lib/src/material/radio.dart b/packages/flutter/lib/src/material/radio.dart index d320f0d8c5..444a1bc5b9 100644 --- a/packages/flutter/lib/src/material/radio.dart +++ b/packages/flutter/lib/src/material/radio.dart @@ -189,6 +189,26 @@ class Radio extends StatefulWidget { /// * [MaterialState.hovered]. /// * [MaterialState.focused]. /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [fillColor] based on the current [MaterialState] + /// of the [Radio], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Radio( + /// value: 1, + /// groupValue: 1, + /// onChanged: (_){}, + /// fillColor: MaterialStateProperty.resolveWith((states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.32); + /// } + /// return Colors.orange; + /// }) + /// ) + /// ``` + /// {@end-tool} /// {@endtemplate} /// /// If null, then the value of [activeColor] is used in the selected state. If diff --git a/packages/flutter/lib/src/material/switch.dart b/packages/flutter/lib/src/material/switch.dart index b3eb1c84aa..6a71b7f782 100644 --- a/packages/flutter/lib/src/material/switch.dart +++ b/packages/flutter/lib/src/material/switch.dart @@ -229,6 +229,25 @@ class Switch extends StatelessWidget { /// * [MaterialState.hovered]. /// * [MaterialState.focused]. /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [thumbColor] based on the current + /// [MaterialState] of the [Switch], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Switch( + /// value: true, + /// onChanged: (_) => true, + /// thumbColor: MaterialStateProperty.resolveWith((states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.48); + /// } + /// return Colors.orange; + /// }), + /// ) + /// ``` + /// {@end-tool} /// {@endtemplate} /// /// If null, then the value of [activeColor] is used in the selected @@ -251,6 +270,25 @@ class Switch extends StatelessWidget { /// * [MaterialState.hovered]. /// * [MaterialState.focused]. /// * [MaterialState.disabled]. + /// + /// {@tool snippet} + /// This example resolves the [trackColor] based on the current + /// [MaterialState] of the [Switch], providing a different [Color] when it is + /// [MaterialState.disabled]. + /// + /// ```dart + /// Switch( + /// value: true, + /// onChanged: (_) => true, + /// thumbColor: MaterialStateProperty.resolveWith((states) { + /// if (states.contains(MaterialState.disabled)) { + /// return Colors.orange.withOpacity(.48); + /// } + /// return Colors.orange; + /// }), + /// ) + /// ``` + /// {@end-tool} /// {@endtemplate} /// /// If null, then the value of [activeTrackColor] is used in the selected