【问题标题】:How can I fix "The named parameter 'colors' isn't defined" problem in Flutter?如何解决 Flutter 中的“未定义命名参数‘颜色’”问题?
【发布时间】:2021-05-19 17:11:33
【问题描述】:

当我将 const 用于渐变颜色时,出现参数格式错误。

                 Expanded(
                child: OpenContainer(
                  closedElevation: 0,
                  transitionType: ContainerTransitionType.fade,
                  transitionDuration: const Duration(milliseconds: 1000),
                  closedColor: const Color(0xFFE9E9E9),
                  openBuilder: (context, _) {
                    return WorkoutScreen();
                  },
                  closedBuilder: (context, VoidCallback openContainer) {
                    return GestureDetector(
                      onTap: openContainer,
                      child: Container(
                        margin: const EdgeInsets.only(bottom: 10, left: 32, right: 32),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(30)),
                          gradient: LinearGradient(
                            begin: Alignment.topCenter,
                            end: Alignment.bottomCenter,
                            **colors: [
                              const Color(0xFF20008B),
                              const Color(0xFF200087),
                            ],**
                          ),
                        ),

这是一条错误消息:未定义命名参数“颜色”。 尝试将名称更正为现有命名参数的名称,或使用名称“colors”定义命名参数。

【问题讨论】:

  • 除了**,这是否是您的确切代码(即,您复制并粘贴它而没有进行任何其他更改)?您确定错误是指指示的行吗?你用的是什么版本的 Flutter?
  • 是的,“颜色”这个词给了我错误。 [√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.18363.1379], locale tr-TR) [√] Android toolchain - development for Android devices (Android SDK version 30.0.2
  • 我用显示错误的图片编辑了我的问题。你能检查一下吗
  • 是的,这个问题在我写完所有内容后就消失了。非常感谢。 @Vineet

标签: flutter dart constructor


【解决方案1】:

您可以尝试通过在终端窗口中执行 flutter clean 来解决此问题,然后等待 VSCode 重新分析您的文件。

【讨论】:

  • 解决这个问题没有帮助。但是 tnx 给你的评论
猜你喜欢
  • 1970-01-01
  • 2022-07-21
  • 2020-05-19
  • 2018-05-14
  • 2020-12-02
  • 2019-03-22
  • 2019-09-18
  • 2020-07-10
  • 1970-01-01
相关资源
最近更新 更多