Giter VIP home page Giter VIP logo

bloc_login's Introduction

🟦 Bloc Nedir ve Neden Kullanıyorum?

Bloc Nedir?

Bloc (Business Logic Component), Flutter uygulamalarında iş mantığını yönetmek için kullanılan bir state management kütüphanesidir. Bloc, iş mantığını (business logic) kullanıcı arayüzünden (UI) ayırarak kodun daha okunabilir, test edilebilir ve yönetilebilir olmasını sağlar. Bloc, bir "state management" (durum yönetimi) çözümüdür ve Dart programlama dilinde yazılmıştır.

Neden Bloc Kullanıyorum?

Bloc kullanmamın birkaç önemli nedeni var:

  1. 🔄 Ayrılmış İş Mantığı ve UI: Bloc, iş mantığını UI'dan ayırır. Bu, uygulamanın farklı bölümlerinin bağımsız olarak geliştirilebilmesini ve test edilebilmesini sağlar. UI bileşenleri yalnızca görünümle ilgilenirken, Bloc sınıfları veri işleme ve iş mantığı ile ilgilenir.

  2. 🧪 Daha İyi Test Edilebilirlik: İş mantığını ayrı bileşenlerde tutmak, test yazmayı kolaylaştırır. Bloc, iş mantığını belirli senaryolar için test etmeyi kolaylaştıran bir yapıya sahiptir.

  3. 📊 Öngörülebilir Durum Yönetimi: Bloc, uygulamanın durumunu (state) yönetmek için belirli bir yapı sağlar. Bu yapı sayesinde uygulamanın her an hangi durumda olduğu ve bu duruma nasıl ulaşıldığı açıkça görülebilir ve yönetilebilir.

  4. ♻️ Yeniden Kullanılabilir Kod: Bloc kullanarak yazılan iş mantığı kodu, uygulamanın farklı yerlerinde tekrar kullanılabilir. Bu, kodun tekrarını azaltır ve geliştirme sürecini hızlandırır.

Nasıl Kullanıyorum?

Bu projede, kullanıcı adı ve şifre ile giriş işlemlerini yönetmek için Bloc yapısını kullanıyorum. İş mantığını LoginBloc adlı bir sınıfta topladım. Bu sınıf, kullanıcının giriş bilgilerini alır, doğrulama işlemlerini yapar ve sonuçları UI bileşenlerine iletir.

Bloc kullanarak login işlemini yönetmek, kodun daha temiz, düzenli ve sürdürülebilir olmasını sağlıyor. Aşağıda bu yapı ile ilgili basit bir örnek bulabilirsiniz:

import 'package:bloc_login/repository/auth/login/login_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../views/auth/form_submisson_status.dart';
import 'login_event.dart';
import 'login_state.dart';

class LoginBloc extends Bloc<LoginEvent, LoginState> {
  final LoginRepository? authRepo;

  LoginBloc({this.authRepo}) : super(LoginState(username: '', password: '', formStatus: InitialFormStatus())) {
    on<LoginEvent>((event, emit) async {
      await mapEventToState(event, emit);
    });
  }

  Future<void> mapEventToState(LoginEvent event, Emitter<LoginState> emit) async {
    if (event is LoginUsernameChanged) {
      emit(state.copyWith(username: event.username));
    } else if (event is LoginPasswordChanged) {
      emit(state.copyWith(password: event.password));
    } else if (event is LoginSubmitted) {
      emit(state.copyWith(formStatus: FormSubmitting()));

      try {
        await authRepo?.login(state.username, state.password);
        emit(state.copyWith(formStatus: SubmissionSuccess()));
      } catch (e) {
        emit(state.copyWith(formStatus: SubmissionFailed(e.toString())));
      }
    }
  }
}

Bu örnek, Bloc yapısını kullanarak kullanıcı adı ve şifre ile giriş işlemlerini nasıl yönettiğimi gösteriyor.

bloc_login's People

Contributors

nurlumeryem avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.