Line data Source code
1 : import 'package:flutter/cupertino.dart'; 2 : 3 : /// A "MessageDraft" structure that stores information about in-progress message drafts. 4 : /// MessageDraft stores text, quoted replies, and attached images. 5 : /// Only one draft is stored per conversation. 6 : class MessageDraft extends ChangeNotifier { 7 : QuotedReference? _quotedReference; 8 : int? _inviteHandle; 9 : TextEditingController ctrlCompose = TextEditingController(); 10 : 11 0 : static MessageDraft empty() { 12 0 : return MessageDraft(); 13 : } 14 : 15 0 : bool isEmpty() { 16 0 : return (this._quotedReference == null) || (this.messageText.isEmpty); 17 : } 18 : 19 0 : String get messageText => ctrlCompose.text; 20 : 21 0 : set messageText(String text) { 22 0 : this.ctrlCompose.text = text; 23 0 : notifyListeners(); 24 : } 25 : 26 0 : set quotedReference(int index) { 27 0 : this._quotedReference = QuotedReference(index); 28 0 : notifyListeners(); 29 : } 30 : 31 0 : void attachInvite(int handle) { 32 0 : this._inviteHandle = handle; 33 0 : notifyListeners(); 34 : } 35 : 36 0 : int? getInviteHandle() { 37 0 : return this._inviteHandle; 38 : } 39 : 40 0 : QuotedReference? getQuotedMessage() { 41 0 : return this._quotedReference; 42 : } 43 : 44 0 : void clearQuotedReference() { 45 0 : this._quotedReference = null; 46 0 : notifyListeners(); 47 : } 48 : 49 0 : void clearDraft() { 50 0 : this._quotedReference = null; 51 0 : this.ctrlCompose.clear(); 52 0 : this.ctrlCompose.clearComposing(); 53 0 : this.ctrlCompose.text = ""; 54 0 : this._inviteHandle = null; 55 0 : notifyListeners(); 56 : } 57 : 58 0 : @override 59 : void dispose() { 60 0 : ctrlCompose.dispose(); 61 0 : super.dispose(); 62 : } 63 : 64 0 : void clearInvite() { 65 0 : this._inviteHandle = null; 66 : } 67 : } 68 : 69 : /// A QuotedReference encapsulates the state of replied-to message. 70 : class QuotedReference { 71 : int index; 72 0 : QuotedReference(this.index); 73 : }