为什么在这些 BLOC 事件中实例化的对象不同?
Why are the objects instantiated differently in these BLOC events?
我正在关注 Felix Angelov 关于 Flutter Bloc 模式的教程“https://www.hidigital.io/blog/2020/06/flutter-login-tutorial-with-flutter-bloc”。
为什么 AuthenticationEvent
的 class 是这样实例化的:
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';
}
而对于 LoginEvent class,它是这样实例化的:
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 }';
}
这里有什么区别?
AuthenticationEvent 是用旧版本的 Equatable 库编写的。您不能在当前版本中使用该语法。
我正在关注 Felix Angelov 关于 Flutter Bloc 模式的教程“https://www.hidigital.io/blog/2020/06/flutter-login-tutorial-with-flutter-bloc”。
为什么 AuthenticationEvent
的 class 是这样实例化的:
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';
}
而对于 LoginEvent class,它是这样实例化的:
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 }';
}
这里有什么区别?
AuthenticationEvent 是用旧版本的 Equatable 库编写的。您不能在当前版本中使用该语法。