Test ListView instead of ListView.builder
This commit is contained in:
parent
1765c31e9f
commit
c9acf47d04
3 changed files with 25 additions and 67 deletions
|
|
@ -12,7 +12,6 @@ class ChatProvider extends ChangeNotifier {
|
|||
|
||||
final channel = WebSocketChannel.connect(Uri.parse('wss://irc-ws.chat.twitch.tv:443'));
|
||||
final messages = <Widget>[];
|
||||
final scrollController = ScrollController();
|
||||
|
||||
final _assetToUrl = <String, String>{};
|
||||
final _emoteIdToWord = <String, String>{};
|
||||
|
|
@ -33,16 +32,6 @@ class ChatProvider extends ChangeNotifier {
|
|||
for (final command in commands) {
|
||||
channel.sink.add(command);
|
||||
}
|
||||
|
||||
scrollController.addListener(() {
|
||||
if (!scrollController.position.atEdge) {
|
||||
autoScroll = false;
|
||||
notifyListeners();
|
||||
} else if (scrollController.position.atEdge && scrollController.position.pixels != scrollController.position.minScrollExtent) {
|
||||
autoScroll = true;
|
||||
notifyListeners();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getEmotes() async {
|
||||
|
|
@ -113,11 +102,6 @@ class ChatProvider extends ChangeNotifier {
|
|||
messages.add(ChatMessage(
|
||||
children: privateMessage(tags: mappedTags, chatMessage: message),
|
||||
));
|
||||
if (autoScroll) {
|
||||
SchedulerBinding.instance?.addPostFrameCallback((_) {
|
||||
scrollController.jumpTo(scrollController.position.maxScrollExtent);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'ROOMSTATE':
|
||||
break;
|
||||
|
|
@ -221,14 +205,6 @@ class ChatProvider extends ChangeNotifier {
|
|||
return result;
|
||||
}
|
||||
|
||||
void resumeScroll() {
|
||||
autoScroll = true;
|
||||
scrollController.jumpTo(scrollController.position.maxScrollExtent);
|
||||
SchedulerBinding.instance?.addPostFrameCallback((_) {
|
||||
scrollController.jumpTo(scrollController.position.maxScrollExtent);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
channel.sink.close();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import 'package:frosty/screens/video_chat.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'chat.dart';
|
||||
|
||||
/// A card widget that displays a live channel's thumbnail and details.
|
||||
class ChannelCard extends StatelessWidget {
|
||||
final Channel channelInfo;
|
||||
|
|
@ -27,7 +29,7 @@ class ChannelCard extends StatelessWidget {
|
|||
),
|
||||
body: ChangeNotifierProvider<ChatProvider>(
|
||||
create: (context) => ChatProvider(channelInfo: channelInfo),
|
||||
child: VideoChat(channelInfo: channelInfo),
|
||||
child: Chat(channelInfo: channelInfo),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -12,50 +12,30 @@ class Chat extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
debugPrint('build');
|
||||
final viewModel = context.read<ChatProvider>();
|
||||
return SafeArea(
|
||||
child: FutureBuilder(
|
||||
future: viewModel.getEmotes(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return StreamBuilder(
|
||||
stream: viewModel.channel.stream,
|
||||
builder: (context, snapshot) {
|
||||
viewModel.handleWebsocketData(snapshot.data);
|
||||
return Stack(
|
||||
alignment: AlignmentDirectional.bottomCenter,
|
||||
children: [
|
||||
ListView.builder(
|
||||
addAutomaticKeepAlives: false,
|
||||
addRepaintBoundaries: false,
|
||||
physics: const ClampingScrollPhysics(),
|
||||
itemCount: viewModel.messages.length,
|
||||
controller: viewModel.scrollController,
|
||||
padding: const EdgeInsets.all(5.0),
|
||||
itemBuilder: (context, index) {
|
||||
return viewModel.messages[index];
|
||||
},
|
||||
),
|
||||
Consumer<ChatProvider>(
|
||||
builder: (context, viewModel, child) {
|
||||
return Visibility(
|
||||
visible: !viewModel.autoScroll,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => viewModel.resumeScroll(),
|
||||
child: const Text('Resume Scroll'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
return FutureBuilder(
|
||||
future: viewModel.getEmotes(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return StreamBuilder(
|
||||
stream: viewModel.channel.stream,
|
||||
builder: (context, snapshot) {
|
||||
viewModel.handleWebsocketData(snapshot.data);
|
||||
debugPrint('update');
|
||||
print(viewModel.messages);
|
||||
if (viewModel.messages.isNotEmpty) {
|
||||
return ListView(
|
||||
reverse: true,
|
||||
children: viewModel.messages.reversed.toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
}
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue