【问题标题】:Error: The argument type 'MaterialAccentColor' can't be assigned to the parameter type 'MaterialColor'错误:无法将参数类型“MaterialAccentColor”分配给参数类型“MaterialColor”
【发布时间】:2021-08-22 16:38:20
【问题描述】:

我正在编写一个基本的 Flutter 应用程序,但仅针对某些特定颜色出现此错误。

import 'package:flutter/material.dart' ;
import 'pages/home_page.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
      themeMode : ThemeMode.light,
      theme: ThemeData(
        primarySwatch: Colors.orangeAccent
      ),
    );
  }
}

当我将主要色板颜色分配给 Colors.orangeColors.red 时,它工作正常。但是当我切换到任何强调色(例如Colors.orangeAccent)时,它会返回此错误。

如何使用强调色?

【问题讨论】:

    标签: android ios flutter dart main


    【解决方案1】:

    您不能将Colors.orangeAccent 分配给primarySwatch,因为Colors.orangeAccent 的数据类型与primarySwatch 所期望的不同。

    您可以将Colors.orangeAccent 分配给MaterialAppaccentColor 属性。

    【讨论】:

    • 感谢您的帮助
    猜你喜欢
    • 2021-01-09
    • 2018-12-26
    • 2021-08-21
    • 2021-08-27
    • 2021-07-09
    • 2021-11-03
    • 2022-08-14
    • 2022-12-24
    • 2020-11-20
    相关资源
    最近更新 更多