From b425175fff769e0f41ee156bab295d1b8ddfd858 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 20 Jun 2022 11:41:31 -0700 Subject: [PATCH] Attempt to fix Scroll-to Bug --- lib/models/contactlist.dart | 2 +- lib/views/contactsview.dart | 15 ++++++++++++--- lib/views/messageview.dart | 2 +- lib/widgets/messagerow.dart | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/models/contactlist.dart b/lib/models/contactlist.dart index 835b6161..afeb5edb 100644 --- a/lib/models/contactlist.dart +++ b/lib/models/contactlist.dart @@ -21,7 +21,7 @@ class ContactListState extends ChangeNotifier { } List filteredList() { - if (!isFiltered) return contacts; + if (!isFiltered) return _contacts; return _contacts.where((ContactInfoState c) => c.onion.toLowerCase().startsWith(_filter) || (c.nickname.toLowerCase().contains(_filter))).toList(); } diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 6cb975f6..8723cbad 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -36,8 +36,7 @@ void selectConversation(BuildContext context, int handle) { Provider.of(context, listen: false).contactList.getContact(previouslySelected)!.unselected(); } Provider.of(context, listen: false).contactList.getContact(handle)!.selected(); - var contactIndex = Provider.of(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == handle); - Provider.of(context, listen: false).contactListScrollController.scrollTo(index: contactIndex, duration: Duration(milliseconds: 500)); + // triggers update in Double/TripleColumnView Provider.of(context, listen: false).initialScrollIndex = unread; Provider.of(context, listen: false).selectedConversation = handle; @@ -216,9 +215,19 @@ class _ContactsViewState extends State { ); }); + var initialScroll = + Provider.of(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == Provider.of(context).selectedConversation); + if (initialScroll < 0) { + initialScroll = 0; + } + var contactList = ScrollablePositionedList.separated( itemScrollController: Provider.of(context).contactListScrollController, - itemCount: tiles.length, + itemCount: Provider.of(context).num, + initialScrollIndex: initialScroll, + shrinkWrap: true, + physics: BouncingScrollPhysics(), + semanticChildCount: Provider.of(context).num, itemBuilder: (context, index) { return tiles.elementAt(index); }, diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index 21d0b501..75c43ba3 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -144,7 +144,7 @@ class _MessageViewState extends State { onPressed: () { Provider.of(context, listen: false).initialScrollIndex = 0; Provider.of(context, listen: false).unreadMessagesBelow = false; - Provider.of(context).messageScrollController.scrollTo(index: 0, duration: Duration(milliseconds: 600)); + Provider.of(context, listen: false).messageScrollController.scrollTo(index: 0, duration: Duration(milliseconds: 600)); }) : null, appBar: AppBar( diff --git a/lib/widgets/messagerow.dart b/lib/widgets/messagerow.dart index f52921c8..3bbb8b87 100644 --- a/lib/widgets/messagerow.dart +++ b/lib/widgets/messagerow.dart @@ -12,6 +12,7 @@ import 'package:cwtch/widgets/profileimage.dart'; import 'package:flutter/physics.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../main.dart'; import '../settings.dart'; @@ -274,6 +275,8 @@ class MessageRowState extends State with SingleTickerProviderStateMi // Can't happen } else { selectConversation(context, id); + var contactIndex = Provider.of(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == id); + Provider.of(context, listen: false).contactListScrollController.jumpTo(index: contactIndex); } }