Files
hash-wallet/lib/entities/list_order_mode.dart
T
cyanandGitHub 64ded5a72b fix: only throw on deserialize if kDebugMode is true (#2976)
This closes #2972, in debug mode we will still catch these issues but if
somehow that happens on production it will fallback to safe default
2026-02-26 14:28:40 +02:00

39 lines
1.1 KiB
Dart

import 'package:cake_wallet/generated/i18n.dart';
import 'package:cw_core/enumerable_item.dart';
import 'package:flutter/foundation.dart';
class ListOrderMode extends EnumerableItem<int> with Serializable<int> {
const ListOrderMode({required String title, required int raw}) : super(title: title, raw: raw);
static const all = [ListOrderMode.ascending, ListOrderMode.descending];
static const ascending = ListOrderMode(raw: 0, title: 'Ascending');
static const descending = ListOrderMode(raw: 1, title: 'Descending');
static ListOrderMode deserialize({required int raw}) {
switch (raw) {
case 0:
return ascending;
case 1:
return descending;
default:
if (kDebugMode) {
throw Exception('Unexpected token: $raw for ListOrderMode deserialize');
}
return descending;
}
}
@override
String toString() {
switch (this) {
case ListOrderMode.ascending:
return S.current.ascending;
case ListOrderMode.descending:
return S.current.descending;
default:
return '';
}
}
}