Bar Progress
import 'dart:async';
import 'package:flutter/material.dart';
double percentage = 0;
void initState() {
Timer.periodic(const Duration(milliseconds: 200), (timer) {
percentage += 5;
setState(() {});
if (percentage == 100) timer.cancel();
});
super.initState();
}
SizedBox(
height: 30,
width: double.infinity,
child: LayoutBuilder(builder: (context, constraints) {
return Stack(
children: [
Positioned.fill(
child: Material(
color: Colors.purple.shade100,
shape: const StadiumBorder(),
),
),
Positioned(
left: 0,
height: constraints.maxHeight,
width: (percentage / 100) * constraints.maxWidth,
child: const Material(
color: Colors.purple,
shape: StadiumBorder(),
),
),
Positioned(
right: 10,
top: 0,
bottom: 0,
child: Center(
child: Text(
'${percentage.round()}%',
textAlign: TextAlign.center,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Colors.white,
),
),
),
),
],
);
}),
),