selfprivacy.org.app/lib/ui/components/progress_bar/progress_bar.dart

59 lines
1.6 KiB
Dart
Raw Normal View History

2020-12-30 14:13:25 +00:00
import 'package:flutter/material.dart';
class ProgressBar extends StatefulWidget {
2022-05-24 18:55:39 +00:00
const ProgressBar({
2021-03-15 15:39:44 +00:00
required this.steps,
required this.activeIndex,
super.key,
2022-06-05 19:36:32 +00:00
});
2020-12-30 14:13:25 +00:00
final int activeIndex;
final List<String> steps;
@override
State<ProgressBar> createState() => _ProgressBarState();
2020-12-30 14:13:25 +00:00
}
class _ProgressBarState extends State<ProgressBar> {
@override
2022-06-05 19:36:32 +00:00
Widget build(final BuildContext context) {
final double progress =
1 / widget.steps.length * (widget.activeIndex + 0.3);
2020-12-30 14:13:25 +00:00
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
2020-12-30 14:13:25 +00:00
borderRadius: BorderRadius.circular(5),
),
child: LayoutBuilder(
2022-06-05 19:36:32 +00:00
builder: (final _, final constraints) => AnimatedContainer(
width: constraints.maxWidth * progress,
height: 5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Theme.of(context).colorScheme.surfaceVariant,
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Theme.of(context).colorScheme.primary,
Theme.of(context).colorScheme.secondary,
],
2020-12-30 14:13:25 +00:00
),
2022-06-05 19:36:32 +00:00
),
duration: const Duration(
milliseconds: 300,
),
),
2020-12-30 14:13:25 +00:00
),
2021-01-06 17:35:57 +00:00
),
2020-12-30 14:13:25 +00:00
],
);
}
}