2022-03-03 14:58:57 +08:00
|
|
|
import 'package:dash_chat/dash_chat.dart';
|
2022-02-28 21:26:44 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-03 14:58:57 +08:00
|
|
|
import 'package:flutter_hbb/pages/chat_page.dart';
|
|
|
|
|
|
|
|
import 'model.dart';
|
|
|
|
import 'native_model.dart';
|
2022-02-28 21:26:44 +08:00
|
|
|
|
|
|
|
class ChatModel with ChangeNotifier {
|
2022-03-03 14:58:57 +08:00
|
|
|
final List<ChatMessage> _messages = [];
|
|
|
|
|
|
|
|
final ChatUser me = ChatUser(
|
|
|
|
name:"me",
|
|
|
|
);
|
|
|
|
|
|
|
|
get messages => _messages;
|
|
|
|
|
|
|
|
receive(String text){
|
|
|
|
if (text.isEmpty) return;
|
|
|
|
// first message show overlay icon
|
|
|
|
if (iconOverlayEntry == null){
|
|
|
|
showChatIconOverlay();
|
|
|
|
}
|
|
|
|
_messages.add(ChatMessage(text: text, user: ChatUser(
|
|
|
|
name:FFI.ffiModel.pi.username,
|
|
|
|
uid: FFI.getId(),
|
|
|
|
)));
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
send(ChatMessage message){
|
|
|
|
_messages.add(message);
|
|
|
|
if(message.text != null && message.text!.isNotEmpty){
|
|
|
|
PlatformFFI.setByName("chat",message.text!);
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-02-28 21:26:44 +08:00
|
|
|
|
2022-03-03 14:58:57 +08:00
|
|
|
release(){
|
|
|
|
hideChatIconOverlay();
|
|
|
|
hideChatWindowOverlay();
|
|
|
|
_messages.clear();
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-02-28 21:26:44 +08:00
|
|
|
}
|