flutter - Flutter TextStyle(不是TextTheme)apply()和copyWith()之间的区别
问题描述
我正在为我的应用程序创建主题。
我混淆了TextStyle的这两种方法(apply,copyWith)。应该使用什么?
TextTheme 中还有 2 个同名的方法。我理解他们,但无法理解 TextStyle 中的想法。
TextStyle 中这 2 个的逻辑与 TextTheme 中的不同
谢谢你。
解决方案
查看文档时,它显示apply
如果您未指定某些参数,则使用默认值。
TextStyle apply({Color?color,Color?backgroundColor,TextDecoration?decoration,Color?decorationColor,TextDecorationStyle?decorationStyle,双decorationThicknessFactor = 1.0,双decorationThicknessDelta = 0.0,String?fontFamily,List?fontFamilyFallback,双fontSizeFactor = 1.0,双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?高度、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
没有fontSize
和fontWeight
作为参数。
推荐阅读
- python - 如何将具有单列中所有数据的熊猫数据框转换为多列?
- java - JNA | User32#PostMessage WM_MOUSEMOVE
- regex - 如何使用
- c - fork() 语句中的进程数量,包括程序
- c# - swagger C# codegen maxlength 验证缺失
- excel - 将内部工作表名称重置为升序
- sql - 按序列号排序以防万一 - 可能性
- sql-server - 在已安装 webmin 的 Ubuntu 16.04 上启用 UFW 后无法再连接到 SQL Server 实例
- ruby-on-rails - Ruby/Rails 从一行扩展 if 块 - rubocop
- windows - 如何使用 Windows shell 从其他 Windows 树创建假/虚拟 Windows 树?