Flutter Bloc:Bloc事件:Equatable:类只能扩展其他类

发布于 2025-01-18 04:32:12 字数 470 浏览 1 评论 0原文

在 Flutter 中使用 Bloc。 在 Bloc 活动中,我遇到了一个关于 Equatable 的问题。 首先,我无法导入 equatable 包: import 'package:equatable/equatable.dart';错误说: “part-of 指令必须是部件中的唯一指令。尝试删除其他指令,或将它们移至该部件所属的库”。

后来,当我创建事件并扩展 Equatable 时,错误提示: “类只能扩展其他类。尝试指定不同的超类,或删除扩展子句”。

(仅供参考:我将公平依赖项放入 pubspec.yaml 中)。

我将一如既往地感谢您的帮助!

等价问题

Playing around with Bloc in Flutter.
In the Bloc event, I faced a problem regarding Equatable.
At first, I cannot import equatable package: import 'package:equatable/equatable.dart'; The error says:
"The part-of directive must be the only directive in a part. Try removing other directives, or moving them to the library for which this is a part".

Later on, when I create the Event and extends Equatable, the error says:
"Classes can only extend other classes. Try specifying a different superclass, or removing the extends clause".

(FYI: I put into the pubspec.yaml the equitable dependency).

I will appreciate your assistance, as always!

Equatable problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所谓喜欢 2025-01-25 04:32:12

part-of 指令必须是部件中的唯一指令。尝试删除其他指令,或将它们移至该指令所属的库。

该错误消息意味着您无法从 bloc_event.dart 导入任何包,因为 bloc_event.dartbloc_bloc.dart 的一部分。尝试在bloc_bloc.dart中导入equatable包。并且不要忘记flutter pub get

import 'package:equatable/equatable.dart';

part 'bloc_event.dart';

class BlocBloc ...

The part-of directive must be the only directive in a part. Try removing other directives, or moving them to the library for which this is a part.

That error message means you can't import any package from bloc_event.dart because bloc_event.dart is part of bloc_bloc.dart. Try to import the equatable package in bloc_bloc.dart. And don't forget to flutter pub get.

import 'package:equatable/equatable.dart';

part 'bloc_event.dart';

class BlocBloc ...
淡淡離愁欲言轉身 2025-01-25 04:32:12

它返回错误,因为 bloc_event.dartbloc_bloc.dart 的一部分。

尝试:

  1. bloc_bloc.dart 中导入 equatable 包,
  2. 导入您的状态类,
  3. 删除所有部分导入,
  4. 正常导入它们而不包含该部分。
    导入 'package:equatable/equatable.dart';
    BlocBloc 类...

It's returning an error because bloc_event.dart is part of bloc_bloc.dart.

Try to:

  1. import the equatable package in bloc_bloc.dart
  2. import your state class,
  3. remove all the part imports
  4. import them normally without the part.
    import 'package:equatable/equatable.dart';
    class BlocBloc...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文