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

134 lines
3.5 KiB
Dart
Raw Normal View History

2020-12-30 14:13:25 +00:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/brand_colors.dart';
import 'package:selfprivacy/config/text_themes.dart';
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart';
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
class ProgressBar extends StatefulWidget {
ProgressBar({
Key key,
@required this.steps,
@required this.activeIndex,
}) : super(key: key);
final int activeIndex;
final List<String> steps;
@override
_ProgressBarState createState() => _ProgressBarState();
}
class _ProgressBarState extends State<ProgressBar> {
@override
Widget build(BuildContext context) {
double progress = 1 / widget.steps.length * (widget.activeIndex + 0.3);
2021-01-06 17:35:57 +00:00
var isDark = context.watch<AppSettingsCubit>().state.isDarkModeOn;
var style = isDark ? progressTextStyleDark : progressTextStyleLight;
var allSteps = widget.steps.asMap().map(
(i, step) {
var value = _stepTitle(index: i, style: style, step: step);
return MapEntry(i, value);
},
).values;
List<Widget> odd = [];
List<Widget> even = [];
var i = 0;
for (var step in allSteps) {
if (i.isEven) {
even.add(step);
} else {
odd.add(step);
}
2021-02-03 19:51:07 +00:00
i++;
2021-01-06 17:35:57 +00:00
}
2021-02-17 16:20:09 +00:00
2021-02-03 19:51:07 +00:00
odd
..insert(
0,
SizedBox(
2021-02-17 16:20:09 +00:00
width: 20,
2021-02-03 19:51:07 +00:00
),
)
..add(
SizedBox(
2021-02-16 18:48:15 +00:00
width: 10,
2021-02-03 19:51:07 +00:00
),
);
2020-12-30 14:13:25 +00:00
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2021-01-06 17:35:57 +00:00
BrandText.h2('Progress'),
2020-12-30 14:13:25 +00:00
SizedBox(height: 10),
2021-01-06 17:35:57 +00:00
Row(children: even),
2021-02-17 16:20:09 +00:00
SizedBox(height: 7),
2020-12-30 14:13:25 +00:00
Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: BrandColors.gray4,
borderRadius: BorderRadius.circular(5),
),
child: LayoutBuilder(
builder: (_, constraints) {
return AnimatedContainer(
width: constraints.maxWidth * progress,
height: 5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: BrandColors.stableGradientColors,
),
),
duration: Duration(
milliseconds: 300,
),
);
},
),
2021-01-06 17:35:57 +00:00
),
2021-02-17 16:20:09 +00:00
SizedBox(height: 5),
2021-01-06 17:35:57 +00:00
Row(
children: odd,
),
2020-12-30 14:13:25 +00:00
],
);
}
2021-01-06 17:35:57 +00:00
Expanded _stepTitle({
int index,
TextStyle style,
String step,
}) {
var isActive = index == widget.activeIndex;
var checked = index < widget.activeIndex;
style = isActive ? style.copyWith(fontWeight: FontWeight.w700) : style;
return Expanded(
flex: 2,
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: progressTextStyleLight,
children: [
checked
? WidgetSpan(
child: Padding(
2021-02-17 16:20:09 +00:00
padding: const EdgeInsets.only(bottom: 0, right: 2),
child: Icon(BrandIcons.check, size: 11),
2021-01-06 17:35:57 +00:00
))
: TextSpan(text: '${index + 1}.', style: style),
TextSpan(text: step, style: style)
],
),
),
);
}
2020-12-30 14:13:25 +00:00
}