flutter_async 0.6.2 copy "flutter_async: ^0.6.2" to clipboard
flutter_async: ^0.6.2 copied to clipboard

Handle async tasks with ease through automatic loading, error handling, and native widget integration.

example/lib/main.dart

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

void main() => runApp(
      MaterialApp(
        theme: ThemeData(
          useMaterial3: true,
          colorScheme: const ColorScheme.light(
            // surface: Colors.black,
            // onSurface: Colors.black,
            onPrimary: Colors.white,
            primary: Colors.black,
          ),
        ),
        home: const Scaffold(
          body: MyWidget(),
        ),
      ),
    );

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

  static const duration = Duration(seconds: 1);

  Future<int> onPressed() async {
    await Future.delayed(duration);
    throw 'Some really long message error';
    return 5;
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        AsyncBuilder(
          future: onPressed(), // or stream
          loadingBuilder: (context) {
            return const CircularProgressIndicator();
          },
          errorBuilder: (context, error, stackTrace) {
            return Text(error.toString());
          },
          builder: (context, data) {
            return Text('$data');
          },
        ),
        AsyncElevatedButton(
          onPressed: onPressed,
          child: const Text('data'),
        ),
        AsyncTextButton(
          onPressed: onPressed,
          child: const Text('data'),
        ),
        AsyncOutlinedButton(
          onPressed: onPressed,
          child: const Text('data'),
        ),
        AsyncFilledButton(
          onPressed: onPressed,
          child: const Text('data'),
        ),
      ].map((e) => Expanded(child: Center(child: e))).toList(),
    );
  }
}
3
likes
0
pub points
66%
popularity

Publisher

verified publisherbranvier.com

Handle async tasks with ease through automatic loading, error handling, and native widget integration.

Homepage

License

unknown (license)

Dependencies

animated_value, async_notifier, flutter

More

Packages that depend on flutter_async