Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

asyncredux-setup

/asyncredux-setup

Inicjalizuje i konfiguruje AsyncRedux w aplikacji Flutter, na przykład przy starcie nowego projektu.

Repozytorium
async_redux ↗
Licencja
MIT
Ostatnia zmiana repozytorium
23.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 23.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Inicjalizuje i konfiguruje AsyncRedux w aplikacji Flutter, na przykład przy starcie nowego projektu.

Oryginalny opis (EN)

Initialize, setup and configure AsyncRedux in a Flutter app. Use it whenever starting a new AsyncRedux project, or when the user requests.

Jak działa

  1. Adding the Dependency
  2. Creating the State Class
  3. Creating the Store
  4. Wrapping with StoreProvider
  5. Required Context Extensions
  6. Required base action
  7. Update CLAUDE.md
Sekcje z nagłówków SKILL.md, w oryginale · 205 linii, 617 słów
Podgląd SKILL.md
---
name: asyncredux-setup
description: Initialize, setup and configure AsyncRedux in a Flutter app. Use it whenever starting a new AsyncRedux project, or when the user requests.
---

# AsyncRedux Setup

## Adding the Dependency

Add AsyncRedux to your `pubspec.yaml`:

```yaml
dependencies:
  async_redux: ^25.6.1
```

Check [pub.dev](https://pub.dev/packages/async_redux) for the latest version.

## Creating the State Class

Create an immutable `AppState` class (in file `app_state.dart`) with:

* `copy()` method
* `==` equals method
* `hashCode` method
* `initialState()` static factory

If the app is new, and you don't have any state yet, create an empty `AppState`:

```dart
@immutable
class AppState {
  AppState();
  static AppState initialState() => AppState();
  AppState copy() => AppState();
  
  @override
  bool operator ==(Object other) =>
    identical(this, other) ||
    other is AppState && runtimeType == other.runtimeType;

  @override
  int get hashCode => 0;
}
```

If there is existing state, create the `AppState` that incorporates that state.
This is an example:

```dart
@immutable
class AppState {
  final String name;
  final int age;
  AppState({required this.name, required this.age});

  static AppState initialState() => AppState(name: "", age: 0);

  AppState copy({String? name, int? age}) => AppState(
    name: name ?? this.name,
    age: age ?? this.age,
  );
  
  @override
  bool operator ==(Object other) =>
    identical(this, other) ||
    other is AppState &&
      runtimeType == other.runtimeType &&
      name == other.name &&
      age == other.age;

  @override
  int get hashCode => Object.hash(name, age);
}

```

All fields must be `final` (immutable). Add additional helper methods as needed:

```dart
AppState withName(String name) => copy(name: name);
AppState withAge(int age) => copy(age: age);
```

## Creating the Store

Find the place where you initialize your app (usually in `main.dart`),
and import your `AppState` class (adapt the path as needed) and the AsyncRedux package:

```dart
import 'app_state.dart'; 
import 'package:async_redux/async_redux.dart';
```

Create the store with your initial state. Note that `PersistorDummy`,
`GlobalErrorObserverDummy`, and `ConsoleActionObserver` are provided by AsyncRedux for basic
setups. In the future these can be replaced with custom implementations as needed.

```dart
late Store store;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Create the persistor, and try to read any previously saved state.
  var persistor = PersistorDummy<AppState>();
  AppState? initialState = await persistor.readState();
  
  // If there is no saved state, create a new empty one and save it.
  if (initialState == null) {
    initialState = AppState.initialState();
    await persistor.saveInitialState(initialState);
  }
    
  // Create the store.
  store = Store<AppState>(
    initialState: initialState,
    persistor: persistor,
    globalErrorObserver: (store) => GlobalErrorObserverDummy(),
    actionObservers: [ConsoleActionObserver()],
  );

  runApp(...);
}
```

## Wrapping with StoreProvider

Wrap your app with `StoreProvider` to make the store accessible.
Find the root of the widget tree of the app, and add it above `MaterialApp` (or
`CupertinoApp`, adapting as needed). Note you will need to import the `store` too.

```dart
import 'package:async_redux/async_redux.dart';

Widget build(context) {
  return StoreProvider<AppState>(
    store: store,
    child: MaterialApp( ... ),
  );
}
```

## Required Context Extensions

You **must** add this extension to your file containing `AppState` (this is required for
easier state access in widgets):

```dart
extension BuildContextExtension on BuildContext {
  AppState get state => getState<AppState>();

  AppState read() => getRead<AppState>();

  R select<R>(R Function(AppState state) selector) =>
      getSelect<AppState, R>(selector);

  R? event<R>(Evt<R> Function(AppState state) selector) =>
      getEvent<AppState, R>(selector);
}
```

## Required base action

Create file `app_action.dart` with this abstract class extending `ReduxAction<AppState>`:

```dart
/// All actions extend this class.
abstract class AppAction extends ReduxAction<AppState> {

ActionSelect get select => ActionSelect(state);
}

// Dedicated selector class to keep the base action clean.
class ActionSelect {
  final AppState state;
  ActionSelect(this.state);
}
```

## Update CLAUDE.md

Add the following information to the project's `CLAUDE.md`, so that all actions extend
this
base action:

```markdown
## Base Action

All actions should extend `AppAction` instead of `ReduxAction<AppState>`. 
There is a dedicated selector class called `ActionSelect` to keep the base action clean,
by namespacing selectors under `select` and enabling IDE autocompletion. Example:

  ```dart
  class ProcessItem extends AppAction {
    final String itemId;
    ProcessItem(this.itemId);
    
    @override
    AppState reduce() {
      // IDE autocomplete shows: select.findById, select.completed, etc.
      final item = select.findById(itemId);
      // ...
    }
  }
  ```

```

Wersje

W bazie nie ma innych skilli o nazwie asyncredux-setup.

Migawka bazy z 13.11.2026 · wersja paczki 69fc27d1d64e (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100asyncredux-abort-dispatch
    Zatrzymuje wysłanie akcji AsyncRedux we Flutter przez abortDispatch(), gdy akcja nie ma być wysłana przy określonych warunkach.
  • 86setup
    Konfiguruje pamięć projektu Aletheia w bieżącym projekcie, gdy użytkownik o to prosi lub brakuje katalogu .aletheia.
  • 100flutter-init-project
    Inicjalizuje lub resetuje projekt Flutter do produkcyjnej bazy: ręczny Riverpod, GoRouter, Material 3, wspólne usługi i widgety, tokeny projektowe oraz moduły w lib/modules/ albo prostszy układ warstw.
  • 100project-create
    Inicjuje nowy projekt od zera: struktura repozytorium, dokumentacja, narzędzia jakości i CI/CD.
  • 90create-project
    Zakłada nowy projekt Dart lub Flutter z szablonów Very Good CLI i instaluje zależności, dobierając szablon do celu.
  • 100dotnet-init
    Interaktywnie inicjalizuje projekt: wykrywa typ projektu, zadaje pytania o architekturę i generuje dopasowany plik CLAUDE.md bez ręcznego kopiowania szablonów, dla nowych i istniejących baz kodu .NET.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.