flutter_command_pattern 1.0.0 copy "flutter_command_pattern: ^1.0.0" to clipboard
flutter_command_pattern: ^1.0.0 copied to clipboard

A powerful and elegant command pattern implementation for Flutter with pipeline support, observers, and state management.

Flutter Command Pattern #

pub package Build Status codecov License: MIT

A powerful and elegant command pattern implementation for Flutter with pipeline support, observers, and state management.

Features #

Type-safe Commands - Execute async operations with built-in state management
🔄 Pipeline System - Chain middleware for logging, analytics, caching, etc.
👀 Global Observers - Monitor all command executions across your app
🎯 Context-aware - React to loading, success, and failure states
📦 Zero dependencies - Pure Flutter implementation

Installation #

dependencies:
  flutter_command_pattern: ^1.0.0

Quick Start #

Basic Command #

final loginCommand = Command(() async {
  await authService.login(email, password);
});

// Execute
await loginCommand.execute();

// Observe state
loginCommand.observe(
  context,
  onLoading: (ctx) => showLoader(ctx),
  onSuccess: (ctx) => navigateToHome(ctx),
  onFailure: (ctx, error) => showError(ctx, error),
);

Command with Parameters #

final fetchUserCommand = CommandWithParams<String>((userId) async {
  return await api.fetchUser(userId);
});

await fetchUserCommand.execute('user123');

Global Pipeline #

void main() {
  // Add logging pipeline
  CommandPipelineRegistry.addPipeline((context, next) async {
    print('Command started: ${context.command.runtimeType}');
    await next();
    print('Command finished: ${context.state.runtimeType}');
  });

  runApp(MyApp());
}

Global Observer #

CommandObserverRegistry.addObserver((context) {
  if (context.state is CommandFailure) {
    analytics.logError(context.command, context.state);
  }
});

Advanced Usage #

See the example for a complete implementation.

License #

MIT License - see LICENSE file for details.

1
likes
160
points
45
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful and elegant command pattern implementation for Flutter with pipeline support, observers, and state management.

Repository (GitHub)
View/report issues

Topics

#command-pattern #state-management #architecture #pipeline

Documentation

API reference

License

MIT (license)

Dependencies

flutter, meta

More

Packages that depend on flutter_command_pattern