MessageFieldController constructor
MessageFieldController( - ChatService? _chatService,
- UserService? _userService,
- AbstractSettingsRepository? _settingsRepository, {
- void onSubmit()?,
- void onChanged()?,
- void onCall(
- bool
)?,
- String? text,
- List<ChatItemQuoteInput> quotes = const [],
- List<Attachment> attachments = const [],
- bool onKeyUp(
- LogicalKeyboardKey
)?,
})
Implementation
MessageFieldController(
this._chatService,
this._userService,
this._settingsRepository, {
this.onSubmit,
this.onChanged,
this.onCall,
String? text,
List<ChatItemQuoteInput> quotes = const [],
List<Attachment> attachments = const [],
this.onKeyUp,
}) : quotes = RxList(quotes),
attachments = RxList(
attachments.map((e) => MapEntry(GlobalKey(), e)).toList(),
) {
field = TextFieldState(
text: text,
onFocus: (s) {
onChanged?.call();
},
submitted: false,
onSubmitted: (s) {
field.unsubmit();
onSubmit?.call();
},
focus: FocusNode(onKeyEvent: (_, KeyEvent e) => handleNewLines(e, field)),
);
field.focus.addListener(_focusListener);
_repliesWorker ??= ever(replied, (_) => onChanged?.call());
_attachmentsWorker ??= ever(this.attachments, (_) => onChanged?.call());
_editedWorker ??= ever(edited, (item) {
if (item != null) {
field.text = item.text?.val ?? '';
this.attachments.value = item.attachments
.map((e) => MapEntry(GlobalKey(), e))
.toList();
replied.value = item.repliesTo
.map((e) => e.original)
.nonNulls
.map((e) => Rx(e))
.toList();
} else {
field.text = '';
this.attachments.clear();
replied.clear();
}
onChanged?.call();
});
}