【问题标题】:flutter ElevatedButton problems颤振 ElevatedButton 问题
【发布时间】:2021-10-20 03:28:39
【问题描述】:

这是我的代码

ElevatedButton(

            child : Text ("Continue"),
            onPressed: () {
              if (_formKey.currentState.validate()) {
                _formKey.currentState.save();

                KeyboardUtil.hideKeyboard(context);
                Navigator.pushNamed(context, LoginSuccessScreen.routeName);
              }
            },
          ),

ElevatedButton 不是函数。 (文档)尝试更正名称以匹配现有函数,或定义名为“ElevatedButton”的方法或函数。 名称 ElevatedButton 在库 package:fitnessapp/components/elevated_button.dartpackage:flutter/src/material/elevated_button.dart (via package:flutter/material.dart) 中定义。 (文档)尝试对其中一个导入指令使用“作为前缀”,或者对除一个导入之外的所有指令隐藏名称。

“我该如何解决这个问题”?

【问题讨论】:

  • 您似乎有一个名为ElevatedButton 的组件。使用as 关键字,如下所示。 import 'package:fitnessapp/components/elevated_button.dart' as CustomElevatedButton;

标签: flutter dart


【解决方案1】:

在你使用的dart文件中,有2个同名的导入文件,所以不知道用哪个。删除其中一个或命名库:

import 'package:fitnessapp/components/elevated_button.dart' as MyButton;

然后,每当您想使用此文件中的某些内容时,都可以这样称呼它:

MyButton.ElevatedButton();

【讨论】:

    猜你喜欢
    • 2021-11-16
    • 2021-05-05
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2019-05-25
    • 2021-07-28
    • 2020-08-03
    相关资源
    最近更新 更多