future_manager 1.3.0 copy "future_manager: ^1.3.0" to clipboard
future_manager: ^1.3.0 copied to clipboard

ValueNotifier and ValueListenableBuilder but for asynchronous value.

example/lib/main.dart

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

import 'home.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return FutureManagerProvider(
      onFutureManagerError: (error, context) {},
      child: MaterialApp(
        title: 'Future Manager Example',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: false
            ? const ExamplePage()
            : MyHomePage(
                dataManager: () => FutureManager(
                  reloading: true,
                  cacheOption: const ManagerCacheOption.non(),
                ),
              ),
      ),
    );
  }
}

class ExamplePage extends StatefulWidget {
  const ExamplePage({Key? key}) : super(key: key);

  @override
  State<ExamplePage> createState() => _ExamplePageState();
}

class _ExamplePageState extends State<ExamplePage> {
  FutureManager<int> dataManager = FutureManager();

  @override
  void initState() {
    dataManager.execute(() async {
      await Future.delayed(const Duration(seconds: 2));
      return 10;
    });
    super.initState();
  }

  @override
  void dispose() {
    dataManager.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("FutureManager Example")),
      body: FutureManagerBuilder<int>(
        futureManager: dataManager,
        ready: (context, data) {
          return Center(
            child: ElevatedButton(
              child: Text("My data: $data"),
              onPressed: () {
                dataManager.refresh();
              },
            ),
          );
        },
      ),
    );
  }
}
10
likes
0
points
678
downloads

Publisher

verified publisherlynical.com

Weekly Downloads

ValueNotifier and ValueListenableBuilder but for asynchronous value.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on future_manager