教程题目:MDC Flutter 教程 3:Material 组件主题、形状、阴影和类型
错误1:
链接:https://codelabs.flutter-io.cn/codelabs/mdc-103-flutter-cn/index.html#3
错误描述:
final ThemeData _kShrineTheme = _buildShrineTheme();
ThemeData _buildShrineTheme() {
final ThemeData base = ThemeData.light();
return base.copyWith(
accentColor: kShrineBrown900,
primaryColor: kShrinePink100,
buttonColor: kShrinePink100,
scaffoldBackgroundColor: kShrineBackgroundWhite,
cardColor: kShrineBackgroundWhite,
textSelectionColor: kShrinePink100,
errorColor: kShrineErrorRed,
// TODO: Add the text themes (103)
// TODO: Add the icon themes (103)
// TODO: Decorate the inputs (103)
);
}
上述代码中,
buttonColor: kShrinePink100,
此种写法不正确,应改为下面的写法:
buttonTheme: base.buttonTheme.copyWith(buttonColor: kShrinePink100),
错误2:
链接:https://codelabs.flutter-io.cn/codelabs/mdc-103-flutter-cn/index.html#4
错误描述:
class AccentColorOverride extends StatelessWidget {
const AccentColorOverride({Key key, this.color, this.child})
: super(key: key);
final Color color;
final Widget child;
@override
Widget build(BuildContext context) {
return Theme(
child: child,
data: Theme.of(context).copyWith(accentColor: color),
);
}
}
上面代码中,
data: Theme.of(context).copyWith(accentColor: color),
应把accentColor改为primaryColor,
data: Theme.of(context).copyWith(primaryColor: color),