forked from eatvio/eatvio_app
fix: fix lazy loading in chat and feed
This commit is contained in:
@@ -27,16 +27,18 @@ class ChatScreen extends StatefulWidget {
|
||||
class _ChatScreenState extends State<ChatScreen> {
|
||||
final scrollController = ScrollController();
|
||||
final TextEditingController textEditingController = TextEditingController();
|
||||
final ChatRoomCubit chatRoomCubit = sl<ChatRoomCubit>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
scrollController.addListener(_onScroll);
|
||||
super.initState();
|
||||
scrollController.addListener(_onScroll);
|
||||
chatRoomCubit.initChat(widget.chatId);
|
||||
}
|
||||
|
||||
_onScroll() {
|
||||
if (scrollController.offset >= scrollController.position.maxScrollExtent && !scrollController.position.outOfRange) {
|
||||
context.read<ChatRoomCubit>().loadNextPage(widget.chatId);
|
||||
chatRoomCubit.loadNextPage(widget.chatId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +50,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<ChatRoomCubit>(
|
||||
create: (BuildContext context) => sl()..initChat(widget.chatId),
|
||||
create: (BuildContext context) => chatRoomCubit,
|
||||
child: BlocBuilder<ChatRoomCubit, ChatRoomState>(
|
||||
bloc: chatRoomCubit,
|
||||
builder: (context, state) {
|
||||
if (state is ChatRoomStateLoaded) {
|
||||
return _buildChat(context, state);
|
||||
@@ -234,7 +237,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
if (result != null) {
|
||||
List<File> files = result.paths.map((path) => File(path!)).toList();
|
||||
context.read<ChatRoomCubit>().sendMessage(
|
||||
chatRoomCubit.sendMessage(
|
||||
chatId: widget.chatId,
|
||||
files: files,
|
||||
);
|
||||
@@ -305,7 +308,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
customBorder: CircleBorder(),
|
||||
onTap: () {
|
||||
if (textEditingController.text.isNotEmpty) {
|
||||
context.read<ChatRoomCubit>().sendMessage(
|
||||
chatRoomCubit.sendMessage(
|
||||
chatId: widget.chatId,
|
||||
data: textEditingController.text.trim(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user