mirror of
https://github.com/friebetill/TubeCards.git
synced 2025-08-14 01:35:57 +08:00
40 lines
1.1 KiB
Dart
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;
|
|
}
|