【问题标题】:" the argument type jsobject cannot be assigned to parameter type BuildContext"“参数类型 jsobject 不能分配给参数类型 BuildContext”
【发布时间】:2021-02-24 18:51:28
【问题描述】:

这是发生错误的 main.dart 代码

theme: MyTheme.lightTheme(context: context),

这是我做的功能

static ThemeData lightTheme({BuildContext context}) =>
  ThemeData(
    primarySwatch: Colors.deepPurple,
    primaryColor: Colors.deepPurple,
    textTheme: TextTheme(
      bodyText1: TextStyle(
        color: Colors.deepPurple,
      ),
      bodyText2: TextStyle(
        color: Colors.deepPurple,
      )
    )
  );

【问题讨论】:

  • 你有什么问题?
  • 无论context 是你传递给MyTheme.lightTheme 的不是BuildContext。它到底是什么对我们来说是个谜。

标签: flutter dart


【解决方案1】:

尝试删除 BuildContext context 周围的花括号“{}”。

static ThemeData lightTheme(BuildContext context) =>
  ThemeData(
    primarySwatch: Colors.deepPurple,
    primaryColor: Colors.deepPurple,
    textTheme: TextTheme(
      bodyText1: TextStyle(
        color: Colors.deepPurple,
      ),
      bodyText2: TextStyle(
        color: Colors.deepPurple,
      )
    )
  );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 2020-06-25
    • 1970-01-01
    • 2019-11-17
    • 2021-08-13
    • 2020-12-03
    相关资源
    最近更新 更多