flutter_async_utils 0.1.0 copy "flutter_async_utils: ^0.1.0" to clipboard
flutter_async_utils: ^0.1.0 copied to clipboard

outdated

Utilities for dealing with stream subscriptions and asynchronous tasks in flutter widgets.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_async_utils/flutter_async_utils.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

Future<void> _wait(int seconds) async {
  await Future<void>.delayed(Duration(seconds: seconds));
}

class _MyAppState extends State<MyApp> with FutureTaskStateMixin {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          width: double.infinity,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              const SizedBox(height: 160),
              const Text('Example App ;-)\n'),
              RaisedButton(
                child: const Text('Tap me.'),
                onPressed: asyncTaskCallback((progress) async {
                  await _wait(1);
                  progress.progressLabel = 'Doing more work';
                  await _wait(2);
                  progress.progressLabel = 'And even more.';
                  await _wait(3);
                }),
              ),
              ...?task == null
                  ? null
                  : [
                      const CircularProgressIndicator(),
                      Text(task.progressLabel ?? ''),
                    ],
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
40
pub points
53%
popularity

Publisher

verified publishercodeux.design

Utilities for dealing with stream subscriptions and asynchronous tasks in flutter widgets.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, logging

More

Packages that depend on flutter_async_utils