Home > other >  extends class in flutter with "<p1,p2>"
extends class in flutter with "<p1,p2>"

Time:02-02

I"m new to flutter and I"m trying to understand the following class extends:

class LoginBloc extends Bloc<LoginEvent, LoginState> {LoginBloc() : super(LoginState());

What does it mean extends Bloc<LoginEvent, LoginState>

?

CodePudding user response:

In flutter, the extends keyword is used to inherit from other classes. In this particular case your LoginBloc class is inheriting from the Bloc class.

The Bloc class takes two dynamic types when it is defined; an Event class and a State class. Flutter/Dart convention is to type everything that you can. The Bloc<LoginEvent, LoginState> is defining that LoginEvent is the blocs Event class and LoginState is the blocs State class.

You will use these two classes to control the state changes in your code. LoginEvents emitted from the front end will trigger functions in the LoginBloc which will then emit different LoginStates which you can listen for on the front end.

  •  Tags:  
  • Related