66 lines
1.7 KiB
Dart
66 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class ProgressBar extends StatelessWidget {
|
|
final double percent;
|
|
final double width;
|
|
final double height;
|
|
final double insetX;
|
|
final double insetY;
|
|
|
|
const ProgressBar({
|
|
super.key,
|
|
required this.percent,
|
|
required this.width,
|
|
required this.height,
|
|
this.insetX = 8,
|
|
this.insetY = 6,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final p = percent.clamp(0.0, 1.0);
|
|
final innerW = (width - insetX * 2).clamp(0.0, double.infinity);
|
|
final innerH = (height - insetY * 2).clamp(0.0, double.infinity);
|
|
final fillW = innerW * p;
|
|
final fillAsset = p >= 1
|
|
? 'assets/images/04ac514f79905c0fd3fd97534829cc34.png'
|
|
: 'assets/images/4ea0244a9d7ad2e9357424465415f8b4.png';
|
|
|
|
return SizedBox(
|
|
width: width,
|
|
height: height,
|
|
child: Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
child: Image.asset(
|
|
'assets/images/18a74842e653d3118c500a2248a2fda7.png',
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
Positioned(
|
|
left: insetX,
|
|
top: insetY,
|
|
width: innerW,
|
|
height: innerH,
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: ClipRect(
|
|
child: SizedBox(
|
|
width: fillW,
|
|
height: innerH,
|
|
child: OverflowBox(
|
|
alignment: Alignment.centerLeft,
|
|
minWidth: innerW,
|
|
maxWidth: innerW,
|
|
child: Image.asset(fillAsset, fit: BoxFit.fill),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|