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

패키지 상세v1.0.8

dash

다시 라이브러리는 Bloc의 제공과 정리에 대해 책임지는 서비스 로케이터 패턴을 제공합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
182
좋아요
10
Pub 점수
160

패키지 설치

flutter pub add dash

패키지 개요

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

Dash는 Flutter용 가벼운 서비스 로케이터 패키지로, bloc의 라이프사이클을 관리하여 종속성 주입을 단순화하고 적절한 인스턴스화 및 해제를 보장합니다. 특히 Bloc 패턴을 사용한 상태 관리에 적합하며, 의존성을 등록하고 검색하는 깔끔한 방법을 제공합니다. 이 라이브러리는 모든 주요 플랫폼을 지원하며 기존 Flutter 프로젝트에 원활하게 통합됩니다. 라이프사이클 인식에 중점을 두어 메모리 누수를 방지하고 앱 성능을 향상시킵니다.

사용 사례

  • Flutter 앱에서 Bloc 라이프사이클 관리
  • 의존성 주입 간소화
  • 수동적인 Bloc 생성 및 해제 대체
  • 상태 관리 패턴과의 통합
  • 테스트 설정 간소화
  • 모듈러 앱 아키텍처 활성화

주요 기능

  • 자동 bloc 정리
  • 간단한 등록 및 검색
  • 플랫폼 독립적 설계
  • 내장형 라이프사이클 관리
  • 최소한의 보일러플레이트
  • 중첩된 종속성 지원

적합한 대상

  • Bloc 패턴을 사용하는 Flutter 개발자
  • 구조화된 종속성 관리가 필요한 앱
  • 경량 DI 솔루션을 찾는 팀
  • 클린 상태 관리를 목표로 하는 프로젝트
  • 자동 리소스 정리를 원하는 개발자

고려 사항

  • Bloc 중심 사용 사례에 한정됨
  • 서비스 로케이터 패턴에 대한 이해가 필요합니다
  • 복잡한 DI 요구 사항에 적합하지 않습니다
  • 고급 시나리오를 위해 추가 설정이 필요할 수 있습니다
  • 완전한 DI 프레임워크보다 기능이 적음

원본 README

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

Dash

Logo

Dash is a simple but efficient library that helps provide BloCs without headaches.

IMPORTANT: Dart2 is required to use this package.

Installation

  • Add dash to your pubspec.yaml under the dependencies section:
dependencies:
  dash: ^latest_version
  • Add build_runner and dash_generator to your pubspec.yaml under the dev_dependencies section:
dev_dependencies:
  build_runner: ^2.0.3
  dash_generator: ^latest_version

Usage

1 - Create a provider class that will gather BlocProvider annotation:

IMPORTANT: Do not forget to add: part 'provider.g.dart';.

import 'package:dash/dash.dart';

part 'provider.g.dart';

@BlocProvider.register(MySampleBloc)
@BlocProvider.register(MyOtherBloc)
abstract class Provider {}

2 - Extend BLoCs from Bloc. It will allow you to override dispose method.

IMPORTANT: All blocs must have an instance() function that returns the instance of the bloc as below.

class MySampleBloc extends Bloc {

  @override
  dispose() {
    //close all streams
  }

  static Bloc instance() => MySampleBloc();
  
}

class MyOtherBloc extends Bloc {

  @override
  dispose() {
    //close all streams
  }

  static Bloc instance() => MyOtherBloc();
}

3 - Run build_runner, it will generate the provider.g.dart class that you added as part on your provider class.

On project directory run in terminal:

pub run build_runner build

For flutter:

flutter packages pub run build_runner build

Note: If you encounter a conflict error, please add the --delete-conflicting-outputs argument to your command:

flutter packages pub run build_runner build --delete-conflicting-outputs

4 - Finally you can get your BLoC instance from anywhere, for example:

  @override
  Widget build(BuildContext context) {
    final _bloc = $Provider.of<MyOtherBloc>();

    return Container();
  }

  @override
  void dispose() {
    $Provider.dispose<MyOtherBloc>();
    super.dispose();
  }

Changelog

Please see the Changelog page to know what's recently changed.

카테고리

소스 저장소

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

아직 데이터가 없습니다.