result_command 1.1.1 copy "result_command: ^1.1.1" to clipboard
result_command: ^1.1.1 copied to clipboard

A command pattern implementation for Dart and Flutter using result_dart package.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:result_command/result_command.dart';
import 'package:result_dart/result_dart.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

int _counter = 0;

final incrementCommand = Command0(() async {
  await Future.delayed(const Duration(seconds: 1));
  _counter++;
  return Success(_counter);
});

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            ValueListenableBuilder(
              valueListenable: incrementCommand,
              builder: (context, state, snapshot) {
                return Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.headlineMedium,
                );
              },
            ),
          ],
        ),
      ),
      floatingActionButton: ValueListenableBuilder<CommandState<int>>(
        valueListenable: incrementCommand,
        builder: (context, state, snapshot) {
          return FloatingActionButton(
            onPressed: incrementCommand.isRunning ? null : () => incrementCommand.execute(),
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          );
        },
      ),
    );
  }
}
22
likes
0
points
500
downloads

Publisher

verified publisherflutterando.com.br

Weekly Downloads

A command pattern implementation for Dart and Flutter using result_dart package.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, result_dart

More

Packages that depend on result_command