gpt4 book ai didi

android - 无法在包含 StatefulWidget 的 flutter 文件中添加 mongodart

转载 作者:IT王子 更新时间:2023-10-29 06:51:28 24 4
gpt4 key购买 nike

我当然是第一个问这个问题的人,因为我在互联网上找不到任何关于这个问题的信息。当我尝试在我的 flutter 应用程序的主文件中导入 mongodart 时,我在我的 IDE (VsCode) 中遇到了这个错误,而且当我尝试使用 flutter run 运行项目时>:

The name 'State' is defined in the libraries 'framework.dart' and 'mongo_dart.dart'.

更多:

Compiler message: lib/main.dart:37:32: Error: Expected 0 type arguments. class _MyHomePageState extends State { ^ lib/main.dart:34:20: Error: The return type of the method 'MyHomePage::createState' is

lib1::_MyHomePageState, which does not match the return type of the overridden method (#lib2::State<#lib2::StatefulWidget>). Change to a

subtype of #lib2::State<#lib2::StatefulWidget>. _MyHomePageState createState() => new _MyHomePageState(); ^ file:///home/quentin/flutter/packages/flutter/lib/src/widgets/framework.dart:1: Error: This is the overridden method ('createState'). lib/main.dart:41:5: Error: Method not found: 'setState'. setState(() { ^^^^^^^^ lib/main.dart:41:5: Error: The method 'setState' isn't defined for the class '#lib1::_MyHomePageState'. Try correcting the name to the name of an existing method, or defining a method named 'setState'. setState(() { ^ lib/main.dart:63:25: Error: Getter not found: 'widget'. title: new Text(widget.title), ^^^^^^ lib/main.dart:63:25: Error: The getter 'widget' isn't defined for the class '#lib1::_MyHomePageState'. Try correcting the name to the name of an existing getter, or defining a getter or field named 'widget'. title: new Text(widget.title),

注意:StatefulWidget 是示例应用程序中的那个。

我确定这个问题是由 mongodart 引起的,因为当我删除时:

import 'package:mongo_dart/mongo_dart.dart';

任何形式的错误都会消失。 Here's导致问题的代码。

最佳答案

是的,在 mongo 包中有一个名为“State”的类会导致冲突,您可以为该包使用别名,如下所示。

import 'package:mongo_dart/mongo_dart.dart' as mongo;

如果你想访问任何 mongo_dart 类,只需使用:

mongo.NameOfTheClass 

关于android - 无法在包含 StatefulWidget 的 flutter 文件中添加 mongodart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53135699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com