fix(ui): check scrollController is attached before calling jump.
This commit is contained in:
@@ -1199,10 +1199,12 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
initialAlignment = _initialAlignment;
|
initialAlignment = _initialAlignment;
|
||||||
|
|
||||||
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
|
||||||
_scrollController?.jumpTo(
|
if (_scrollController?.isAttached ?? false) {
|
||||||
index: initialIndex,
|
_scrollController?.jumpTo(
|
||||||
alignment: initialAlignment,
|
index: initialIndex,
|
||||||
);
|
alignment: initialAlignment,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_messageNewListener =
|
_messageNewListener =
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
|
import 'mocks.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late StreamChatClient client;
|
||||||
|
late Channel channel;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
client = MockClient();
|
||||||
|
channel = MockChannel();
|
||||||
|
when(() => channel.on(any(), any(), any(), any()))
|
||||||
|
.thenAnswer((_) => const Stream.empty());
|
||||||
|
final channelClientState = MockChannelState();
|
||||||
|
when(() => channel.state).thenReturn(channelClientState);
|
||||||
|
when(() => channelClientState.threadsStream)
|
||||||
|
.thenAnswer((_) => const Stream.empty());
|
||||||
|
when(() => channelClientState.messagesStream)
|
||||||
|
.thenAnswer((_) => const Stream.empty());
|
||||||
|
when(() => channelClientState.messages).thenReturn([]);
|
||||||
|
when(() => channelClientState.isUpToDate).thenReturn(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// https://github.com/GetStream/stream-chat-flutter/issues/674
|
||||||
|
testWidgets('renders empty message list view', (tester) async {
|
||||||
|
const emptyWidgetKey = Key('empty_widget');
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: StreamChat(
|
||||||
|
client: client,
|
||||||
|
child: StreamChannel(
|
||||||
|
channel: channel,
|
||||||
|
child: MessageListView(
|
||||||
|
emptyBuilder: (_) => Container(key: emptyWidgetKey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(MessageListView), findsOneWidget);
|
||||||
|
expect(find.byKey(emptyWidgetKey), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user