我正在尝试为应用程序使用自定义颜色主题。
\n\n这是 main.dart 文件
\n\nimport \'package:flutter/material.dart\';\n\nimport \'pages/HomePage.dart\';\n\nvoid main() => runApp(new MyApp());\n\nclass MyApp extends StatelessWidget {\n // This widget is the root of your application.\n @override\n Widget build(BuildContext context) {\n return new MaterialApp(\n title: \'Flutter Demo\',\n debugShowCheckedModeBanner: false,\n theme: new ThemeData(\n // This is the theme of your application.\n //\n // Try running your application with "flutter run". You\'ll see the\n // application has a blue toolbar. Then, without quitting the app, try\n // changing the primarySwatch below to Colors.green and then invoke\n // "hot reload" (press "r" in the console where you ran "flutter run",\n // or press Run > Flutter Hot Reload in IntelliJ). Notice that the\n // counter didn\'t reset back to zero; the application is not restarted.\n primarySwatch: MaterialColor(0xFF990000, {\n 50: Color(0xFF990001),\n 300: Color(0xFF990002),\n 900: Color(0xFF990003)\n }),\n ),\n home: new HomePage(),\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我收到以下错误:
\n\nflutter: \xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 小部件库捕获异常 \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\ xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\ x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\ x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\ xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\ x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\ x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\ xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nflutter:构建 MyApp(脏)时抛出以下 NoSuchMethodError:\ nflutter:在 null 上调用了“computeLuminance”方法。\nflutter:接收器:null\nflutter:尝试调用:computeLuminance()
\n\n我做错了什么?
\n如果你想让它工作,你应该定义所有的值,当我只定义一两个值时,我也遇到了同样的错误。
从官方文档我们发现
MaterialColor 类 定义单一颜色以及具有十种颜色阴影的色样。
例如:
primarySwatch: MaterialColor(0xFFFFFFFF, {
50: Color(0xFFFFFFFF),
100: Color(0xFFFFFFFF),
200: Color(0xFFFFFFFF),
300: Color(0xFFFFFFFF),
400: Color(0xFFFFFFFF),
500: Color(0xFFFFFFFF),
600: Color(0xFFFFFFFF),
700: Color(0xFFFFFFFF),
800: Color(0xFFFFFFFF),
900: Color(0xFFFFFFFF),
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6938 次 |
| 最近记录: |