Skip to content

Instantly share code, notes, and snippets.

Last active December 20, 2022 17:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Typed data classes
import 'package:data_classes/data_classes.dart';
import 'package:common/const.dart';
part 'change_log.g.dart';
typedef FieldValueGetter<T> = T Function(dynamic);
enum EntityType {
enum ChangeField<T> {
/// Transaction
categoryLvl2({EntityType.transaction}, TypeConverters.categoryLvl2),
counterpartyName({EntityType.transaction}, TypeConverters.counterpartyName);
// ...
const ChangeField(this.supportedEntities, this.getValue);
final Set<EntityType> supportedEntities;
final FieldValueGetter<T> getValue;
/// {@nodoc}
class _ChangeModel<T> {
late String id;
late ChangeField<T> field;
late String filterField;
late Object filterFieldValue;
TransactionDetailsChanger initiator = TransactionDetailsChanger.cashcoach;
late T? nextValue;
T? prevValue;
/// Document timestamps
late DateTime createdAt;
late DateTime updatedAt;
class TypeConverters {
static String counterpartyName(dynamic v) => v.toString();
static CategoryLvl2 categoryLvl2(v) =>
CategoryLvl2.values.firstWhere((item) => == v.toString());
void checkType(Change change) {
if (change is Change<CategoryLvl2>) print('CategoryLvl2');
else print('unknown');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment