🐛 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:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:provider/provider.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/models/message.dart';
import 'package:solian/models/pagination.dart';
import 'package:solian/providers/auth.dart';
@ -144,6 +143,11 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
_pagingController.addPageRequestListener((pageKey) => fetchMessages(pageKey, context));
super.initState();
Future.delayed(Duration.zero, () {
_chat.fetchOngoingCall(widget.alias);
_chat.fetchChannel(widget.alias);
});
}
@override
@ -199,21 +203,12 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
],
);
return FutureBuilder(
future: (() async {
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) {
if (_chat.focusChannel == null) {
return const Center(child: CircularProgressIndicator());
}
return ChatMaintainer(
channel: snapshot.data!,
channel: _chat.focusChannel!,
child: Stack(
children: [
Column(
@ -250,7 +245,12 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
onCallStarted: (call) => _chat.setOngoingCall(call),
onCallEnded: () => _chat.setOngoingCall(null),
);
},
);
}
@override
void deactivate() {
_chat.focusChannel = null;
_chat.ongoingCall = null;
super.deactivate();
}
}