Giter Site home page Giter Site logo

diaglyonok / async_loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chimon2000/async_loader

0.0 1.0 0.0 229 KB

A flutter plugin for loading content asynchronously.

Home Page: https://pub.dartlang.org/packages/async_loader

License: ISC License

Java 6.19% Objective-C 12.58% Dart 76.68% Shell 4.55%

async_loader's Introduction

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'),
  );
}

async_loader's People

Contributors

bcko avatar chimon2000 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.