TextStyle.merge 和 TextStyle.copyWith 有不同的描述,但我似乎得到了相同的结果。 如果 merge 的行为与 copyWith 相同,则无需在 TextStyle 中添加 merge 方法。它们之间有什么区别吗?
class TestView extends StatelessWidget {
@override
Widget build(BuildContext context) {
const baseStyle = TextStyle(color: Colors.blue, fontSize: 16);
final titleStyle = baseStyle.copyWith(
color: Colors.red,
decoration: TextDecoration.lineThrough,
); // copyWith
final noticeStyle = baseStyle.merge(const TextStyle(
color: Colors.grey,
decoration: TextDecoration.lineThrough,
)); // merge
return Column(
children: [
Text('this is title style', style: titleStyle),
Text('this is notice style', style: noticeStyle),
],
);
}
}