• Stars
    star
    100
  • Rank 339,434 (Top 7 %)
  • Language
    Dart
  • License
    ISC License
  • Created almost 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A flutter plugin for loading content asynchronously.

async_loader

A flutter plugin for loading content asynchronously.

Example

Usage

To use this plugin, add async_loader as a dependency in your pubspec.yaml file.

Create instance

getMessage() async {
  return new Future.delayed(TIMEOUT, () => 'Welcome to your async screen');
}

...

var _asyncLoader = new AsyncLoader(
    key: _asyncLoaderState,
    initState: () async => await getMessage(),
    renderLoad: () => new CircularProgressIndicator(),
    renderError: ([error]) =>
        new Text('Sorry, there was an error loading your joke'),
    renderSuccess: ({data}) => new Text(data),
);

Trigger reload

class ExampleApp extends StatelessWidget {
  final GlobalKey<AsyncLoaderState> _asyncLoaderState =
      new GlobalKey<AsyncLoaderState>();

  reload() {
      _asyncLoaderState.currentState.reloadState()
  }
}

Full Example

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:async_loader/async_loader.dart';

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

class ExampleApp extends StatelessWidget {
  final GlobalKey<AsyncLoaderState> _asyncLoaderState =
      new GlobalKey<AsyncLoaderState>();

  @override
  Widget build(BuildContext context) {
    var _asyncLoader = new AsyncLoader(
      key: _asyncLoaderState,
      initState: () async => await getMessage(),
      renderLoad: () => new CircularProgressIndicator(),
      renderError: ([error]) =>
          new Text('Sorry, there was an error loading your joke'),
      renderSuccess: ({data}) => new Text(data),
    );

    return new MaterialApp(
        title: 'Async Loader Demo',
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: new Scaffold(
          appBar: new AppBar(title: buildTitle('Async Loader Demo')),
          body: new Center(child: _asyncLoader),
          floatingActionButton: new FloatingActionButton(
            onPressed: () => _asyncLoaderState.currentState
                .reloadState()
                .whenComplete(() => print('finished reload')),
            tooltip: 'Reload',
            child: new Icon(Icons.refresh),
          ),
        ));
  }
}

const TIMEOUT = const Duration(seconds: 5);

getMessage() async {
  return new Future.delayed(TIMEOUT, () => 'Welcome to your async screen');
}

buildTitle(String title) {
  return new Padding(
    padding: new EdgeInsets.all(10.0),
    child: new Text('Async Loader Demo'),
  );
}

More Repositories

1

hello_scoped_model

A project that demonstrates the use of scoped_model in flutter
Dart
31
star
2

awesome-flutter-provider

😎 A curated list of stuff related to the Flutter Provider library
22
star
3

remote_state

Tools for mapping data from remote sources in Dart, similar to Elm's RemoteData: https://elmprogramming.com/remote-data.html
Dart
14
star
4

hashnode

πŸ“± A minimal, clean client for Hashnode
Dart
12
star
5

good_first_issue

πŸ“± An app for finding good first issues
Dart
11
star
6

mithril-hn

TypeScript
9
star
7

excuses

A Flutter 101 application - let's make excuses to ditch work.
C++
7
star
8

simple_flutter_patterns

A sampling of patterns for dealing with side effects in Flutter
Dart
7
star
9

hello-vue-tsx

An extremely brief example of Vue + tsx
JavaScript
5
star
10

flutter_state_five_ways

Dart
5
star
11

dynamic_env_switching_flutterfire

An example demonstrating dynamic environment switching in Firebase
Dart
2
star
12

redom-hn

TypeScript
2
star
13

polymer-fusebox

TypeScript
1
star
14

chimon2000.github.io

HTML
1
star
15

design-system-ws

TypeScript
1
star
16

tslint-config-lynt-typed

tslint-config-lynt-typed
TypeScript
1
star
17

chimon2000

✨special ✨ secret repository that adds a README.md to your GitHub profile
1
star
18

nest_gql

TypeScript
1
star
19

nativescript-safetynet-helper

TypeScript
1
star
20

cyclejs-hn

TypeScript
1
star
21

dio-hn

1
star
22

awesome-flutter-frameworks

😎 A curated list of opinionated Flutter frameworks
1
star
23

basscss-js

1
star
24

edge_library

Dart
1
star
25

hn_flutter

Dart
1
star
26

hello-world-rc

TypeScript
1
star
27

edge_library_nitric_workshop

Dart
1
star
28

graphql-hn

TypeScript
1
star
29

useref-cli

useref for the command line
JavaScript
1
star
30

ckeditor-ws

TypeScript
1
star
31

releasify

A simple release tool for GitHub
JavaScript
1
star