
Remove more `textScaleFactor` references from flutter/flutter. - Some changes are related to label scaling: the padding EdgeInsets values of some chip subclasses scale linearly between predetermined "max" padding values and "min" padding values. Before they scale with the `textScaleFactor` scalar, now they scale with the font size and are still capped at the original "max" and "min" values. - The rest of them are tests or size heuristics that depend on `textScaleFactor`, these are replaced by an effective text scale factor computed using a default font size (which is determined in a pretty random fashion, but it will only make a difference on Android 14+). No API changes in this batch. There are still some references left that I intend to remove in a different batch that would introduce API changes.
86 lines
2.9 KiB
Dart
86 lines
2.9 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 'template.dart';
|
|
|
|
class ChipTemplate extends TokenTemplate {
|
|
const ChipTemplate(super.blockName, super.fileName, super.tokens, {
|
|
super.colorSchemePrefix = '_colors.',
|
|
super.textThemePrefix = '_textTheme.'
|
|
});
|
|
|
|
static const String tokenGroup = 'md.comp.assist-chip';
|
|
static const String variant = '.flat';
|
|
|
|
@override
|
|
String generate() => '''
|
|
class _${blockName}DefaultsM3 extends ChipThemeData {
|
|
_${blockName}DefaultsM3(this.context, this.isEnabled)
|
|
: super(
|
|
elevation: ${elevation("$tokenGroup$variant.container")},
|
|
shape: ${shape("$tokenGroup.container")},
|
|
showCheckmark: true,
|
|
);
|
|
|
|
final BuildContext context;
|
|
final bool isEnabled;
|
|
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
|
late final TextTheme _textTheme = Theme.of(context).textTheme;
|
|
|
|
@override
|
|
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")};
|
|
|
|
@override
|
|
MaterialStateProperty<Color?>? get color => null; // Subclasses override this getter
|
|
|
|
@override
|
|
Color? get shadowColor => ${colorOrTransparent("$tokenGroup.container.shadow-color")};
|
|
|
|
@override
|
|
Color? get surfaceTintColor => ${colorOrTransparent("$tokenGroup.container.surface-tint-layer.color")};
|
|
|
|
@override
|
|
Color? get checkmarkColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
|
|
|
|
@override
|
|
Color? get deleteIconColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
|
|
|
|
@override
|
|
BorderSide? get side => isEnabled
|
|
? ${border('$tokenGroup$variant.outline')}
|
|
: ${border('$tokenGroup$variant.disabled.outline')};
|
|
|
|
@override
|
|
IconThemeData? get iconTheme => IconThemeData(
|
|
color: isEnabled
|
|
? ${color("$tokenGroup.with-icon.icon.color")}
|
|
: ${color("$tokenGroup.with-icon.disabled.icon.color")},
|
|
size: ${getToken("$tokenGroup.with-icon.icon.size")},
|
|
);
|
|
|
|
@override
|
|
EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0);
|
|
|
|
/// The label padding of the chip scales with the font size specified in the
|
|
/// [labelStyle], and the system font size settings that scale font sizes
|
|
/// globally.
|
|
///
|
|
/// The chip at effective font size 14.0 starts with 8px on each side and as
|
|
/// the font size scales up to closer to 28.0, the label padding is linearly
|
|
/// interpolated from 8px to 4px. Once the label has a font size of 2 or
|
|
/// higher, label padding remains 4px.
|
|
@override
|
|
EdgeInsetsGeometry? get labelPadding {
|
|
final double fontSize = labelStyle?.fontSize ?? 14.0;
|
|
final double fontSizeRatio = MediaQuery.textScalerOf(context).scale(fontSize) / 14.0;
|
|
return EdgeInsets.lerp(
|
|
const EdgeInsets.symmetric(horizontal: 8.0),
|
|
const EdgeInsets.symmetric(horizontal: 4.0),
|
|
clampDouble(fontSizeRatio - 1.0, 0.0, 1.0),
|
|
)!;
|
|
}
|
|
}
|
|
''';
|
|
}
|