anywhere_loader 1.0.6
anywhere_loader: ^1.0.6 copied to clipboard
A lightweight, hassle-free way to show overlay loaders in your Flutter apps.
β‘ AnywhereLoader β Effortless Overlay Loader Without Context or Dependencies #
A lightweight and customizable overlay loader for Flutter. No Stack, no context, no complex state managementβjust one-line integration to show loaders globally.
Features #
- π’ Uses Overlay instead of
Stack
for smooth integration. - π¨ Customizable font size, font color, and font family.
- π Supports async operations.
- π Blur effect on background while loading.
- π Simple API: Just wrap your widget and call
startLoader()
.
Installation #
Add this to your pubspec.yaml:
dependencies:
anywhere_loader: latest_version
Then run:
flutter pub get
Usage #
1οΈβ£ βοΈ Setup #
Wrap your screen (not the whole app) inside AnyWhereLoaderContextProvider. This should be placed inside the MaterialApp:
import 'package:flutter/material.dart';
import 'package:anywhere_loader/anywhere_loader.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Anywhere Loader Demo',
debugShowCheckedModeBanner: false,
home: AnyWhereLoaderContextProvider(
child: HomePage(),
),
);
}
}
2οΈβ£ Start and Stop Loader #
To start the loader anywhere in your app:
AnywhereLoader.instance.startLoader(
text: "Loading data...",
seconds: 5, // Default is 10 seconds
fontSize: 18,
fontColor: Colors.white,
fontFamily: 'Arial',
);
To stop the loader manually:
AnywhereLoader.instance.stopLoader();
3οΈβ£ Using showAsyncLoader() (Recommended for async calls) #
Use this method to automatically show a loader while executing any async function like API calls, database operations, etc.
await AnyWhereLoader.instance.showAsyncLoader(
asyncFunction: () async {
// Simulate a network call or long task
await Future.delayed(const Duration(seconds: 5));
},
text: "Loading, please wait...",
);
β The loader automatically starts and stops. π‘ Ideal for API calls or tasks where you donβt want to manually call startLoader() and stopLoader().
4οΈβ£ Use Custom Loader Widget #
You can replace the default loader with your own widget:
AnywhereLoader.instance.startLoader(
customWidget: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(),
SizedBox(height: 10),
Text("Fetching data...")
],
),
),
);
5οΈβ£ π Customization for iOS (Cupertino Loader) #
You can enable a native iOS-style progress indicator using the isIos: true flag. You can also customize its radius.
ElevatedButton(
onPressed: () {
AnyWhereLoader.instance.startLoader(
blurSigma: 5,
backgroundColor: Colors.black,
opacity: 0.5,
isIos: true, // π Enables CupertinoActivityIndicator
iosProgressRadius: 20, // π Customize the radius of the Cupertino spinner
progressColor: Colors.blue, // π Optional color for the Cupertino spinner
);
Future.delayed(const Duration(seconds: 3), () {
AnyWhereLoader.instance.stopLoader();
});
},
child: const Text("Show Loader"),
);
β CupertinoActivityIndicator gives a native iOS feel ποΈ Use isIos: false (default) to switch back to Material spinner π― Great for iOS-specific UI consistency
License #
This package is released under the MIT License.