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

flutter_triple 표지
패키지 상세v3.0.0

flutter_triple

세그먼트 상태 패턴(SSP)의 구현으로, 별명은 트리플입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
4.7천
좋아요
125
Pub 점수
140

패키지 설치

flutter pub add flutter_triple

패키지 개요

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

Flutter Triple은 분할 상태 패턴(SSP)을 구현한 상태 관리 솔루션으로, 일반적으로 '트리플'이라고 알려져 있습니다. 데이터, 로딩, 오류 상태를 분리함으로써 애플리케이션 상태를 명확하고 예측 가능한 방식으로 관리합니다. 간단함과 확장성을 위해 설계되었으며, Flutter의 반응형 생태계와 원활하게 통합됩니다. 코드 정리와 부가 작업을 줄여주어 전통적인 상태 관리 접근 방식의 가벼우면서도 강력한 대안을 개발자에게 제공합니다. Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원합니다.

사용 사례

  • Flutter 앱에서 복잡한 UI 상태 관리
  • 명확한 로딩 및 오류 상태로 비동기 작업 처리
  • 확장 가능하고 유지보수 가능한 상태 로직 구축
  • 반응형 UI에서 상태 전환 간소화
  • 의존성 주입 프레임워크와의 통합
  • 상태 관리에서 반복 코드 줄이기

주요 기능

  • 상태 유형(초기, 성공, 로딩, 실패)의 명확한 분리
  • 비동기 작업에 대한 내장 지원
  • StreamBuilder 및 ValueListenableBuilder를 통한 반응형 업데이트
  • 최소한의 보일러플레이트와 직관적인 API
  • 조합 가능하고 확장 가능한 상태 패턴
  • 크로스 플랫폼 호환성

적합한 대상

  • 경량 상태 관리 솔루션을 찾는 개발자
  • 프로젝트 간에 일관된 상태 처리를 원하는 팀
  • 자주 비동기 작업을 수행하는 앱
  • 의존성 주입을 사용하는 프로젝트
  • 초보자가 상태 관리 패턴을 배우는 중
  • 유지보수 가능한 상태 로직을 필요로 하는 대규모 애플리케이션

고려 사항

  • 삼중 패턴 개념에 대한 이해가 필요합니다
  • 고급 사용 사례를 위해 추가 설정이 필요할 수 있습니다
  • 완전한 프레임워크에 비해 내장된 디버깅 도구가 제한적
  • 상태의 복잡성이 그 구조를 정당화할 만큼 필요한 앱에 가장 적합
  • 비동기 로직이 필요하지 않은 매우 단순한 상태 요구 사항에는 적합하지 않음
  • 완전한 기능을 위해 외부 라이브러리에 의존합니다

원본 README

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

Triple - Segmented State Pattern


Logo Logo

Welcome to Triple! Design Pattern for State Management.

· Report Bug · Request Feature



Table of Contents
  1. About The Project
  2. Usage
    1. Installation
    2. How to use?
  3. Contributing
  4. Contact
  5. Contributors


:memo: About The Project

What is Triple?

Triple is a nickname to SSP (Segmented State Standard). Some packages were created to make it easier for developers to start using the standard. We'll call it an extension.

Segmented State Pattern (SSP)

When we talk about a single flow state, we end up solving architecture problems early, as we will have only one data flow for each state.

In addition to the maintainability and to the ease of use architecture, we also have the possibility of increasing this flow with other standards such as the Observer, which gives reactivity to the component when it is modified, and Memento, which makes it possible to revert or redo this state.

A beautiful example of a pattern with a single flow is BLoC, giving reactivity to a state allowing all transformations in that flow. This (although complicated for some), consolidates very well in the architecture of a project, even the limits of this practice are beneficial for not allowing the developer to resort to other solutions for the architecture and the standard for its resource.

There are other ways to promote reactivity in a property instead of the entire object, such as MobX's Observable and Flutter's ValueNotifier, and that gives us a lot of choices. However, we lose some important architecture limits, which can put in check the project maintenance in the future. Therefore, it needs a standard to force limits on the individual reactivity of each property and thereby improve the maintainability of the components responsible for managing the states of the application.

Triple is a nickname to SSP (Segmented State Standard). Some packages were created to make it easier for developers to start using the standard. We'll call it an extension.


This project is distributed under the MIT License. See LICENSE.txt for more information.


✨ Usage

The SSP segments the state into 3 reactive parts, the state value (state), the error object (error), and the state loading action (loading).

These segments are observed in a listener or separate listeners. They can also be combined to obtain a new segment, always starting from the 3 main segments.

Installation

Dependencies

add the following dependencies to your pubspec.yaml file:

dependencies:
  flutter_triple: ^1.3.0
Import

Import the package in your code with:

import 'package:flutter_triple/flutter_triple.dart';

How to use?

Create a Store

Create a class that extends NotifierStore<Error, State>. The first type is the type of the error, the second is the type of the state.

class CounterStore extends NotifierStore<Exception, int> {
  CounterStore() : super(0);

  void increment() => update(state + 1);
  void decrement() => update(state - 1);
}
Consume with Listeners, Builders and Consumers

Consume the store with scopes ScopedBuilder, ScopedListener and ScopedConsumer.


class CounterPage extends StatefulWidget {
  @override
  _CounterPageState createState() => _CounterPageState();
}

class _CounterPageState extends State<CounterPage> {
  final store = CounterStore();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Counter'),
      ),
      body: ScopedBuilder<CounterStore, Exception, int>(
        store: store,
        onLoading: (context) => Center(child: CircularProgressIndicator()),
        onError: (context, error) => Center(child: Text(error.toString())),
        onState: (context, state) => Center(
          child: Text(
            '$state',
            style: Theme.of(context).textTheme.headline4,
          ),
        ),
      ),
      floatingActionButton: Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            FloatingActionButton(
              onPressed: store.decrement,
              tooltip: 'Decrement',
              child: Icon(Icons.remove),
            ),
            SizedBox(width: 5),
            FloatingActionButton(
              onPressed: store.increment,
              tooltip: 'Increment',
              child: Icon(Icons.add),
            ),
          ],
        ),
    );
  }
}

🧑‍💻 Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the appropriate tag. Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Remember to include a tag, and to follow Conventional Commits and Semantic Versioning when uploading your commit and/or creating the issue.

(back to top)

💬 Contact

Flutterando Community

(back to top)


👥 Contributors

(back to top)

🛠️ Maintaned by


This fork version is maintained by Flutterando.

카테고리

의존성

의존성 목록 3 개

소스 저장소

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