BLoC Architecture Setup for Flutter App

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
BLoC Architecture Setup for Flutter App
Medium
~2-3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Setting up BLoC Architecture for Flutter Applications

BLoC (Business Logic Component) is the officially recommended state management pattern from the Flutter team. Based on event and state streams: UI sends Event, BLoC processes it and emits State. The flutter_bloc library from Felix Angelov has become standard in large Flutter projects.

How BLoC Works in Practice

// Events
abstract class ProfileEvent {}
class ProfileLoaded extends ProfileEvent {
  final String userId;
  ProfileLoaded(this.userId);
}
class ProfileRefreshed extends ProfileEvent {}

// States
abstract class ProfileState {}
class ProfileInitial extends ProfileState {}
class ProfileLoading extends ProfileState {}
class ProfileSuccess extends ProfileState {
  final UserProfile profile;
  ProfileSuccess(this.profile);
}
class ProfileFailure extends ProfileState {
  final String error;
  ProfileFailure(this.error);
}

// BLoC
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
  final UserRepository _repository;

  ProfileBloc(this._repository) : super(ProfileInitial()) {
    on<ProfileLoaded>(_onLoaded);
    on<ProfileRefreshed>(_onRefreshed);
  }

  Future<void> _onLoaded(ProfileLoaded event, Emitter<ProfileState> emit) async {
    emit(ProfileLoading());
    try {
      final profile = await _repository.getProfile(event.userId);
      emit(ProfileSuccess(profile));
    } catch (e) {
      emit(ProfileFailure(e.toString()));
    }
  }
}

In a widget:

BlocBuilder<ProfileBloc, ProfileState>(
  builder: (context, state) {
    return switch (state) {
      ProfileLoading() => const CircularProgressIndicator(),
      ProfileSuccess(:final profile) => ProfileView(profile: profile),
      ProfileFailure(:final error) => ErrorView(error: error),
      _ => const SizedBox(),
    };
  },
)

BLoC vs Cubit

Cubit is a simplified BLoC without Events. Cubit methods are called directly: profileCubit.load(userId). Suitable for simple screens. BLoC with Events provides an event log and tests better with complex logic involving multiple event sources.

What We Configure

Project structure: lib/features/profile/bloc/, data/, domain/. Connect flutter_bloc, equatable (for proper state comparison). Register BLoCs via MultiBlocProvider at app root or BlocProvider at route level. Configure BlocObserver for global event and error logging.

Testing via bloc_test:

blocTest<ProfileBloc, ProfileState>(
  'emits [Loading, Success] when ProfileLoaded is added',
  build: () => ProfileBloc(mockRepository),
  act: (bloc) => bloc.add(ProfileLoaded('user-123')),
  expect: () => [ProfileLoading(), ProfileSuccess(tProfile)],
);

Timeline

Setting up BLoC architecture from scratch: 2–3 days. Refactoring setState project: 1–2 weeks. Cost — after analysis.