I've been following this NoSQL tutorial which uses BLoC. But when I paste in the code from 'fruit_event.dart' into Visual Studio Code, it gives me an error.
fruit_event.dart:
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
import 'package:sembast_prep/data/fruit.dart';
@immutable
abstract class FruitEvent extends Equatable {
FruitEvent([List props = const []]) : super(props); // error here!
}
class LoadFruits extends FruitEvent {}
class AddRandomFruit extends FruitEvent {}
class UpdateWithRandomFruit extends FruitEvent {
final Fruit updatedFruit;
UpdateWithRandomFruit(this.updatedFruit) : super([updatedFruit]);
}
class DeleteFruit extends FruitEvent {
final Fruit fruit;
DeleteFruit(this.fruit) : super([fruit]);
}
I get this error (Visual Studio Code):
[List<dynamic> props = const []]
Too many positional arguments: 0 expected, but 1 found.
Try removing the extra positional arguments.dart(extra_positional_arguments)
Source code of Equatable class: https://github.com/felangel/equatable/blob/master/lib/src/equatable.dart
It has only one constructor and the constructor accepts no argument/parameter. So you are not allowed to call super(props)
from your constructor.
But, in your code you are passing one argument i.e props
to the constructor of super class i.e Equatable in your case.
Replace this:
FruitEvent([List props = const []]) : super(props);
With this:
FruitEvent([List props = const []]);
And it won't give you any error.
You may want to refer this question to understand usage of super constructor in dart: How do I call a super constructor in Dart?
Edited:
/// The [List] of `props` (properties) which will be used to determine whether
/// two [Equatables] are equal.
@override
List<Object> get props => [parameter1, parameter2, parameter3.....];
Read this comment from the source code:
/// A class that helps implement equality
/// without needing to explicitly override == and [hashCode].
/// Equatables override their own `==` operator and [hashCode] based on their `props`.
const Equatable();
You can refer: https://pub.dev/packages/equatable#-example-tab- to learn about using Equitable class.
I hope this helps, in case of any doubt please comment. If this answer helps you then please accept and up-vote it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With