1

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

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35

2 Answers2

1

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 ...
Yanuar
  • 151
  • 4
1

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...
Nihal Harish
  • 980
  • 5
  • 13
  • 31