From 3b7ed0006cc60c5c6d4db1493844fbeb811e46ce Mon Sep 17 00:00:00 2001 From: asci Date: Tue, 9 Jan 2024 08:06:10 +0900 Subject: [PATCH] [docs] Add document content related to chip shape (#140015) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (#139572) I would like to request an update to the document to resolve confusion. I actually modified the code by applying priority as in the comment in [#139572](https://github.com/flutter/flutter/issues/139572) as shown below, but I thought that if 'OutlinedBorder' was used for 'shape', the default value of side for 'OutlinedBorder' was also the developer's intention. ``` OutlinedBorder _getShape(ThemeData theme, ChipThemeData chipTheme, ChipThemeData chipDefaults) { final BorderSide? resolvedSide = MaterialStateProperty.resolveAs(widget.side, materialStates) ?? MaterialStateProperty.resolveAs(chipTheme.side, materialStates); final BorderSide? resolvedShapeSide = MaterialStateProperty.resolveAs(widget.shape?.side, materialStates) ?? MaterialStateProperty.resolveAs(chipTheme.shape?.side, materialStates); final OutlinedBorder resolvedShape = MaterialStateProperty.resolveAs(widget.shape, materialStates) ?? MaterialStateProperty.resolveAs( chipTheme.shape, materialStates) ?? MaterialStateProperty.resolveAs(chipDefaults.shape, materialStates) // TODO(tahatesser): Remove this fallback when Material 2 is deprecated. ?? const StadiumBorder(); // If the side is provided, shape uses the provided side. if (resolvedSide != null) { return resolvedShape.copyWith(side: resolvedSide); } if (resolvedShapeSide != null) { return resolvedShape.copyWith(side: resolvedShapeSide); } // If the side is not provided // then the shape's side is used. Otherwise, the default side is used. return resolvedShape.copyWith(side: chipDefaults.side); } ``` (in `chip.dart`) However, (#133856) PR seems to be intended to ignore this and use the aspect of `chipDefault.side` even if the developer specifies `shape.side` as [Border.none] without explicitly applying `side` . This is probably because the default value of OutlinedBorder is [Border.none]. I think this is an area that can cause enough confusion, but there are a lot of things that need to be modified to reduce confusion through code changes, and the impact on existing code is likely to be significant. I also confirmed that this is not accurately explained in the API Docs. So rather than modifying the code, I decided to add additional explanation to the `shape` comment. If the results are different from what you intended or the updated content is strange, please review. 🙏 --- packages/flutter/lib/src/material/chip.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index 6033d766a0..03eb6526da 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -123,7 +123,9 @@ abstract interface class ChipAttributes { /// Otherwise, [StadiumBorder] is used. /// /// This shape is combined with [side] to create a shape decorated with an - /// outline. To omit the outline entirely, pass [BorderSide.none] to [side]. + /// outline. If [side] is not null or side of [shape] is [BorderSide.none], + /// side of [shape] is ignored. To omit the outline entirely, + /// pass [BorderSide.none] to [side]. /// /// If it is a [MaterialStateOutlinedBorder], [MaterialStateProperty.resolve] /// is used for the following [MaterialState]s: