future_button 0.1.2
future_button: ^0.1.2 copied to clipboard

Flutter Android iOS Linux macOS web Windows

Customizable Material and Cupertino buttons with progress bars. Useful if you want to show a loading indicator when user presses some action, and show the result afterwards.

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:future_button/future_button.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Future Button'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  MyHomePage({
    Key key,
    this.title,
  }) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<void> waitFor([int seconds = 2]) {
    return Future.delayed(Duration(seconds: seconds));
  }

  Future<void> waitForAndFail([int seconds = 2]) async {
    await Future.delayed(Duration(seconds: seconds));
    throw Exception();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FutureRaisedButton(
              child: Text('Load'),
              onPressed: waitFor,
              showResult: true,
            ),
            FutureRaisedButton(
              child: Text('Load (right)'),
              onPressed: waitForAndFail,
              progressIndicatorLocation: ProgressIndicatorLocation.right,
              showResult: true,
            ),
            FutureRaisedButton.icon(
              icon: Icon(Icons.star),
              label: Text('Star'),
              onPressed: waitFor,
              showResult: false,
            ),
            FutureIconButton(
              icon: Icon(Icons.link),
              onPressed: waitFor,
              showResult: true,
            ),
            FutureCupertinoButton(
              child: Text('Like'),
              onPressed: waitFor,
              showResult: true,
            ),
            FutureCupertinoButton.filled(
              child: Text('Like'),
              onPressed: waitForAndFail,
              showResult: true,
            ),
          ],
        ),
      ),
    );
  }
}
23
likes
100
pub points
69%
popularity

Customizable Material and Cupertino buttons with progress bars. Useful if you want to show a loading indicator when user presses some action, and show the result afterwards.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

kk.erzhan@gmail.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on future_button