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

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(const MyApp());
}

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

  @override
  State<MyApp> 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: SizedBox(
          width: double.infinity,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              const SizedBox(height: 160),
              const Text('Example App ;-)\n'),
              ElevatedButton(
                onPressed: asyncTaskCallback((progress) async {
                  await _wait(1);
                  progress.progressLabel = 'Doing more work';
                  await _wait(2);
                  progress.progressLabel = 'And even more.';
                  await _wait(3);
                }),
                child: const Text('Tap me.'),
              ),
              ...?withTask((task) => [
                    const CircularProgressIndicator(),
                    Text(task.progressLabel ?? ''),
                  ]),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
130
pub points
55%
popularity

Publisher

verified publishercodeux.design

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, logging

More

Packages that depend on flutter_async_utils