2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-27 23:56:22 +00:00
|
|
|
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../../../themes/stack_colors.dart';
|
2024-05-27 23:56:22 +00:00
|
|
|
import 'step_indicator.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
class StepRow extends StatelessWidget {
|
|
|
|
const StepRow({
|
2024-05-27 23:56:22 +00:00
|
|
|
super.key,
|
2022-08-26 08:11:35 +00:00
|
|
|
required this.count,
|
|
|
|
required this.current,
|
|
|
|
required this.width,
|
|
|
|
this.indicatorSize = 16,
|
|
|
|
this.minSpacing = 4,
|
2024-05-27 23:56:22 +00:00
|
|
|
});
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
final int count;
|
|
|
|
final int current;
|
|
|
|
final double width;
|
|
|
|
final double indicatorSize;
|
|
|
|
final double minSpacing;
|
|
|
|
|
2022-09-22 23:48:50 +00:00
|
|
|
Color getColor(int index, BuildContext context) {
|
2022-08-26 08:11:35 +00:00
|
|
|
if (current >= count - 1) {
|
2022-09-22 23:48:50 +00:00
|
|
|
return Theme.of(context).extension<StackColors>()!.accentColorDark;
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current <= index) {
|
2022-09-22 23:48:50 +00:00
|
|
|
return Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.stepIndicatorBGLinesInactive;
|
2022-08-26 08:11:35 +00:00
|
|
|
} else {
|
2022-09-22 23:48:50 +00:00
|
|
|
return Theme.of(context).extension<StackColors>()!.stepIndicatorBGLines;
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StepIndicatorStatus getStatus(int index) {
|
|
|
|
if (current < index) {
|
|
|
|
return StepIndicatorStatus.incomplete;
|
|
|
|
} else if (current > index) {
|
|
|
|
return StepIndicatorStatus.completed;
|
|
|
|
} else {
|
|
|
|
return StepIndicatorStatus.current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 23:48:50 +00:00
|
|
|
List<Widget> _buildList(double spacerWidth, BuildContext context) {
|
2024-05-27 23:56:22 +00:00
|
|
|
final List<Widget> list = [];
|
2022-08-26 08:11:35 +00:00
|
|
|
for (int i = 0; i < count - 1; i++) {
|
2024-05-27 23:56:22 +00:00
|
|
|
list.add(
|
|
|
|
StepIndicator(
|
|
|
|
step: i + 1,
|
|
|
|
status: getStatus(i),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
list.add(
|
|
|
|
_SpacerRow(
|
|
|
|
width: spacerWidth,
|
|
|
|
dotSize: 1.5,
|
|
|
|
spacing: 4,
|
|
|
|
color: getColor(i, context),
|
|
|
|
),
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
2024-05-27 23:56:22 +00:00
|
|
|
list.add(
|
|
|
|
StepIndicator(
|
|
|
|
step: count,
|
|
|
|
status: getStatus(count - 1),
|
|
|
|
),
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final spacerWidth =
|
|
|
|
((width - (indicatorSize * count)) / (count - 1)) - (2 * minSpacing);
|
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2022-09-22 23:48:50 +00:00
|
|
|
..._buildList(spacerWidth, context),
|
2022-08-26 08:11:35 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SpacerRow extends StatelessWidget {
|
|
|
|
const _SpacerRow({
|
2024-05-27 23:56:22 +00:00
|
|
|
super.key,
|
2022-08-26 08:11:35 +00:00
|
|
|
required this.width,
|
|
|
|
required this.dotSize,
|
|
|
|
required this.spacing,
|
|
|
|
required this.color,
|
2024-05-27 23:56:22 +00:00
|
|
|
});
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
final Color color;
|
|
|
|
final double width;
|
|
|
|
final double dotSize;
|
|
|
|
final double spacing;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final count = ((width - dotSize) / (dotSize + spacing)).floor() + 1;
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
for (int i = 0; i < count - 1; i++)
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
_SpacerDot(
|
|
|
|
color: color,
|
|
|
|
size: dotSize,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: spacing,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
_SpacerDot(
|
|
|
|
color: color,
|
|
|
|
size: dotSize,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SpacerDot extends StatelessWidget {
|
|
|
|
const _SpacerDot({
|
2024-05-27 23:56:22 +00:00
|
|
|
super.key,
|
2022-08-26 08:11:35 +00:00
|
|
|
required this.color,
|
|
|
|
this.size = 1.5,
|
2024-05-27 23:56:22 +00:00
|
|
|
});
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
final double size;
|
|
|
|
final Color color;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: color,
|
|
|
|
borderRadius: BorderRadius.circular(size),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|