Attempt to fix Scroll-to Bug
continuous-integration/drone/pr Build was killed Details

This commit is contained in:
Sarah Jamie Lewis 2022-06-20 11:41:31 -07:00
parent 8570199196
commit b425175fff
4 changed files with 17 additions and 5 deletions

View File

@ -21,7 +21,7 @@ class ContactListState extends ChangeNotifier {
} }
List<ContactInfoState> filteredList() { List<ContactInfoState> 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(); return _contacts.where((ContactInfoState c) => c.onion.toLowerCase().startsWith(_filter) || (c.nickname.toLowerCase().contains(_filter))).toList();
} }

View File

@ -36,8 +36,7 @@ void selectConversation(BuildContext context, int handle) {
Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(previouslySelected)!.unselected(); Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(previouslySelected)!.unselected();
} }
Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle)!.selected(); Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle)!.selected();
var contactIndex = Provider.of<ProfileInfoState>(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == handle);
Provider.of<ProfileInfoState>(context, listen: false).contactListScrollController.scrollTo(index: contactIndex, duration: Duration(milliseconds: 500));
// triggers update in Double/TripleColumnView // triggers update in Double/TripleColumnView
Provider.of<AppState>(context, listen: false).initialScrollIndex = unread; Provider.of<AppState>(context, listen: false).initialScrollIndex = unread;
Provider.of<AppState>(context, listen: false).selectedConversation = handle; Provider.of<AppState>(context, listen: false).selectedConversation = handle;
@ -216,9 +215,19 @@ class _ContactsViewState extends State<ContactsView> {
); );
}); });
var initialScroll =
Provider.of<ProfileInfoState>(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == Provider.of<AppState>(context).selectedConversation);
if (initialScroll < 0) {
initialScroll = 0;
}
var contactList = ScrollablePositionedList.separated( var contactList = ScrollablePositionedList.separated(
itemScrollController: Provider.of<ProfileInfoState>(context).contactListScrollController, itemScrollController: Provider.of<ProfileInfoState>(context).contactListScrollController,
itemCount: tiles.length, itemCount: Provider.of<ContactListState>(context).num,
initialScrollIndex: initialScroll,
shrinkWrap: true,
physics: BouncingScrollPhysics(),
semanticChildCount: Provider.of<ContactListState>(context).num,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return tiles.elementAt(index); return tiles.elementAt(index);
}, },

View File

@ -144,7 +144,7 @@ class _MessageViewState extends State<MessageView> {
onPressed: () { onPressed: () {
Provider.of<AppState>(context, listen: false).initialScrollIndex = 0; Provider.of<AppState>(context, listen: false).initialScrollIndex = 0;
Provider.of<AppState>(context, listen: false).unreadMessagesBelow = false; Provider.of<AppState>(context, listen: false).unreadMessagesBelow = false;
Provider.of<ContactInfoState>(context).messageScrollController.scrollTo(index: 0, duration: Duration(milliseconds: 600)); Provider.of<ContactInfoState>(context, listen: false).messageScrollController.scrollTo(index: 0, duration: Duration(milliseconds: 600));
}) })
: null, : null,
appBar: AppBar( appBar: AppBar(

View File

@ -12,6 +12,7 @@ import 'package:cwtch/widgets/profileimage.dart';
import 'package:flutter/physics.dart'; import 'package:flutter/physics.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import '../main.dart'; import '../main.dart';
import '../settings.dart'; import '../settings.dart';
@ -274,6 +275,8 @@ class MessageRowState extends State<MessageRow> with SingleTickerProviderStateMi
// Can't happen // Can't happen
} else { } else {
selectConversation(context, id); selectConversation(context, id);
var contactIndex = Provider.of<ProfileInfoState>(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == id);
Provider.of<ProfileInfoState>(context, listen: false).contactListScrollController.jumpTo(index: contactIndex);
} }
} }