Files
TubeCards/lib/utils/progress.dart
friebetill 80f218097d Initial commit
Add Space version 2.0.1
2022-03-28 14:56:00 +02:00

40 lines
1.1 KiB
Dart

import 'package:meta/meta.dart';
/// Represents progress of some continuous operation.
///
/// The progress spans from 0% to 100%. An operation is assumed to be finished
/// once the progress
/// hits 100%.
@immutable
class Progress {
/// Constructs a new [Progress] instance from the given parameters.
const Progress(this.value);
/// Actual progress value of the underlying operation.
///
/// The progress value is in the interval [0, 1] and ranges from 0% to 100%.
final double value;
/// Returns whether the underlying operation if done.
bool isDone() => value == 1;
/// Converts the progress to percent and returns the value.
///
/// Percentages are in the range [0, 100].
double toPercent([int fractionDigits = 0]) =>
double.parse((value * 100).toStringAsFixed(fractionDigits));
@override
String toString() => '${toPercent()}%';
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Progress &&
runtimeType == other.runtimeType &&
value == other.value;
@override
int get hashCode => value.hashCode;
}