Getx is much easier and beginners friendly. With Getx you just need to know about some basic concept like GetBuilder, Obx, obs, Update() and some routing functions. And that’s all.
With BLoc you must understand what is stream, sink, Provider and things like that. But these things are hard for beginners to grasp and it takes a lot of coding to do it.
For example for a simple counter function, using Getx you may just need to write less than 10 lines of dart code and you can use it.
Let compare a counter app for getx and bloc
import 'package:get/get.dart';
class Getx_counter extends GetxController{
int _x=0;
int get x=>_x;
void increment(){
_x++;
update();
}
void decrement(){
_x--;
update();
}
}
But with BLoc you need to write at least 30-50 lines of code. and the concept is very abstract.
import 'dart:async';
import 'EventCounter.dart';
// async enable
class Bloc_Counter{
int _counter = 0;
//StreamCountroller handle input and output
final _counterStateController = StreamController<int>();
// Sink in Flutter can be easily stated, In Simple Words Sink = Import
StreamSink<int> get _inCounter =>_counterStateController.sink;
// Stream in Flutter can be easily stated, In Simple Words Stream = Output
Stream<int> get counter =>_counterStateController.stream;
//event controller to trigger which event has occurred
final _counterEventController = StreamController<EventCounter>();
Sink<EventCounter> get counterEventSink =>_counterEventController.sink;
Bloc_Counter(){
_counterEventController.stream.listen((_mapEventtoState));
}
void _mapEventtoState(EventCounter event){
// depending on event either increment or decrement the counter variable
if(event is IncrementEvent)
_counter++;
else
_counter--;
_inCounter.add(_counter);
}
// Dispose the Controller, Very important step, Otherwise you may get memory leak
void dispose(){
_counterStateController.close();
_counterEventController.close();
}
}
But yes, with BLoc you get to see the underlying flutter framework and how it works.