Skip to content

Instantly share code, notes, and snippets.

@joshuachinemezu
Created June 4, 2020 12:03
Show Gist options
  • Save joshuachinemezu/5093d5a6577387e1af39f3f2e0167514 to your computer and use it in GitHub Desktop.
Save joshuachinemezu/5093d5a6577387e1af39f3f2e0167514 to your computer and use it in GitHub Desktop.
Flutter Progress Indicator with Text
import 'dart:async';
import 'package:flutter/material.dart';
class CircularLoadingWidget extends StatefulWidget {
final double height;
final String text;
CircularLoadingWidget({Key key, this.height, this.text: ""})
: super(key: key);
@override
_CircularLoadingWidgetState createState() => _CircularLoadingWidgetState();
}
class _CircularLoadingWidgetState extends State<CircularLoadingWidget>
with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController animationController;
void initState() {
super.initState();
animationController =
AnimationController(duration: Duration(milliseconds: 300), vsync: this);
CurvedAnimation curve =
CurvedAnimation(parent: animationController, curve: Curves.easeOut);
animation = Tween<double>(begin: widget.height, end: 0).animate(curve)
..addListener(() {
if (mounted) {
setState(() {});
}
});
Timer(Duration(seconds: 10), () {
if (mounted) {
animationController.forward();
}
});
}
@override
void dispose() {
// Timer(Duration(seconds: 30), () {
// //if (mounted) {
// //}
// });
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Opacity(
opacity: animation.value / 100 > 1.0 ? 1.0 : animation.value / 100,
child: new Center(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(height: 2),
Expanded(
flex: 0,
child: new CircularProgressIndicator(),
),
SizedBox(height: 10),
Text(widget.text)
],
)),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment