Merge pull request #60 from GetStream/fix/channel-list-scroll-performance
fix(ui): channel list performance
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:example/localizations.dart';
|
|||||||
import 'package:example/routes/routes.dart';
|
import 'package:example/routes/routes.dart';
|
||||||
import 'package:example/search_text_field.dart';
|
import 'package:example/search_text_field.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
import 'channel_page.dart';
|
import 'channel_page.dart';
|
||||||
@@ -16,6 +17,8 @@ class ChannelList extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ChannelList extends State<ChannelList> {
|
class _ChannelList extends State<ChannelList> {
|
||||||
|
ScrollController _scrollController = ScrollController();
|
||||||
|
|
||||||
TextEditingController? _controller;
|
TextEditingController? _controller;
|
||||||
|
|
||||||
String _channelQuery = '';
|
String _channelQuery = '';
|
||||||
@@ -46,6 +49,7 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_controller?.removeListener(_channelQueryListener);
|
_controller?.removeListener(_channelQueryListener);
|
||||||
_controller?.dispose();
|
_controller?.dispose();
|
||||||
|
_scrollController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,8 +65,17 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
child: NotificationListener<ScrollUpdateNotification>(
|
||||||
|
onNotification: (ScrollNotification scrollInfo) {
|
||||||
|
if (_scrollController.position.userScrollDirection ==
|
||||||
|
ScrollDirection.reverse) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
child: NestedScrollView(
|
child: NestedScrollView(
|
||||||
floatHeaderSlivers: true,
|
controller: _scrollController,
|
||||||
|
floatHeaderSlivers: false,
|
||||||
headerSliverBuilder: (_, __) => [
|
headerSliverBuilder: (_, __) => [
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: SearchTextField(
|
child: SearchTextField(
|
||||||
@@ -72,14 +85,8 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
body: AnimatedSwitcher(
|
body: _isSearchActive
|
||||||
duration: const Duration(milliseconds: 350),
|
? MessageSearchListView(
|
||||||
child: GestureDetector(
|
|
||||||
behavior: HitTestBehavior.opaque,
|
|
||||||
onPanDown: (_) => FocusScope.of(context).unfocus(),
|
|
||||||
child: _isSearchActive
|
|
||||||
? MessageSearchBloc(
|
|
||||||
child: MessageSearchListView(
|
|
||||||
showErrorTile: true,
|
showErrorTile: true,
|
||||||
messageQuery: _channelQuery,
|
messageQuery: _channelQuery,
|
||||||
filters: Filter.in_('members', [user!.id]),
|
filters: Filter.in_('members', [user!.id]),
|
||||||
@@ -90,7 +97,7 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
pullToRefresh: false,
|
pullToRefresh: false,
|
||||||
limit: 20,
|
limit: 30,
|
||||||
emptyBuilder: (_) {
|
emptyBuilder: (_) {
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
builder: (context, viewportConstraints) {
|
builder: (context, viewportConstraints) {
|
||||||
@@ -141,10 +148,8 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
)
|
)
|
||||||
: ChannelsBloc(
|
: ChannelListView(
|
||||||
child: ChannelListView(
|
|
||||||
onChannelTap: (channel, _) {
|
onChannelTap: (channel, _) {
|
||||||
Navigator.pushNamed(
|
Navigator.pushNamed(
|
||||||
context,
|
context,
|
||||||
@@ -160,7 +165,7 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
swipeToAction: true,
|
swipeToAction: true,
|
||||||
filter: Filter.in_('members', [user!.id]),
|
filter: Filter.in_('members', [user!.id]),
|
||||||
presence: true,
|
presence: true,
|
||||||
limit: 20,
|
limit: 30,
|
||||||
onViewInfoTap: (channel) {
|
onViewInfoTap: (channel) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
if (channel.memberCount == 2 && channel.isDistinct) {
|
if (channel.memberCount == 2 && channel.isDistinct) {
|
||||||
@@ -170,8 +175,8 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
builder: (context) => StreamChannel(
|
builder: (context) => StreamChannel(
|
||||||
channel: channel,
|
channel: channel,
|
||||||
child: ChatInfoScreen(
|
child: ChatInfoScreen(
|
||||||
messageTheme: StreamChatTheme.of(context)
|
messageTheme:
|
||||||
.ownMessageTheme,
|
StreamChatTheme.of(context).ownMessageTheme,
|
||||||
user: channel.state!.members
|
user: channel.state!.members
|
||||||
.where((m) =>
|
.where((m) =>
|
||||||
m.userId !=
|
m.userId !=
|
||||||
@@ -189,8 +194,8 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
builder: (context) => StreamChannel(
|
builder: (context) => StreamChannel(
|
||||||
channel: channel,
|
channel: channel,
|
||||||
child: GroupInfoScreen(
|
child: GroupInfoScreen(
|
||||||
messageTheme: StreamChatTheme.of(context)
|
messageTheme:
|
||||||
.ownMessageTheme,
|
StreamChatTheme.of(context).ownMessageTheme,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -200,8 +205,6 @@ class _ChannelList extends State<ChannelList> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,11 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
body: IndexedStack(
|
body: IndexedStack(
|
||||||
index: _currentIndex,
|
index: _currentIndex,
|
||||||
children: [
|
children: [
|
||||||
ChannelList(),
|
ChannelsBloc(
|
||||||
|
child: MessageSearchBloc(
|
||||||
|
child: ChannelList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
UserMentionsPage(),
|
UserMentionsPage(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user