颤振 | XD 去扑关键问题! Key键,值为null
Flutter | XD to flutter key issue ! Key key, value of null
出于某种原因,当我使用 XD to flutter 插件将我的 Adobe XD 项目导出到 flutter 时
它给出了错误
The parameter 'key' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
这是一个新项目,每次我导出它时,都会报错
这是非常简单的代码,只是屏幕中间的文本小部件
代码:
import 'package:flutter/material.dart';
import 'package:adobe_xd/pinned.dart';
class XDIPhone678SE1 extends StatelessWidget {
XDIPhone678SE1(
{
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xffffffff),
body: Stack(
children: <Widget>[
Pinned.fromPins(
Pin(size: 143.0, middle: 0.5),
Pin(size: 27.0, middle: 0.5),
child: Text(
'Hello World!',
style: TextStyle(
fontFamily: 'Segoe UI',
fontSize: 20,
color: const Color(0xff707070),
),
textAlign: TextAlign.left,
),
),
],
)
}
}
,
);
中 // pubspec.yaml
dependencies:
adobe_xd: ^2.0.0
flutter:
sdk: flutter
你的参数key
在
XDIPhone678SE1({
Key key,
}) : super(key: key);
是不可为 null 的类型 Key
但您没有将其指定为 required
。
这意味着你的 class 可以这样构造:
XDIPhone678SE1();
这应该没问题,因为参数 key
不是必需的,但最终你的 key
是 null
...
您有 2 种修复方法:
- 将您的类型更改为
Key?
这样 key
就可以是 null
- 使
key
成为必需的参数:
XDIPhone678SE1({
required Key key,
}) : super(key: key);
出于某种原因,当我使用 XD to flutter 插件将我的 Adobe XD 项目导出到 flutter 时
它给出了错误
The parameter 'key' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
这是一个新项目,每次我导出它时,都会报错
这是非常简单的代码,只是屏幕中间的文本小部件 代码:
import 'package:flutter/material.dart';
import 'package:adobe_xd/pinned.dart';
class XDIPhone678SE1 extends StatelessWidget {
XDIPhone678SE1(
{
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xffffffff),
body: Stack(
children: <Widget>[
Pinned.fromPins(
Pin(size: 143.0, middle: 0.5),
Pin(size: 27.0, middle: 0.5),
child: Text(
'Hello World!',
style: TextStyle(
fontFamily: 'Segoe UI',
fontSize: 20,
color: const Color(0xff707070),
),
textAlign: TextAlign.left,
),
),
],
)
}
}
,
);
中 // pubspec.yaml
dependencies:
adobe_xd: ^2.0.0
flutter:
sdk: flutter
你的参数key
在
XDIPhone678SE1({
Key key,
}) : super(key: key);
是不可为 null 的类型 Key
但您没有将其指定为 required
。
这意味着你的 class 可以这样构造:
XDIPhone678SE1();
这应该没问题,因为参数 key
不是必需的,但最终你的 key
是 null
...
您有 2 种修复方法:
- 将您的类型更改为
Key?
这样key
就可以是null
- 使
key
成为必需的参数:
XDIPhone678SE1({
required Key key,
}) : super(key: key);