gpt4 book ai didi

apply() 和 copyWith() 之间的 Flutter TextStyle(不是 TextTheme)区别

转载 作者:行者123 更新时间:2023-12-05 01:57:52 24 4
gpt4 key购买 nike

我正在为我的应用创建主题。

我混淆了 TextStyle 的这两种方法(apply、copyWith)。应该用什么?

在 TextTheme 中还有 2 个同名的方法。我理解它们,但在 TextStyle 中无法理解。

这两个在 TextStyle 中的逻辑与在 TextTheme 中不同

谢谢。

最佳答案

在查看文档时,它表明如果您未指定某些参数,apply 会使用默认值。

TextStyle apply({Color? color,Color? backgroundColor,TextDecoration? decoration,Color? decorationColor,TextDecorationStyle? decorationStyle,double decorationThicknessFactor = 1.0,double decorationThicknessDelta = 0.0,String? fontFamily,List? fontFamilyFallback,double fontSizeFactor = 1.0,double fontSizeDelta = 0.0,int fontWeightDelta = 0,FontStyle? fontStyle,double letterSpacingFactor = 1.0,double letterSpacingDelta = 0.0,double wordSpacingFactor = 1.0,double wordSpacingDelta = 0.0,double heightFactor = 1.0,double heightDelta = 0.0,TextBaseline? textBaseline,TextLeadingDistribution? leadingDistribution,Locale? locale,List? shadows,List? fontFeatures})

https://api.flutter.dev/flutter/painting/TextStyle/apply.html

copywith 不使用默认值,而是使用(复制)原始 TextStyle 对象中已经定义的值。

TextStyle copyWith({bool? inherit,Color? color,Color? backgroundColor,String? fontFamily,List? fontFamilyFallback,double? fontSize,FontWeight? fontWeight,FontStyle? fontStyle,double? letterSpacing,double? wordSpacing,TextBaseline? textBaseline,double? height,TextLeadingDistribution? leadingDistribution,Locale? locale,Paint? foreground,Paint? background,List? shadows,List? fontFeatures,TextDecoration? decoration,Color? decorationColor,TextDecorationStyle? decorationStyle,double? decorationThickness,String? debugLabel})

https://api.flutter.dev/flutter/painting/TextStyle/copyWith.html

编辑:它们似乎也有不同的参数,例如 apply 没有 fontSizefontWeight 作为参数。

关于apply() 和 copyWith() 之间的 Flutter TextStyle(不是 TextTheme)区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68824071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com