Why are the objects instantiated differently in these BLOC events?

63 views Asked by At

I am following Felix Angelov's tutorial "https://www.hidigital.io/blog/2020/06/flutter-login-tutorial-with-flutter-bloc" on Flutter Bloc pattern.

Why is the class for AuthenticationEvent instantiated like this:

import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';

abstract class AuthenticationEvent extends Equatable {
  AuthenticationEvent([List props = const []]) : super(props);  <--------- this line
}

class AppStarted extends AuthenticationEvent {
  @override
  String toString() => 'AppStarted';
}

class LoggedIn extends AuthenticationEvent {
  final String token;

  LoggedIn({@required this.token}) : super([token]);

  @override
  String toString() => 'LoggedIn { token: $token }';
}

class LoggedOut extends AuthenticationEvent {
  @override
  String toString() => 'LoggedOut';
}

While for the LoginEvent class it is instantiated like this:

import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';

abstract class LoginEvent extends Equatable {
  const LoginEvent(); <----------------------------------------- this line
}

class LoginButtonPressed extends LoginEvent {
  final String username;
  final String password;

  const LoginButtonPressed({
    @required this.username,
    @required this.password,
  });

  @override
  List<Object> get props => [username, password];

  @override
  String toString() =>
      'LoginButtonPressed { username: $username, password: $password }';
}

What is the difference here?

1

There are 1 answers

2
Derek K On BEST ANSWER

The AuthenticationEvent is written with an older version of the Equatable library. You cannot use that syntax in the current version.