flutter_async_widgets 1.0.0 copy "flutter_async_widgets: ^1.0.0" to clipboard
flutter_async_widgets: ^1.0.0 copied to clipboard

Flutter async convenience widgets

example/main.dart

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

void main() {
  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'flutter_async_builder example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const ExampleWidget(),
    );
  }
}

class ExampleWidget extends StatelessWidget {
  const ExampleWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AsyncBuilder.single<String>(
      Future.delayed(
          const Duration(seconds: 5), () => 'String from the future'),
      builder: (context, child, data) => Scaffold(
        appBar: AppBar(
          title: const Text('AsyncBuilder'),
          actions: [
            // If data is null the future is still loading
            if (data == null)
              const Padding(
                padding: EdgeInsets.all(16),
                child: AspectRatio(
                  aspectRatio: 1,
                  child: CircularProgressIndicator(),
                ),
              ),
          ],
        ),
        body: Container(
          width: double.infinity,
          padding: const EdgeInsets.all(24),
          child: child,
        ),
      ),
      onData: (context, data) =>
          Center(child: Text(data, textAlign: TextAlign.center)),
    );
  }
}
4
likes
150
points
58
downloads

Publisher

verified publisherdevnico.me

Weekly Downloads

Flutter async convenience widgets

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, riverpod

More

Packages that depend on flutter_async_widgets