Playing around with Bloc in Flutter. In Bloc event I faced a problem regarding Equatable. At first, I cannot import equetable 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 equatable dependency).
I will appreciate your assistance, as always!
CodePudding user response:
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 ...
CodePudding user response:
It's returning an error because bloc_event.dart
is part of bloc_bloc.dart
.
Try to:
- import the equatable package in
bloc_bloc.dart
- import your state class,
- remove all the part imports
- import them normally without the part.
import 'package:equatable/equatable.dart'; class BlocBloc...