Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Do not edit by hand. The code is generated from data in the Material
// Design token database by the script:
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
part of '../input_chip.dart';

class _InputChipDefaultsM3 extends ChipThemeData {
_InputChipDefaultsM3(this.context, this.isEnabled, this.isSelected)
: super(
Expand Down
111 changes: 2 additions & 109 deletions packages/material_ui/lib/src/input_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import 'text_theme.dart';
import 'theme.dart';
import 'theme_data.dart';

part 'generated/input_chip_defaults_m3.g.dart';

/// A Material Design input chip.
///
/// Input chips represent a complex piece of information, such as an entity
Expand Down Expand Up @@ -275,112 +277,3 @@ class InputChip extends StatelessWidget
);
}
}

// BEGIN GENERATED TOKEN PROPERTIES - InputChip

// Do not edit by hand. The code between the "BEGIN GENERATED" and
// "END GENERATED" comments are generated from data in the Material
// Design token database by the script:
// dev/tools/gen_defaults/bin/gen_defaults.dart.

// dart format off
class _InputChipDefaultsM3 extends ChipThemeData {
_InputChipDefaultsM3(this.context, this.isEnabled, this.isSelected)
: super(
elevation: 0.0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
showCheckmark: true,
);

final BuildContext context;
final bool isEnabled;
final bool isSelected;
late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme;

@override
TextStyle? get labelStyle => _textTheme.labelLarge?.copyWith(
color: isEnabled
? isSelected
? _colors.onSecondaryContainer
: _colors.onSurfaceVariant
: _colors.onSurface,
);

@override
WidgetStateProperty<Color?>? get color =>
WidgetStateProperty.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.selected) && states.contains(WidgetState.disabled)) {
return _colors.onSurface.withOpacity(0.12);
}
if (states.contains(WidgetState.disabled)) {
return null;
}
if (states.contains(WidgetState.selected)) {
return _colors.secondaryContainer;
}
return null;
});

@override
Color? get shadowColor => Colors.transparent;

@override
Color? get surfaceTintColor => Colors.transparent;

@override
Color? get checkmarkColor => isEnabled
? isSelected
? _colors.primary
: _colors.onSurfaceVariant
: _colors.onSurface;

@override
Color? get deleteIconColor => isEnabled
? isSelected
? _colors.onSecondaryContainer
: _colors.onSurfaceVariant
: _colors.onSurface;

@override
BorderSide? get side => !isSelected
? isEnabled
? BorderSide(color: _colors.outlineVariant)
: BorderSide(color: _colors.onSurface.withOpacity(0.12))
: const BorderSide(color: Colors.transparent);

@override
IconThemeData? get iconTheme => IconThemeData(
color: isEnabled
? isSelected
? _colors.primary
: _colors.onSurfaceVariant
: _colors.onSurface,
size: 18.0,
);

@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),
)!;
}
}
// dart format on

// END GENERATED TOKEN PROPERTIES - InputChip
5 changes: 3 additions & 2 deletions packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import '../templates/card_template.dart';
// import '../templates/fab_template.dart';
// import '../templates/filter_chip_template.dart';
// import '../templates/icon_button_template.dart';
// import '../templates/input_chip_template.dart';
import '../templates/input_chip_template.dart';

