mirror of
https://github.com/Linloir/Simple-TCP-Client.git
synced 2025-12-17 00:38:11 +08:00
Improvement:
- Precache image widget
This commit is contained in:
parent
72a898a8b0
commit
4366a49466
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-13 14:03:16
|
||||
* @LastEditTime : 2022-10-20 00:48:43
|
||||
* @LastEditTime : 2022-10-20 10:52:30
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -87,7 +87,6 @@ class ChatPage extends StatelessWidget {
|
||||
else {
|
||||
//Return history tile
|
||||
return Padding(
|
||||
key: ValueKey(state.chatHistory[index].message.contentmd5),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 8
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-13 14:03:56
|
||||
* @LastEditTime : 2022-10-20 00:13:18
|
||||
* @LastEditTime : 2022-10-20 11:04:40
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -11,6 +11,7 @@ import 'dart:convert';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:open_file/open_file.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tcp_client/chat/cubit/chat_state.dart';
|
||||
@ -78,7 +79,8 @@ class ChatCubit extends Cubit<ChatState> {
|
||||
var newHistory = ChatHistory(
|
||||
message: msg,
|
||||
type: ChatHistoryType.outcome,
|
||||
status: ChatHistoryStatus.sending
|
||||
status: ChatHistoryStatus.sending,
|
||||
preCachedImage: msg.type == MessageType.image ? Image.memory(base64.decode(msg.contentDecoded)) : null
|
||||
);
|
||||
if(msg.type == MessageType.file) {
|
||||
//Remove mock history
|
||||
@ -112,7 +114,8 @@ class ChatCubit extends Cubit<ChatState> {
|
||||
var history = ChatHistory(
|
||||
message: message,
|
||||
type: message.senderID == userID ? ChatHistoryType.income : ChatHistoryType.outcome,
|
||||
status: ChatHistoryStatus.done
|
||||
status: ChatHistoryStatus.done,
|
||||
preCachedImage: message.type == MessageType.image ? Image.memory(base64.decode(message.contentDecoded)) : null
|
||||
);
|
||||
newHistories.add(history);
|
||||
}
|
||||
@ -208,7 +211,8 @@ class ChatCubit extends Cubit<ChatState> {
|
||||
var newHistory = ChatHistory(
|
||||
message: response.message,
|
||||
type: response.message.senderID == userID ? ChatHistoryType.income : ChatHistoryType.outcome,
|
||||
status: ChatHistoryStatus.done
|
||||
status: ChatHistoryStatus.done,
|
||||
preCachedImage: response.message.type == MessageType.image ? Image.memory(base64.decode(response.message.contentDecoded)) : null
|
||||
);
|
||||
var newHistoryList = [newHistory, ...state.chatHistory];
|
||||
emit(state.copyWith(chatHistory: newHistoryList));
|
||||
@ -223,7 +227,8 @@ class ChatCubit extends Cubit<ChatState> {
|
||||
var newHistory = ChatHistory(
|
||||
message: message,
|
||||
type: message.senderID == userID ? ChatHistoryType.income : ChatHistoryType.outcome,
|
||||
status: ChatHistoryStatus.done
|
||||
status: ChatHistoryStatus.done,
|
||||
preCachedImage: message.type == MessageType.image ? Image.memory(base64.decode(message.contentDecoded)) : null
|
||||
);
|
||||
fetchedHistories.insert(0, newHistory);
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-14 14:55:20
|
||||
* @LastEditTime : 2022-10-18 15:19:46
|
||||
* @LastEditTime : 2022-10-20 11:01:03
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tcp_client/repositories/common_models/message.dart';
|
||||
|
||||
enum ChatHistoryType { outcome, income }
|
||||
@ -15,22 +16,26 @@ class ChatHistory extends Equatable {
|
||||
final Message message;
|
||||
final ChatHistoryType type;
|
||||
final ChatHistoryStatus status;
|
||||
final Image? preCachedImage;
|
||||
|
||||
const ChatHistory({
|
||||
required this.message,
|
||||
required this.type,
|
||||
required this.status
|
||||
required this.status,
|
||||
this.preCachedImage,
|
||||
});
|
||||
|
||||
ChatHistory copyWith({
|
||||
Message? message,
|
||||
ChatHistoryType? type,
|
||||
ChatHistoryStatus? status
|
||||
ChatHistoryStatus? status,
|
||||
Image? preCachedImage
|
||||
}) {
|
||||
return ChatHistory(
|
||||
message: message ?? this.message,
|
||||
type: type ?? this.type,
|
||||
status: status ?? this.status
|
||||
status: status ?? this.status,
|
||||
preCachedImage: preCachedImage ?? this.preCachedImage
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-14 17:04:20
|
||||
* @LastEditTime : 2022-10-20 00:47:44
|
||||
* @LastEditTime : 2022-10-20 11:05:37
|
||||
* @Description :
|
||||
*/
|
||||
|
||||
@ -24,7 +24,7 @@ class ImageBox extends StatelessWidget {
|
||||
onTap: (){},
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 500, maxHeight: 250),
|
||||
child: Image.memory(base64Decode(history.message.contentDecoded)),
|
||||
child: history.preCachedImage ?? Image.memory(base64Decode(history.message.contentDecoded)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author : Linloir
|
||||
* @Date : 2022-10-10 08:04:53
|
||||
* @LastEditTime : 2022-10-19 11:17:44
|
||||
* @LastEditTime : 2022-10-20 10:34:41
|
||||
* @Description :
|
||||
*/
|
||||
import 'package:easy_debounce/easy_debounce.dart';
|
||||
@ -38,12 +38,12 @@ void main() async {
|
||||
skipTaskbar: false,
|
||||
titleBarStyle: TitleBarStyle.normal
|
||||
);
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
await windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
if(posX != null && posY != null) {
|
||||
await windowManager.setPosition(Offset(posX, posY));
|
||||
}
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user