mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
CheckboxListTile: add property to scale the checkbox (#154806)
Added a property in the CheckboxListTile to scale the underlying Checkbox using `Transform.scale`. Fixes: #81334
This commit is contained in:
parent
672eebc55b
commit
bae7971431
@ -205,6 +205,7 @@ class CheckboxListTile extends StatelessWidget {
|
||||
this.onFocusChange,
|
||||
this.enableFeedback,
|
||||
this.checkboxSemanticLabel,
|
||||
this.checkboxScaleFactor = 1.0,
|
||||
this.internalAddSemanticForOnTap = false,
|
||||
}) : _checkboxType = _CheckboxType.material,
|
||||
assert(tristate || value != null),
|
||||
@ -250,6 +251,7 @@ class CheckboxListTile extends StatelessWidget {
|
||||
this.onFocusChange,
|
||||
this.enableFeedback,
|
||||
this.checkboxSemanticLabel,
|
||||
this.checkboxScaleFactor = 1.0,
|
||||
this.internalAddSemanticForOnTap = false,
|
||||
}) : _checkboxType = _CheckboxType.adaptive,
|
||||
assert(tristate || value != null),
|
||||
@ -473,6 +475,11 @@ class CheckboxListTile extends StatelessWidget {
|
||||
// the default value to true.
|
||||
final bool internalAddSemanticForOnTap;
|
||||
|
||||
/// Controls the scaling factor applied to the [Checkbox] within the [CheckboxListTile].
|
||||
///
|
||||
/// Defaults to 1.0.
|
||||
final double checkboxScaleFactor;
|
||||
|
||||
/// {@macro flutter.material.checkbox.semanticLabel}
|
||||
final String? checkboxSemanticLabel;
|
||||
|
||||
@ -497,44 +504,50 @@ class CheckboxListTile extends StatelessWidget {
|
||||
switch (_checkboxType) {
|
||||
case _CheckboxType.material:
|
||||
control = ExcludeFocus(
|
||||
child: Checkbox(
|
||||
value: value,
|
||||
onChanged: enabled ?? true ? onChanged : null,
|
||||
mouseCursor: mouseCursor,
|
||||
activeColor: activeColor,
|
||||
fillColor: fillColor,
|
||||
checkColor: checkColor,
|
||||
hoverColor: hoverColor,
|
||||
overlayColor: overlayColor,
|
||||
splashRadius: splashRadius,
|
||||
materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap,
|
||||
autofocus: autofocus,
|
||||
tristate: tristate,
|
||||
shape: checkboxShape,
|
||||
side: side,
|
||||
isError: isError,
|
||||
semanticLabel: checkboxSemanticLabel,
|
||||
child: Transform.scale(
|
||||
scale: checkboxScaleFactor,
|
||||
child: Checkbox(
|
||||
value: value,
|
||||
onChanged: enabled ?? true ? onChanged : null,
|
||||
mouseCursor: mouseCursor,
|
||||
activeColor: activeColor,
|
||||
fillColor: fillColor,
|
||||
checkColor: checkColor,
|
||||
hoverColor: hoverColor,
|
||||
overlayColor: overlayColor,
|
||||
splashRadius: splashRadius,
|
||||
materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap,
|
||||
autofocus: autofocus,
|
||||
tristate: tristate,
|
||||
shape: checkboxShape,
|
||||
side: side,
|
||||
isError: isError,
|
||||
semanticLabel: checkboxSemanticLabel,
|
||||
),
|
||||
),
|
||||
);
|
||||
case _CheckboxType.adaptive:
|
||||
control = ExcludeFocus(
|
||||
child: Checkbox.adaptive(
|
||||
value: value,
|
||||
onChanged: enabled ?? true ? onChanged : null,
|
||||
mouseCursor: mouseCursor,
|
||||
activeColor: activeColor,
|
||||
fillColor: fillColor,
|
||||
checkColor: checkColor,
|
||||
hoverColor: hoverColor,
|
||||
overlayColor: overlayColor,
|
||||
splashRadius: splashRadius,
|
||||
materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap,
|
||||
autofocus: autofocus,
|
||||
tristate: tristate,
|
||||
shape: checkboxShape,
|
||||
side: side,
|
||||
isError: isError,
|
||||
semanticLabel: checkboxSemanticLabel,
|
||||
child: Transform.scale(
|
||||
scale: checkboxScaleFactor,
|
||||
child: Checkbox.adaptive(
|
||||
value: value,
|
||||
onChanged: enabled ?? true ? onChanged : null,
|
||||
mouseCursor: mouseCursor,
|
||||
activeColor: activeColor,
|
||||
fillColor: fillColor,
|
||||
checkColor: checkColor,
|
||||
hoverColor: hoverColor,
|
||||
overlayColor: overlayColor,
|
||||
splashRadius: splashRadius,
|
||||
materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap,
|
||||
autofocus: autofocus,
|
||||
tristate: tristate,
|
||||
shape: checkboxShape,
|
||||
side: side,
|
||||
isError: isError,
|
||||
semanticLabel: checkboxSemanticLabel,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1266,6 +1266,49 @@ void main() {
|
||||
final Offset offsetPlatform = tester.getTopLeft(platform);
|
||||
expect(offsetPlatform, const Offset(736.0, 8.0));
|
||||
});
|
||||
|
||||
testWidgets('CheckboxListTile renders with default scale', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(
|
||||
home: Material(
|
||||
child: CheckboxListTile(
|
||||
value: false,
|
||||
onChanged: null,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
final Transform widget = tester.widget(
|
||||
find.ancestor(
|
||||
of: find.byType(Checkbox),
|
||||
matching: find.byType(Transform),
|
||||
),
|
||||
);
|
||||
|
||||
expect(widget.transform.getMaxScaleOnAxis(), 1.0);
|
||||
});
|
||||
|
||||
testWidgets('CheckboxListTile respects checkboxScaleFactor', (WidgetTester tester) async {
|
||||
const double scale = 1.5;
|
||||
|
||||
await tester.pumpWidget(const MaterialApp(
|
||||
home: Material(
|
||||
child: CheckboxListTile(
|
||||
value: false,
|
||||
onChanged: null,
|
||||
checkboxScaleFactor: scale,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
final Transform widget = tester.widget(
|
||||
find.ancestor(
|
||||
of: find.byType(Checkbox),
|
||||
matching: find.byType(Transform),
|
||||
),
|
||||
);
|
||||
|
||||
expect(widget.transform.getMaxScaleOnAxis(), scale);
|
||||
});
|
||||
}
|
||||
|
||||
class _SelectedGrabMouseCursor extends MaterialStateMouseCursor {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user