Switch proposal: Expose _SwitchConfig
configuration
#131478
Labels
c: proposal
A detailed proposal for a change to Flutter
customer: crowd
Affects or could affect many people, though not necessarily a specific customer.
f: material design
flutter/packages/flutter/material repository.
framework
flutter/packages/flutter repository. See also f: labels.
P3
Issues that are less important to the Flutter project
team-design
Owned by Design Languages team
triaged-design
Triaged by Design Languages team
Is there an existing issue for this?
Use case
The
Switch
has many useful styling configuration options hidden in a private mixin class called_SwitchConfig
.flutter/packages/flutter/lib/src/material/switch.dart
Line 1626 in 0ff68b8
The addition of it is a part of what enables the same component to change its look from Material2 to Material3, by using its internal configuration options.
These configuration options would be very useful when creating custom
Switch
designs. For example, currently theSwitch
in Flutter can currently not even mimic the "official" custom switch style used in Android system settings by Google's Pixel phones, shown below:Pixel7Pro-Switch.mp4
Android System Settings Switch Style - Recorded on Pixel7Pro
In this design, the Switch thumb is fixed size, and the height of the switch is more narrow and without a border.
While we could remove the borders from the M3 Switch and even fake the
Switch
thumb being fixed sized by adding a transparent icon, we cannot change the size of the thumb radius, or even height of theSwitch
track.Screen.Recording.2023-07-28.at.15.41.16.mov
Fake fixed thumb size is doable, but size changes are not
Fixed Switch Size Example Code
The code sample used for the fixed
Code sample
Used Flutter version
Channel master, 3.13.0-11.0.pre.24
Flutter doctor
Proposal
Refactor
_SwitchConfig
class to a public classSwitchConfig
and add it as a public configuration propertyswitchConfig
(or namedswitchStyle
) to theSwitch
widget and itsSwitchThemeData
.This type of configuration class would be much in-line with current sub-config classes
ButtonStyle
andMenyStyle
, used in many themes and widgets. Considering those name precedents, maybe a better name would beSwitchStyle
.A public
SwitchStyle
(orSwitchConfig
) would need to use mixinDiagnosticable
" and implementdebugFillProperties
,copyWith
,merge
,lerp
,hashCode
andoperator
==.It should be reasonably straight forward to do this refactoring.
The text was updated successfully, but these errors were encountered: