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

Declarative async and error handling for Flutter inspired by React Suspense and Error Boundary. Throw futures during build to suspend the surrounding AsyncZone and show its fallback.

example/lib/main.dart

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

Future<String> fetchGreeting() async {
  await Future.delayed(const Duration(seconds: 2));
  return 'Hello, async_zone!';
}

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(body: Center(child: HomePage())),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return const AsyncZone(
      fallback: CircularProgressIndicator(),
      child: _Greeting(),
    );
  }
}

class _Greeting extends StatefulZoneWidget {
  const _Greeting();

  @override
  State<_Greeting> createState() => _GreetingState();
}

class _GreetingState extends State<_Greeting> {
  late final Future<String> _greeting = fetchGreeting();

  @override
  Widget build(BuildContext context) {
    final message = AsyncZone.of(context).use(_greeting);
    return Text(message, style: const TextStyle(fontSize: 20));
  }
}
0
likes
150
points
82
downloads

Documentation

API reference

Publisher

verified publisherkyoheig3.jp

Weekly Downloads

Declarative async and error handling for Flutter inspired by React Suspense and Error Boundary. Throw futures during build to suspend the surrounding AsyncZone and show its fallback.

Repository (GitHub)
View/report issues

Topics

#suspense #async #react #fallback #error-boundary

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on async_zone