What is BLoC in Flutter?

 

BLoC (Business Logic Component) separates the UI from business logic using Streams.

  • Input: Events (via Sink)

  • Output: States (via Stream)

Example:

class CounterBloc { final _countController = StreamController<int>(); int _count = 0; Stream<int> get countStream => _countController.stream; void increment() { _count++; _countController.sink.add(_count); } void dispose() { _countController.close(); } }

Advantages:

  • Clean architecture

  • Reusable and testable code

Comments

Popular posts from this blog

1. What is Flutter?

What is FutureBuilder and StreamBuilder?