Skip to content

Instantly share code, notes, and snippets.

@Milvintsiss
Last active December 31, 2023 01:42
Show Gist options
  • Save Milvintsiss/30d1f6ae08e660c9757830f77a8dfbd0 to your computer and use it in GitHub Desktop.
Save Milvintsiss/30d1f6ae08e660c9757830f77a8dfbd0 to your computer and use it in GitHub Desktop.
[SO]CircularProgressBar with percentage
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: CircularProgressBar(),
),
),
);
}
}
class CircularProgressBar extends StatefulWidget {
@override
State<CircularProgressBar> createState() => _CircularProgressBarState();
}
class _CircularProgressBarState extends State<CircularProgressBar>
with SingleTickerProviderStateMixin {
late final _animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 5000),
)..repeat();
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _animationController,
builder: (context, child) => Stack(
alignment: Alignment.center,
children: [
SizedBox.square(
dimension: 112,
child: CircularProgressIndicator(
value: _animationController.value,
color: Colors.green,
strokeWidth: 24.0,
),
),
Text(
'${(_animationController.value * 100).toInt()}%',
style: const TextStyle(
fontSize: 28.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment