async_button_builder 0.0.1-nullsafety.1 copy "async_button_builder: ^0.0.1-nullsafety.1" to clipboard
async_button_builder: ^0.0.1-nullsafety.1 copied to clipboard

outdated

A builder to wrap around buttons that handles loading and disabled state

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Async Buttons')),
      body: SizedBox.expand(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Spacer(),
            Divider(),
            Text('Text Button:'),
            AsyncButtonBuilder(
              child: Text('Click Me'),
              onPressed: () async {
                await Future.delayed(Duration(seconds: 1));
              },
              builder: (context, child, callback) {
                return TextButton(
                  child: child,
                  onPressed: callback,
                );
              },
            ),
            Divider(),
            Text('Elevated Button:'),
            AsyncButtonBuilder(
              child: Text('Click Me'),
              onPressed: () async {
                await Future.delayed(Duration(seconds: 1));
              },
              builder: (context, child, callback) {
                return ElevatedButton(
                  child: child,
                  onPressed: callback,
                );
              },
            ),
            Divider(),
            Text('Custom Outline Button:'),
            AsyncButtonBuilder(
              child: Text('Click Me'),
              loadingWidget: Text('Loading...'),
              onPressed: () async {
                await Future.delayed(Duration(seconds: 1));
              },
              builder: (context, child, callback) {
                return OutlineButton(
                  child: child,
                  onPressed: callback,
                );
              },
            ),
            Divider(),
            Text('Custom Material Button:'),
            const SizedBox(height: 6.0),
            Material(
              color: Colors.lightBlue,
              shape: StadiumBorder(),
              child: AsyncButtonBuilder(
                valueColor: Colors.white,
                padding: const EdgeInsets.symmetric(
                  horizontal: 16.0,
                  vertical: 8.0,
                ),
                loadingPadding: const EdgeInsets.all(8.0),
                child: Text(
                  'Click Me',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () async {
                  await Future.delayed(Duration(seconds: 1));
                },
                builder: (context, child, callback) {
                  return InkWell(
                    child: child,
                    onTap: callback,
                  );
                },
              ),
            ),
            Divider(),
            Spacer(),
          ],
        ),
      ),
    );
  }
}
86
likes
0
pub points
90%
popularity

Publisher

unverified uploader

A builder to wrap around buttons that handles loading and disabled state

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on async_button_builder