패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.0.6

cubit_base

Bloc/Cubit을 사용하여 데이터 가져오기 및 페이징을 간소화하는 가벼운 Flutter 라이브러리입니다. 표준화된 상태와 반복 코드를 줄이는 Fetcher 유틸리티를 제공합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
49
좋아요
1
Pub 점수
155

패키지 설치

flutter pub add cubit_base

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

cubit_base는 Bloc/Cubit 패턴 내에서 데이터 가져오기 및 페이징을 간소화하기 위해 설계된 가벼운 Flutter 라이브러리입니다. 표준화된 상태 관리와 반복적인 코드를 최소화하는 내장된 Fetcher 유틸리티를 제공하여 로딩, 성공, 오류 상태 처리를 쉽게 만듭니다. 봐일러플레이트를 줄여 개발 속도를 높이며, 플랫폼 간에 명확하고 예측 가능한 상태 전환을 유지합니다.

사용 사례

  • API 데이터 가져오기 간소화
  • 페이지inated 목록 구현
  • 상태 관리 부품 코드 줄이기
  • 재사용 가능한 데이터 공급자 만들기
  • 로딩 및 오류 상태 관리
  • CRUD 작업 간소화

주요 기능

  • 일관된 UI 처리를 위한 표준 상태
  • 비동기 작업을 위한 내장 Fetcher 유틸리티
  • 기본적으로 페이지네이션 지원
  • 최소한의 설정과 명확한 구조
  • 크로스 플랫폼 호환성
  • 관심사의 명확한 분리

적합한 대상

  • Bloc/Cubit 패턴을 사용하는 개발자
  • 자주 데이터를 가져와야 하는 프로젝트
  • 보일러플레이트를 줄이려는 팀
  • 페이지네이션된 콘텐츠를 포함한 앱
  • 초보자가 상태 관리 배우기
  • 빠른 프로토타이핑 및 MVP 개발

고려 사항

  • Bloc/Cubit에 대한 이해가 필요합니다
  • 복잡한 상태 로직에 대한 사용자 정의 제한
  • 매우 동적인 상태 흐름에는 적합하지 않음
  • 간단한 데이터 작업에 가장 적합
  • 고급 캐싱을 위해 추가 레이어가 필요할 수 있습니다
  • 완전한 기능을 위해 외부 종속성에 의존합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

cubit_base

A lightweight Flutter library to simplify data fetching and pagination using Bloc/Cubit. It provides standardized states and a Fetcher utility to reduce boilerplate in your Clean Architecture features.

Features

  • 🚀 Standardized States: BaseState and BasePaginationState for consistent UI handling.
  • 🔄 Simplified Fetching: Fetcher.fetchWithBase handles loading, success, and error states automatically.
  • 📑 Built-in Pagination: Fetcher.fetchWithPaginate manages page increments and "reached max" logic.
  • 🏗️ Clean Architecture Friendly: Designed to work seamlessly with UseCases and DataStates.

Installation

Add cubit_base to your pubspec.yaml:

dependencies:
  cubit_base: ^0.0.5

Usage

1. Simple Data Fetching

Define your state using BaseState:

class UserState {
  final BaseState<User> user;
  
  UserState({required this.user});
  
  UserState copyWith({BaseState<User>? user}) => UserState(user: user ?? this.user);
}

Use the Fetcher in your Cubit:

Future<void> getUser() async {
  await Fetcher.fetchWithBase<User>(
    fetcher: () => _getUserUseCase.call(),
    state: state.user,
    emitter: (newState) => emit(state.copyWith(user: newState)),
  );
}
2. Pagination

Define your state using BasePaginationState:

class ProductState {
  final BasePaginationState<Product> products;

  ProductState({required this.products});

  ProductState copyWith({BasePaginationState<Product>? products}) =>
      ProductState(products: products ?? this.products);
}

Implement pagination in your Cubit:

Future<void> getProducts({bool isRefresh = false}) async {
  await Fetcher.fetchWithPaginate<Product>(
    fetcher: () => _getProductsUseCase.call(
      params: ProductParams(
        page: isRefresh ? 1 : state.products.query.page,
        size: state.products.query.size,
      ),
    ),
    state: state.products,
    isRefresh: isRefresh,
    emitter: (newState) => emit(state.copyWith(products: newState)),
  );
}

State Components

BaseState<T>

Manages a single object of type T.

  • status: initial, loading, success, error.
  • data: The fetched object.
  • error: Error message if any.
BasePaginationState<T>

Manages a list of type T.

  • list: List of items.
  • status: initial, loading, paging, success, error.
  • query: Contains page and size.
  • reachedMax: Boolean indicating if all data is loaded.

License

This project is licensed under the MIT License - see the LICENSE file for details.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.