import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green,
),
debugShowCheckedModeBanner: false,
title: 'Loading Examples',
home: MyHomePage(),
builder: EasyLoading.init(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Loading Examples'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
_showDefaultLoading();
},
child: Text('Default Loading'),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
_showProgressLoading();
},
child: Text('Loading with Progress'),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
_showSuccessMessage();
},
child: Text('Loading with Success Message'),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
_showErrorMessage();
},
child: Text('Loading with Error Message'),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
_showInfoMessage();
},
child: Text('Loading with Information Message'),
),
],
),
),
);
}
// Show default loading with a status message
void _showDefaultLoading() {
EasyLoading.show(status: 'Loading...');
// Simulate a background task
Future.delayed(Duration(seconds: 2), () {
EasyLoading.dismiss();
});
}
// Show loading with progress and a status message
void _showProgressLoading() {
EasyLoading.showProgress(0.5, status: 'Loading...');
// Simulate a background task
Future.delayed(Duration(seconds: 2), () {
EasyLoading.dismiss();
});
}
// Show success message with a checkmark
void _showSuccessMessage() {
EasyLoading.showSuccess('Loaded successfully!');
}
// Show error message with a warning icon
void _showErrorMessage() {
EasyLoading.showError('Failed to load!');
}
// Show information message with an info icon
void _showInfoMessage() {
EasyLoading.showInfo('Information message');
}
}