
fixes [Chip border side color not working in Material3](https://github.com/flutter/flutter/issues/132922) ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( useMaterial3: true, chipTheme: const ChipThemeData( // shape: RoundedRectangleBorder( // side: BorderSide(color: Colors.amber), // borderRadius: BorderRadius.all(Radius.circular(12)), // ), // side: BorderSide(color: Colors.red), ), ), home: const Example(), ); } } class Example extends StatelessWidget { const Example({super.key}); @override Widget build(BuildContext context) { return const Scaffold( body: Center( child: RawChip( shape: RoundedRectangleBorder( side: BorderSide(color: Colors.amber), borderRadius: BorderRadius.all(Radius.circular(12)), ), // side: BorderSide(color: Colors.red), label: Text('Chip'), ), ), ); } } ``` </details> --- ### Before When `RawChip.shape` is provided with a `BorderSide`. ```dart body: Center( child: RawChip( shape: RoundedRectangleBorder( side: BorderSide(color: Colors.amber), borderRadius: BorderRadius.all(Radius.circular(12)), ), label: Text('Chip'), ), ), ```  When `RawChip.shape` is provided with a `BorderSide` and also `RawChip.side` is provided. The `RawChip.side` overrides the shape's side. ```dart body: Center( child: RawChip( shape: RoundedRectangleBorder( side: BorderSide(color: Colors.amber), borderRadius: BorderRadius.all(Radius.circular(12)), ), side: BorderSide(color: Colors.red), label: Text('Chip'), ), ), ```  --- ### After When `RawChip.shape` is provided with a `BorderSide`. ```dart body: Center( child: RawChip( shape: RoundedRectangleBorder( side: BorderSide(color: Colors.amber), borderRadius: BorderRadius.all(Radius.circular(12)), ), label: Text('Chip'), ), ), ```  When `RawChip.shape` is provided with a `BorderSide` and also `RawChip.side` is provided. The `RawChip.side` overrides the shape's side. ```dart body: Center( child: RawChip( shape: RoundedRectangleBorder( side: BorderSide(color: Colors.amber), borderRadius: BorderRadius.all(Radius.circular(12)), ), side: BorderSide(color: Colors.red), label: Text('Chip'), ), ), ```  ---
81 lines
2.6 KiB
Dart
81 lines
2.6 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")},
|
|
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
|
|
OutlinedBorder? get shape {
|
|
return ${shape("$tokenGroup.container")}.copyWith(
|
|
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 chip at text scale 1 starts with 8px on each side and as text scaling
|
|
/// gets closer to 2, the label padding is linearly interpolated from 8px to 4px.
|
|
/// Once the widget has a text scaling of 2 or higher than the label padding
|
|
/// remains 4px.
|
|
@override
|
|
EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp(
|
|
const EdgeInsets.symmetric(horizontal: 8.0),
|
|
const EdgeInsets.symmetric(horizontal: 4.0),
|
|
clampDouble(MediaQuery.textScalerOf(context).textScaleFactor - 1.0, 0.0, 1.0),
|
|
)!;
|
|
}
|
|
''';
|
|
}
|