loading_animation_widget 0.0.1-beta.2 loading_animation_widget: ^0.0.1-beta.2 copied to clipboard
flutter loading animation or spiner whatever you wanna call.
import 'package:flutter/material.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
const Color _kAppColor = Color(0xFFFDDE6F);
// #1A1A3F
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
canvasColor: _kAppColor,
snackBarTheme: const SnackBarThemeData(
backgroundColor: Colors.brown,
contentTextStyle: TextStyle(
fontSize: 20,
))),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late PageController _pageController;
int _currentPage = 0;
@override
void initState() {
super.initState();
_pageController = PageController(initialPage: _currentPage);
}
void _onTapNext() {
if (_currentPage + 1 < listOfAnimations.length) {
_pageController.jumpToPage(_currentPage + 1);
setState(() {
_currentPage++;
});
} else {
_pageController.animateToPage(
0,
duration: const Duration(milliseconds: 800),
curve: Curves.ease,
);
setState(() {
_currentPage = 0;
});
}
}
void _onTapPrevious() {
if (_currentPage == 0) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'There is nothing left 🌚',
),
),
);
} else {
_pageController.jumpToPage(_currentPage - 1);
setState(() {
_currentPage--;
});
}
}
@override
Widget build(BuildContext context) {
return PageView(
physics: const NeverScrollableScrollPhysics(),
controller: _pageController,
children: listOfAnimations
.map(
(appBody) => Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SafeArea(
bottom: false,
child: Text(
appBody.title,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.w500,
),
),
),
Expanded(
child: Center(
child: appBody.widget,
),
),
],
),
bottomNavigationBar: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(
Icons.chevron_left_rounded,
),
onPressed: _onTapPrevious,
),
IconButton(
icon: const Icon(
Icons.chevron_right_rounded,
),
onPressed: _onTapNext,
),
],
),
),
),
),
)
.toList(),
);
}
}
class AppBody {
final String title;
final Widget widget;
AppBody(
this.title,
this.widget,
);
}
final listOfAnimations = <AppBody>[
AppBody(
'Initial',
const Text('Initial'),
),
AppBody(
'wavingDots',
LoadingAnimationWidget.wavingDots(
color: Colors.white,
size: 100,
),
),
AppBody(
'inkDrop',
LoadingAnimationWidget.inkDrop(
color: Colors.white,
size: 100,
),
),
AppBody(
'twistingDots',
LoadingAnimationWidget.twistingDots(
leftDotColor: const Color(0xFF1A1A3F),
rightDotColor: const Color(0xFFEA3799),
size: 100,
),
),
AppBody(
'threeRotatingDots',
LoadingAnimationWidget.threeRotatingBalls(
color: Colors.white,
size: 100,
),
),
AppBody(
'staggeredDotWave',
LoadingAnimationWidget.staggeredDotWave(
color: Colors.white,
size: 100,
),
),
AppBody(
'fourRotatingDots',
LoadingAnimationWidget.fourRotatingDots(
color: Colors.white,
size: 100,
),
),
AppBody(
'fallingDot',
LoadingAnimationWidget.fallingDot(
color: Colors.white,
size: 100,
),
),
AppBody(
'prograssiveDots',
LoadingAnimationWidget.prograssiveDots(
color: Colors.white,
size: 100,
),
),
AppBody(
'discreteCircle',
LoadingAnimationWidget.discreteCircle(
color: Colors.white,
size: 100,
),
),
AppBody(
'threeArchedCircle',
LoadingAnimationWidget.threeArchedCircle(
color: Colors.white,
size: 100,
),
),
AppBody(
'bouncingBall',
LoadingAnimationWidget.bouncingBall(
color: Colors.white,
size: 100,
),
),
AppBody(
'flickr',
LoadingAnimationWidget.flickr(
leftDotColor: const Color(0xFF0063DC),
rightDotColor: const Color(0xFFFF0084),
size: 100,
),
),
AppBody(
'hexagonDots',
LoadingAnimationWidget.hexagonDots(
color: Colors.white,
size: 100,
),
),
AppBody(
'beat',
LoadingAnimationWidget.beat(
color: Colors.white,
size: 100,
),
),
AppBody(
'twoRotatingArc',
LoadingAnimationWidget.twoRotatingArc(
color: Colors.white,
size: 100,
),
),
AppBody(
'horizontalDotsRotation',
LoadingAnimationWidget.threeHorizontalDots(
color: Colors.white,
size: 100,
),
),
AppBody(
'newtonCradle',
LoadingAnimationWidget.newtonCradle(
color: Colors.white,
size: 200,
),
),
AppBody(
'stretchedDots',
LoadingAnimationWidget.stretchedDots(
color: Colors.white,
size: 100,
),
),
AppBody(
'halfTringleDot',
LoadingAnimationWidget.halfTringleDot(
color: Colors.white,
size: 100,
),
),
AppBody(
'dotsTriangle',
LoadingAnimationWidget.dotsTriangle(
color: Colors.white,
size: 100,
),
),
];