screen_loader 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

screen_loader #

Using showDialog for showing loader is a BAD IDEA. You may end up messing the navigation stack due to pushing and popping the loader(dialog). Hence, I have come up with an easy to use mixin ScreenLoader, which will handle the loading on the screen. You can customise the loading as well, check below how it is done.

Installation #

Add dependency in pubspec.yaml:

screen_loader: ^1.1.1

Basic Usage #

Extend your screen(StatefulWidget) with ScreenLoader. Use performFuture to show loader while your future us being performed. That's it!

Basic Example

Override Loader #

Simply overide loader() method in your _ScreenState class

loader() {
    // here any widget would do
    return AlertDialog(
        title: Text('Wait.. Loading data..'),
    );
}

Local Loader Example

Override Loader Gobally #


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ScreenLoaderApp(
      app: MaterialApp(
        title: AppStrings.yapChat,
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Screen(),
      ),
      globalLoader: AlertDialog(
        title: Text('Gobal Loader..'),
      ),
    );
  }
}

Global Loader Example

Priority of loaders #

  • Local loader: the one you override in the _ScreenState class
  • Global loader: the one you specify in ScreenLoaderApp. Note: if you don't override local(), this loader will be used.
  • Default loader: if you don't specify global loader or override local loader, this loader will be used

PS #

PRs are welcome. Please raise issue if you face any on https://github.com/arnold-parge/screen_loader.

[1.1.1]

  • Updated readme

[1.1.0]

Breaking changes #

  • Removed state parameter from screenWrapper function
  • Added performFuture
  • Added BasicScreen in example
  • Added loadingBgBlur in ScreenLoader

[1.0.4]

  • Updated description

[1.0.3]

  • Added example

[1.0.2]

  • Updated description in pubspec.yaml

[1.0.1]

  • Updated description in pubspec.yaml

[1.0.0]

  • Initial release

example/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ScreenLoaderApp(
      app: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Screen Loader',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Screen(),
      ),
      globalLoader: AlertDialog(
        title: Text('Gobal Loader..'),
      ),
      globalLoadingBgBlur: 20.0,
    );
  }
}

class Screen extends StatefulWidget {
  @override
  _ScreenState createState() => _ScreenState();
}

class _ScreenState extends State<Screen> with ScreenLoader<Screen> {
  @override
  loader() {
    return AlertDialog(
      title: Text('Wait.. Loading data..'),
    );
  }

  @override
  loadingBgBlur() => 10.0;

  Widget _buildBody() {
    return Center(
      child: Icon(
        Icons.home,
        size: MediaQuery.of(context).size.width,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ScreenLoader Example'),
      ),
      body: this.screenWrapper(
        child: this._buildBody(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          await this.performFuture(NetworkService.getData);
        },
        child: Icon(Icons.refresh),
      ),
    );
  }
}

class BasicScreen extends StatefulWidget {
  @override
  _BasicScreenState createState() => _BasicScreenState();
}

class _BasicScreenState extends State<BasicScreen>
    with ScreenLoader<BasicScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Basic ScreenLoader Example'),
      ),
      body: this.screenWrapper(
        child: Center(
          child: Icon(
            Icons.home,
            size: MediaQuery.of(context).size.width,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          await this.performFuture(NetworkService.getData);
        },
        child: Icon(Icons.refresh),
      ),
    );
  }
}

class NetworkService {
  static Future getData() async {
    return await Future.delayed(Duration(seconds: 2));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  screen_loader: ^1.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:screen_loader/screen_loader.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
48
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test