reload_widget 0.0.2 copy "reload_widget: ^0.0.2" to clipboard
reload_widget: ^0.0.2 copied to clipboard

outdated

A Flutter component that supports tapping Reload when fetching data fails.

example/lib/main.dart

import 'dart:math';

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Reload widget Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(title: 'Reload widget Demo Home Page')
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  const MyHomePage({super.key, required this.title});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ReloadStatus _customStatus = ReloadStatus.none;
  int _data = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.refresh),
        onPressed: () {
          setState(() {
            _customStatus = ReloadStatus.failed;
          });
        }
      ),
      body: ReloadWidget(
        customStatus: _customStatus,
        (BuildContext builderContext) {
          return Center(
            child: Text(
              'Data: $_data',
              style: const TextStyle(
                fontSize: 28,
                fontWeight: FontWeight.w700,
                color: Colors.green
              )
            )
          );
        },
        onReload: () async {
          // To simulate API calls
          final bool result = await Future.delayed(const Duration(seconds: 2)).then(
            (value) => Future.value(Random(DateTime.now().millisecond).nextBool())
          );

          _data = Random().nextInt(999);

          return result ? ReloadStatus.succeeded : ReloadStatus.timeout;
        }
      )
    );
  }
}
4
likes
0
points
29
downloads

Publisher

verified publisherwacow.cc

Weekly Downloads

A Flutter component that supports tapping Reload when fetching data fails.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on reload_widget