Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev3.0.0

minimal_mvn

Uma solução mínima de gerenciamento de estado para aplicativos Flutter usando o padrão Model-View-Notifier (MVN)

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
54
Curtidas
44
Pontos Pub
150

Instalar pacote

flutter pub add minimal_mvn

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Minimal MVN é uma solução leve de gerenciamento de estado para Flutter que implementa o padrão Model-View-Notifier (MVN). Oferece uma maneira simples e reativa de gerenciar o estado do aplicativo com pouca quantidade de código repetitivo. Ao separar dados (modelo), interface (visualização) e atualizações de estado (notificador), promove arquitetura limpa e facilidade de testes. O pacote foi projetado para desenvolvedores que buscam uma alternativa direta a soluções mais pesadas de gerenciamento de estado sem sacrificar desempenho ou escalabilidade.

Casos de uso

  • Gerenciamento simples de estado do aplicativo
  • Atualizações de UI reativas
  • Alternativas leves aos provedores
  • lógica de negócio testável
  • Aplicativos Flutter de pequeno a médio porte

Principais recursos

  • Boilerplate mínimo
  • padrão Modelo-Visualização-Notificador
  • Atualizações de estado reativas
  • Integração fácil com código existente
  • Suporta todas as plataformas do Flutter

Indicado para

  • Desenvolvedores que querem simplicidade
  • Projetos que evitam bibliotecas de estado complexas
  • Equipes que priorizam a manutenibilidade
  • Aprenda os fundamentos da gestão de estado
  • Aplicativos com complexidade moderada de estado

Considerações

  • Não é ideal para aplicativos de grande escala
  • Ferramentas de depuração internas limitadas
  • Persistência embutida não disponível
  • Requer configuração manual para recursos avançados
  • Mais adequado para aplicativos com necessidades básicas a intermediárias de estado

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

Minimal Logo

Pub Version License

Minimal MVN

A minimal state management package for Flutter. Part of a minimalistic architecture based on the MVN (Model-View-Notifier) pattern.

This package aims for the simplest possible architecture, making it easier to understand and use, while offering an alternative to the growing complexity found in many other state management solutions, in an attempt to minimize side effects.

Try it

Check out the live example at https://alesalv.github.io/minimal/

Counter

The classical Flutter counter app demonstrates basic state management. The counter on the top is a non disposable notifier, so it keeps memory when re-entering the page. The one on the bottom is a disposable notifier, so it resets when re-entering the page.

Chroma Counter

A more advanced counter widget, which increases the counter, and randomly changes color and shape. The reveal button shows a second widget using the same notifier. Thanks to the autodispose feature, the notifier is disposed only when both the widgets are not visible anymore. The string on top of the choma counter updates every 10 counts, thanks to the select feature, which is used to avoid unnecessary rebuilds.

The complete source code is in the example folder.

Getting Started

Add Minimal to your pubspec.yaml:

dart pub add minimal_mvn
# or
flutter pub add minimal_mvn

and import the package:

import 'package:minimal_mvn/minimal_mvn.dart';

You can now start using Minimal's MVN pattern in your application. The quickest way is to follow the 4 steps below.

Features

  • 🎯 MVN (Model-View-Notifier) pattern
  • 🚀 Lazy initialization of notifiers
  • 🔄 Optional autodispose for notifiers
  • ⚡ State selection for optimized rebuilds
  • 📦 Dependency injection with locator

State Management in 4 Steps

1. Create an immutable UI state
@MappableClass()
class ChromaCounterUIState with ChromaCounterUIStateMappable {
  const ChromaCounterUIState({
    this.backgroundColor = Colors.blue,
    this.count = 0,
  });
  final Color backgroundColor;
  final int count;
}
2. Create a notifier to hold your state
class ChromaCounterNotifier extends MMNotifier<ChromaCounterUIState> {
  ChromaCounterNotifier() : super(const ChromaCounterUIState());

  void nextMetamorph() => notify(
        state.copyWith(
          backgroundColor: _randomColor(),
          count: state.count + 1,
        ),
      );
}
3. Create a manager to access your notifier
final MMManager<ChromaCounterNotifier> chromaCounterManager =
    MMManager(ChromaCounterNotifier.new, autodispose: true);
4 Use the notifier from UI
Access the notifier upon user's actions
FloatingActionButton(
  onPressed: () => chromaCounterManager.notifier.nextMetamorph(),
);
Rebuild the UI when state changes
final notifier = chromaCounterManager.notifier;
return ListenableBuilder(
  listenable: notifier,
  builder: (context, _) => Container(
    color: notifier.state.backgroundColor,
    child: const Text('Count: ${notifier.state.count}'),
  ),
);
(Optimized) Rebuild the UI only when part of the state changes
final notifier = chromaCounterManager.notifier;
return ListenableBuilder(
  listenable: notifier.select((state) => state.backgroundColor),
  builder: (context, _) => Container(
    color: notifier.state.backgroundColor,
  ),
);

Testing

Widget Testing

In tests, you can override the notifier with a mock notifier through the minimal manager:

testWidgets('should update UI when state changes', (tester) async {
  // Use the minimal manager to override the notifier
  chromaCounterManager.override(MockCounterNotifier.new);

  await tester.pumpWidget(const MaterialApp(home: ChromaCounter()));

  // Change state through the mock notifier
  chromaCounterManager.notifier.nextMetamorph();
  await tester.pump();

  final newColor = _getContainerColor(tester);
  // Test the exact color instead of a random one
  expect(newColor, equals(Colors.red));
});

See the example app tests for more testing examples.

Categorias

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.