Merge pull request #693 from GetStream/fix/674
fix(ui): check scrollController is attached before calling jump.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
- [[#668]](https://github.com/GetStream/stream-chat-flutter/issues/668): Fix `MessageInput` rendering errors in case
|
||||
there are no actions available to show.
|
||||
- [[#349]](https://github.com/GetStream/stream-chat-flutter/issues/349): Fix `MessageInput` attachment render overflow error.
|
||||
- [[#674]](https://github.com/GetStream/stream-chat-flutter/issues/674): Check scrollController is attached before calling jump in MessageListView.
|
||||
|
||||
🔄 Changed
|
||||
|
||||
|
||||
@@ -1199,10 +1199,12 @@ class _MessageListViewState extends State<MessageListView> {
|
||||
initialAlignment = _initialAlignment;
|
||||
|
||||
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
|
||||
_scrollController?.jumpTo(
|
||||
index: initialIndex,
|
||||
alignment: initialAlignment,
|
||||
);
|
||||
if (_scrollController?.isAttached == true) {
|
||||
_scrollController?.jumpTo(
|
||||
index: initialIndex,
|
||||
alignment: initialAlignment,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
_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