get_command 1.0.3 copy "get_command: ^1.0.3" to clipboard
get_command: ^1.0.3 copied to clipboard

outdated

Command class to be used within GetControllers. Encapsulate a async function call to simplify UI updates.

example/readme.md

class HomeController extends GetxController {
  final computationResult = 0.obs;
  final GetCommand cmdExecuteComputation = GetCommand();

  int _timesCalled = 41;
  
  HomeController() {
    cmdExecuteComputation.commandFunc = _longRunningComputation;
  }

  @override
  void onClose() {
    cmdExecuteComputation.dispose();
    super.onClose();
  }

  FutureOr<void> _longRunningComputation() async {
    await Future.delayed(Duration(seconds: 1));
    computationResult.value = _timesCalled++;
  }
}
class HomeView extends GetView<HomeController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('HomeView'),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Service Value:'),
            Obx(() {
              return Text(
                '${controller.computationResult}',
                style: TextStyle(fontSize: 20),
              );
            }),
            Obx(() {
              return ElevatedButton(
                onPressed: controller.cmdExecuteComputation.canBeExecuted
                    ? () async => await controller.cmdExecuteComputation()
                    : null,
                child: controller.cmdExecuteComputation.executing
                    ? Row(mainAxisSize: MainAxisSize.min, children: [
                        const Text('Executing'),
                        CircularProgressIndicator(),
                      ])
                    : const Text('Call computation'),
              );
            }),
          ],
        ),
      ),
    );
  }
}

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Command class to be used within GetControllers. Encapsulate a async function call to simplify UI updates.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, get_rx

More

Packages that depend on get_command