[0.1.0]
This commit is contained in:
84
lib/src/loading/loading_helper.astromic.dart
Normal file
84
lib/src/loading/loading_helper.astromic.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
//s1 Imports
|
||||
//s2 Core Package Imports
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
//s2 1st-party Package Imports
|
||||
//s2 3rd-party Package Imports
|
||||
import 'package:loader_overlay/loader_overlay.dart';
|
||||
//s2 Dependancies Imports
|
||||
//s3 Routes
|
||||
//s3 Services
|
||||
//s3 Models
|
||||
import 'src/models/models.exports.dart';
|
||||
//s1 Exports
|
||||
|
||||
class AstromicLoadingHelper {
|
||||
static AstromicLoadingOverlayStyle _style = AstromicLoadingOverlayStyle(loadingWidget: (_) => Container());
|
||||
|
||||
/// Initialize the global builder method
|
||||
static Widget initialize({
|
||||
required Widget child,
|
||||
required AstromicLoadingOverlayStyle style,
|
||||
}) {
|
||||
_style = style;
|
||||
return GlobalLoaderOverlay(
|
||||
child: child,
|
||||
disableBackButton: !style.canDismess,
|
||||
closeOnBackButton: style.canDismess,
|
||||
//
|
||||
duration: style.inDuration,
|
||||
reverseDuration: style.outDuration,
|
||||
switchInCurve: style.inCurve,
|
||||
switchOutCurve: style.outCurve,
|
||||
transitionBuilder: (Widget w, Animation<double> a) => style.animationBuilder?.call(w, a),
|
||||
//
|
||||
overlayColor: Colors.transparent,
|
||||
overlayWidgetBuilder: (dynamic progress) => style.loadingWidget(progress),
|
||||
);
|
||||
}
|
||||
|
||||
/// Get the current visiblity state of the loader.
|
||||
static bool isShowing(BuildContext context) => context.loaderOverlay.visible;
|
||||
|
||||
/// Show the loader with an optional progress parameter.
|
||||
static Future<void> start(BuildContext context, {dynamic startProgress}) async {
|
||||
context.loaderOverlay.show(progress: startProgress);
|
||||
return await Future<dynamic>.delayed(_style.inDuration);
|
||||
}
|
||||
|
||||
/// Hide the loader.
|
||||
static Future<void> stop(BuildContext context, {dynamic startProgress}) async {
|
||||
context.loaderOverlay.hide();
|
||||
return await Future<dynamic>.delayed(_style.outDuration);
|
||||
}
|
||||
|
||||
/// Update the progres in the builder.
|
||||
static Future<void> updateProgress(BuildContext context, dynamic progress) async {
|
||||
context.loaderOverlay.progress(progress);
|
||||
return await Future<dynamic>.delayed(Duration(milliseconds: (_style.inDuration.inMilliseconds / 2).floor()));
|
||||
}
|
||||
|
||||
/// Quickly add in a loading segment for an Async function.
|
||||
static Future<T?> load<T>(
|
||||
BuildContext context,
|
||||
Future<T?> Function(Future<void> Function(dynamic p) updateProgress) process, {
|
||||
dynamic startingProgress,
|
||||
Function(dynamic e, StackTrace trace)? onFail,
|
||||
}) async {
|
||||
Completer<T> c = Completer<T>();
|
||||
//
|
||||
await start(context, startProgress: startingProgress);
|
||||
try {
|
||||
T? p = await process((dynamic p) async {
|
||||
return await updateProgress(context, p);
|
||||
});
|
||||
c.complete(p);
|
||||
} catch (e, trace) {
|
||||
c.complete(null);
|
||||
if (onFail != null) onFail(e, trace);
|
||||
} finally {
|
||||
await stop(context);
|
||||
}
|
||||
return c.future;
|
||||
}
|
||||
}
|
||||
1
lib/src/loading/src/models/models.exports.dart
Normal file
1
lib/src/loading/src/models/models.exports.dart
Normal file
@@ -0,0 +1 @@
|
||||
export 'style.model.dart';
|
||||
56
lib/src/loading/src/models/style.model.dart
Normal file
56
lib/src/loading/src/models/style.model.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AstromicLoadingOverlayStyle {
|
||||
final Widget Function(dynamic progress) loadingWidget;
|
||||
//
|
||||
final Color? backgroundColor;
|
||||
final (int sigmaX, int sigmaY)? backgroundBlur;
|
||||
//
|
||||
final bool canDismess;
|
||||
//
|
||||
final Duration inDuration;
|
||||
final Duration outDuration;
|
||||
final Curve inCurve;
|
||||
final Curve outCurve;
|
||||
final Function(Widget child, Animation<double> animation)? animationBuilder;
|
||||
AstromicLoadingOverlayStyle({
|
||||
required this.loadingWidget,
|
||||
this.backgroundColor,
|
||||
this.backgroundBlur,
|
||||
this.canDismess = false,
|
||||
this.inCurve = Curves.easeOut,
|
||||
this.inDuration = const Duration(milliseconds: 250),
|
||||
this.outCurve = Curves.easeIn,
|
||||
this.outDuration = const Duration(milliseconds: 250),
|
||||
this.animationBuilder,
|
||||
});
|
||||
|
||||
AstromicLoadingOverlayStyle copyWith({
|
||||
Widget Function(dynamic progress)? loadingWidget,
|
||||
Color? backgroundColor,
|
||||
(int sigmaX, int sigmaY)? backgroundBlur,
|
||||
bool? canDismess,
|
||||
Duration? inDuration,
|
||||
Duration? outDuration,
|
||||
Curve? inCurve,
|
||||
Curve? outCurve,
|
||||
Function(Widget child, Animation<double> animation)? animationBuilder,
|
||||
}) {
|
||||
return AstromicLoadingOverlayStyle(
|
||||
loadingWidget: loadingWidget ?? this.loadingWidget,
|
||||
backgroundColor: backgroundColor ?? this.backgroundColor,
|
||||
backgroundBlur: backgroundBlur ?? this.backgroundBlur,
|
||||
canDismess: canDismess ?? this.canDismess,
|
||||
inDuration: inDuration ?? this.inDuration,
|
||||
outDuration: outDuration ?? this.outDuration,
|
||||
inCurve: inCurve ?? this.inCurve,
|
||||
outCurve: outCurve ?? this.outCurve,
|
||||
animationBuilder: animationBuilder ?? this.animationBuilder,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AstromicLoadingOverlayStyle(loadingWidget: $loadingWidget, backgroundColor: $backgroundColor, backgroundBlur: $backgroundBlur, canDismess: $canDismess, inDuration: $inDuration, outDuration: $outDuration, inCurve: $inCurve, outCurve: $outCurve, animationBuilder: $animationBuilder)';
|
||||
}
|
||||
}
|
||||
1
lib/src/loading/src/src.exports.dart
Normal file
1
lib/src/loading/src/src.exports.dart
Normal file
@@ -0,0 +1 @@
|
||||
export 'models/models.exports.dart';
|
||||
Reference in New Issue
Block a user