Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aligator2236 committed Feb 25, 2020
1 parent 2391fa3 commit fcfdeb1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## [0.4.0]

* ability to skip calling load in `initState` by setting `skipLoad` to `true`

## [0.3.4]

* fixed a bug with calling setState when the widget is not mounted
Expand Down
16 changes: 9 additions & 7 deletions lib/src/loader.dart
Expand Up @@ -6,18 +6,20 @@ typedef LoaderCallback<T> = Future<T> Function();
typedef WidgetValueBuilder<T> = Widget Function(BuildContext context, T value);

class Loader<T> extends StatefulWidget {
final bool autoReload;
final LoaderCallback<T> load;
final WidgetValueBuilder<T> builder;
final Widget loadingWidget;
final Widget Function(String error) errorBuilder;

const Loader(
{Key key,
@required this.load,
this.builder,
this.loadingWidget,
this.errorBuilder})
: super(key: key);
const Loader({
Key key,
@required this.load,
this.autoReload = true,
this.builder,
this.loadingWidget,
this.errorBuilder,
}) : super(key: key);

static LoadingMixin of(BuildContext context) {
return context.findAncestorStateOfType<_LoaderState>();
Expand Down
16 changes: 11 additions & 5 deletions lib/src/loadingMixin.dart
Expand Up @@ -3,22 +3,28 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

mixin LoadingMixin<T extends StatefulWidget> on State<T> {
bool loading;
bool hasError;
bool _loaded;
bool loading = false;
bool hasError = false;
bool _loaded = true;
bool skipLoad = false;
String error;

// put your async initiating logic in load
///
/// put your async initiating logic in load
///
Future<void> load();

// recalls load and rebuilds the widgets
///
/// recalls load and rebuilds the widgets
///
void reload() {
setState(() {
_load();
});
}

void _load() {
if(skipLoad) return;
loading = true;
hasError = false;
_loaded = false;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: loader
description: Run asynchronous code before building your widget. Loader will rebuild your widget after the loading is complete.
version: 0.3.4+1
version: 0.4.0
author: Ali Ghanabri <ali.gh2236@gmail.com>
homepage: https://github.com/ali2236/loader

Expand Down

0 comments on commit fcfdeb1

Please sign in to comment.