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

패키지 상세v0.0.4

mobx_provider

UI를 스토어(뷰모델)와 쉽게 바인딩할 수 있는 패키지로, 채워진 스택 아키텍처 패턴에서 영감을 받았습니다

30일 다운로드
12
좋아요
14
Pub 점수
40

패키지 설치

flutter pub add mobx_provider

패키지 개요

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

MobX Provider는 Flutter 애플리케이션에서 UI와 상태 관리 스토어(뷰모델) 간의 연결을 단순화하는 가벼운 패키지입니다. Clean Architecture 패턴에 영감을 받아, MobX의 반응형 상태 관리를 Flutter 위젯 트리와 원활하게 통합할 수 있습니다. 이 패키지는 종속성 주입과 상태 접근을 간소화하여 봐일러플레이트를 줄이고 코드 유지보수성을 향상시킵니다. 하위 상태가 변경될 때 효율적인 반응성과 자동 UI 업데이트를 지원합니다.

사용 사례

  • MobX 스토어를 사용한 반응형 UI
  • 대규모 플러터 앱에서의 상태 관리
  • 클린 아키텍처 구현
  • 뷰모델을 위한 종속성 주입
  • 위젯 간에 스토어 액세스를 단순화

주요 기능

  • MobX와의 간편한 통합
  • 상태 변경 시 자동 UI 재구성
  • 최소한의 보일러플레이트
  • 중첩된 스토어 계층 구조를 지원합니다
  • 관심사의 명확한 분리

적합한 대상

  • 상태 관리에 MobX를 사용하는 개발자
  • 클린 아키텍처를 따르는 프로젝트
  • 간단하고 확장 가능한 상태 솔루션을 찾는 팀
  • 복잡한 상태를 필요로 하는 Flutter 앱
  • 반응형 UI 업데이트가 필요한 앱

고려 사항

  • MobX 설정이 필요합니다
  • MobX 기반 상태 관리에 한정
  • 내장된 오류 처리 없음
  • 비-MobX 워크플로우에는 적합하지 않습니다
  • 고급 사용 사례를 위해 추가 설정이 필요할 수 있습니다

원본 README

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

mobx_provider

Additional package for Mobx, it allows you to bind your (viewmodels) mobx stores with UI more easily the package is inspired by filled stacks pattern [view model provider].

Getting Started

NOTE : if you are not familiar with Mobx, take a look on it to see how you can use this package.

what's new in version 0.0.3

  • The packages now depends on the latest versions of [mobx],[flutter_mobx],[provider] see the change log for thier versions
  • Fix MobxStatefulProvider exception on dispose , Thanks to wbemanuel
  • change [Provider.of(context)] to [Context.read()]

Breaking Changes

  • in older versions (before 0.0.2) MobxStatefulProvider now changed to MobxStatefulObserver and MobxStatelessProvider now changed to MobxStatelessObserver with the same functionalities
  • in the new version (0.0.2) the MobxStatefulProvider widget is integration between Mobx and Provider package it contains Provider.of<T>(context) where T extends MobxBase , this widget exposes only the value of the store wihtout observing it
  • MobxWidgetProvider uses also Provider to get the value of the store and observe it in specific widget (see the example to have a better understanding)

1 - create you own store and make it extends MobxBase class and write your own logic

class CounterStore = _CounterStore with _$CounterStore;
abstract class _CounterStore extends MobxBase with Store {

  
  _CounterStore():_counter=0;
  @observable
  int _counter;

  int get counter => _counter;

  @action
  void increment() => _counter++;
  @override
  void dispose() {}
}

NOTE:

  • the class MobxBase contains a dispose function which should be implemented in your store .
  • additionally, it has some helper functions and states which indicates the state of your store whether it's loading ,error ,initial,success.

2- bind your logic with the UI like this

class CounterWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MobxStatefulObserver<CounterStore>(
      store: CounterStore(),
      initFunction:(store){
        //do api calls here
        //store.fetchData();
      }
      builder: (context, store) {
        return Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: store.increment,
          ),
          appBar: AppBar(
            title: Text('mobx provider example'),
          ),
          body: Center(
            child: Column(
              children: <Widget>[
                Text('counter value is ${store.counter}'),
              ],
            ),
          ),
        );
      },
    );
  }
}
  • MobxStatefulObserver is a stateful widget that takes a generic type which extends MobxBase .
  • it contains initFunction that's called in initState if you wanted to run some code when the widget is rendered for the first time
  • it'll call the dispose function when the widget it removed from the widget tree.

If you want to have more optimization when rendring the widget tree

  • you can use MobxStatefulProvider which exposes only the store from the provider package (donsn't observe any state)
  • use MobxWidgetProvider to observe the state of the store and only this widget will be rendered when the store changes
class CounterWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MobxStatefulProviderr<CounterStore>(
      initFunction: (store){
        //do api calls here
        //store.fetchData();
      }
      builder: (context, store) {
        return Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: store.increment,
          ),
          appBar: AppBar(
            title: Text('mobx provider example'),
          ),
          body: Center(
            child: Column(
              children: <Widget>[
               MobxWidgetProvider<CounterStore>(
                  builder:(context,store){
                    //this widget will only be rendered when the value changes
                    return Text('counter value is ${store.counter}');
                  }
               ) 
              ],
            ),
          ),
        );
      },
    );
  }
}

if you have any suggestions or improvments please let me know .

카테고리

의존성

의존성 목록 3 개

소스 저장소

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

아직 데이터가 없습니다.