Files
Vishesh Handa 7fce95c187 Make Note class immutable
This greatly simplifies the entire data flow. Though, it comes at the
risk of introducing bugs, but I think it's worth it.

Plus, it makes everything far far more testable.
2022-01-18 21:42:56 +01:00

34 lines
786 B
Dart

/*
* SPDX-FileCopyrightText: 2019-2021 Vishesh Handa <me@vhanda.in>
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import 'package:flutter_emoji/flutter_emoji.dart';
import 'base.dart';
class EmojiTransformer implements NoteReadTransformer, NoteWriteTransformer {
static final _emojiParser = EmojiParser();
@override
Future<Note> onRead(Note note) async {
var title = note.title;
return note.copyWith(
body: _emojiParser.emojify(note.body),
title: title != null ? _emojiParser.emojify(title) : null,
);
}
@override
Future<Note> onWrite(Note note) async {
var title = note.title;
return note.copyWith(
body: _emojiParser.unemojify(note.body),
title: title != null ? _emojiParser.unemojify(title) : null,
);
}
}