🐛 Bug fixes of infinite reloading

This commit is contained in:
LittleSheep 2024-05-02 21:19:37 +08:00
parent e5a4554bdd
commit 1a5faabf86

View File

@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart'; import 'package:flutter_animate/flutter_animate.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/models/message.dart'; import 'package:solian/models/message.dart';
import 'package:solian/models/pagination.dart'; import 'package:solian/models/pagination.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
@ -144,6 +143,11 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
_pagingController.addPageRequestListener((pageKey) => fetchMessages(pageKey, context)); _pagingController.addPageRequestListener((pageKey) => fetchMessages(pageKey, context));
super.initState(); super.initState();
Future.delayed(Duration.zero, () {
_chat.fetchOngoingCall(widget.alias);
_chat.fetchChannel(widget.alias);
});
} }
@override @override
@ -199,58 +203,54 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
], ],
); );
return FutureBuilder( if (_chat.focusChannel == null) {
future: (() async { return const Center(child: CircularProgressIndicator());
final res = await Future.wait([ }
_chat.fetchOngoingCall(widget.alias),
_chat.fetchChannel(widget.alias),
]);
return res[1] as Channel;
})(),
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == null) {
return const Center(child: CircularProgressIndicator());
}
return ChatMaintainer( return ChatMaintainer(
channel: snapshot.data!, channel: _chat.focusChannel!,
child: Stack( child: Stack(
children: [
Column(
children: [ children: [
Column( Expanded(
children: [ child: PagedListView<int, Message>(
Expanded( reverse: true,
child: PagedListView<int, Message>( pagingController: _pagingController,
reverse: true, builderDelegate: PagedChildBuilderDelegate<Message>(
pagingController: _pagingController, animateTransitions: true,
builderDelegate: PagedChildBuilderDelegate<Message>( transitionDuration: 500.ms,
animateTransitions: true, itemBuilder: chatHistoryBuilder,
transitionDuration: 500.ms, noItemsFoundIndicatorBuilder: (_) => Container(),
itemBuilder: chatHistoryBuilder,
noItemsFoundIndicatorBuilder: (_) => Container(),
),
),
), ),
ChatMessageEditor( ),
channel: widget.alias, ),
editing: _editingItem, ChatMessageEditor(
replying: _replyingItem, channel: widget.alias,
onReset: () => setState(() { editing: _editingItem,
_editingItem = null; replying: _replyingItem,
_replyingItem = null; onReset: () => setState(() {
}), _editingItem = null;
), _replyingItem = null;
], }),
), ),
_chat.ongoingCall != null ? callBanner.animate().slideY() : Container(),
], ],
), ),
onInsertMessage: (message) => addMessage(message), _chat.ongoingCall != null ? callBanner.animate().slideY() : Container(),
onUpdateMessage: (message) => updateMessage(message), ],
onDeleteMessage: (message) => deleteMessage(message), ),
onCallStarted: (call) => _chat.setOngoingCall(call), onInsertMessage: (message) => addMessage(message),
onCallEnded: () => _chat.setOngoingCall(null), onUpdateMessage: (message) => updateMessage(message),
); onDeleteMessage: (message) => deleteMessage(message),
}, onCallStarted: (call) => _chat.setOngoingCall(call),
onCallEnded: () => _chat.setOngoingCall(null),
); );
} }
@override
void deactivate() {
_chat.focusChannel = null;
_chat.ongoingCall = null;
super.deactivate();
}
} }