// import '../templates/input_decorator_template.dart';
// import '../templates/list_tile_template.dart';
// import '../templates/menu_template.dart';
Expand Down Expand Up @@ -89,7 +90,7 @@ Future<void> main(List<String> args) async {
// const FabTemplateM3().generateFile(verbose: verbose);
// const FilterChipTemplateM3().generateFile(verbose: verbose);
// const IconButtonTemplateM3().generateFile(verbose: verbose);
// const InputChipTemplateM3().generateFile(verbose: verbose);
const InputChipTemplateM3().generateFile(verbose: verbose);
// const InputDecoratorTemplateM3().generateFile(verbose: verbose);
// const ListTileTemplateM3().generateFile(verbose: verbose);
// const MenuTemplateM3().generateFile(verbose: verbose);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../data/input_chip.dart';
import 'template.dart';

class InputChipTemplateM3 extends TokenTemplateM3 {
const InputChipTemplateM3();

@override
String get name => 'Input Chip';

@override
String get parentFilePath => 'input_chip.dart';

// TODO(QuncCccccc): Replace these values if padding tokens become available.
static const double _defaultPadding = 8.0;
static const double _minimumLabelPadding = 4.0;

@override
String generateContents(String className) =>
'''
class $className extends ChipThemeData {
$className(this.context, this.isEnabled, this.isSelected)
: super(
elevation: ${TokenInputChip.containerElevation},
shape: ${shape(TokenInputChip.containerShape)},
showCheckmark: true,
);

final BuildContext context;
final bool isEnabled;
final bool isSelected;
late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme;

@override
TextStyle? get labelStyle => ${textStyle(TokenInputChip.labelTextType, '_textTheme')}?.copyWith(
color: isEnabled
? isSelected
? ${color(TokenInputChip.selectedLabelTextColor)}
: ${color(TokenInputChip.unselectedLabelTextColor)}
: ${color(TokenInputChip.disabledLabelTextColor)},
);

@override
WidgetStateProperty<Color?>? get color =>
WidgetStateProperty.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.selected) && states.contains(WidgetState.disabled)) {
return ${colorWithOpacity(TokenInputChip.disabledSelectedContainerColor, TokenInputChip.disabledSelectedContainerOpacity)};
}
if (states.contains(WidgetState.disabled)) {
return null;
}
if (states.contains(WidgetState.selected)) {
return ${color(TokenInputChip.selectedContainerColor)};
}
return null;
});

@override
Color? get shadowColor => Colors.transparent;

@override
Color? get surfaceTintColor => Colors.transparent;

@override
Color? get checkmarkColor => isEnabled
? isSelected
? ${color(TokenInputChip.withLeadingIconSelectedLeadingIconColor)}
: ${color(TokenInputChip.withLeadingIconUnselectedLeadingIconColor)}
: ${color(TokenInputChip.withLeadingIconDisabledLeadingIconColor)};

@override
Color? get deleteIconColor => isEnabled
? isSelected
? ${color(TokenInputChip.withTrailingIconSelectedTrailingIconColor)}
: ${color(TokenInputChip.withTrailingIconUnselectedTrailingIconColor)}
: ${color(TokenInputChip.withTrailingIconDisabledTrailingIconColor)};

@override
BorderSide? get side => !isSelected
? isEnabled
? ${border(color(TokenInputChip.unselectedOutlineColor), width: TokenInputChip.unselectedOutlineWidth)}
: ${border(colorWithOpacity(TokenInputChip.disabledUnselectedOutlineColor, TokenInputChip.disabledUnselectedOutlineOpacity))}
: const BorderSide(color: Colors.transparent);

@override
IconThemeData? get iconTheme => IconThemeData(
color: isEnabled
? isSelected
? ${color(TokenInputChip.withLeadingIconSelectedLeadingIconColor)}
: ${color(TokenInputChip.withLeadingIconUnselectedLeadingIconColor)}
: ${color(TokenInputChip.withLeadingIconDisabledLeadingIconColor)},
size: ${TokenInputChip.withLeadingIconLeadingIconSize},
);

@override
EdgeInsetsGeometry? get padding => const EdgeInsets.all(${number(_defaultPadding)});

/// 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 ?? ${number(TokenInputChip.labelTextType.fontSize)};
final double fontSizeRatio = MediaQuery.textScalerOf(context).scale(fontSize) / ${number(TokenInputChip.labelTextType.fontSize)};
return EdgeInsets.lerp(
const EdgeInsets.symmetric(horizontal: ${number(_defaultPadding)}),
const EdgeInsets.symmetric(horizontal: ${number(_minimumLabelPadding)}),
clampDouble(fontSizeRatio - 1.0, 0.0, 1.0),
)!;
}
}
''';
}

This file was deleted.

Loading
Loading