问题描述
我正在遵循关于Flutter Bloc模式的Felix Angelov的教程“ https://www.hidigital.io/blog/2020/06/Flutter-login-tutorial-with-Flutter-bloc”。
为什么AuthenticationEvent
的类实例化如下:
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类,它是这样实例化的:
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库编写的。您不能在当前版本中使用该语法。