我是 Flutter 的新手。
这是我的代码,
对于 ElevatedButton,
ElevatedButton(
onPressed: () {
// Add your onPressed code here!
},
child: Text("Login"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
AppColors.SecondaryColor),
foregroundColor: MaterialStateProperty.all<Color>(
AppColors.PrimaryColor))),
Run Code Online (Sandbox Code Playgroud)
对于轮廓按钮,
OutlinedButton(
onPressed: () {
// Add your onPressed code here!
},
child: Text("Register Now"),
style: OutlinedButton.styleFrom(
side: BorderSide(width: 2, color: AppColors.SecondaryColor),
))
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么我必须对OutlinedButton使用styleFrom而不是ButtonStyle?如果用ButtonStyle替换OutlinedButton.styleFrom,则会出错。为什么?
我对ButtonStyle和styleFrom的使用感到非常困惑。因为互联网上的一些示例使用ButtonStyle而一些使用styleFrom。