Attempt to fix Scroll-to Bug

pull/481/head
Sarah Jamie Lewis 6 months ago
parent 8570199196
commit b425175fff
  1. 2
      lib/models/contactlist.dart
  2. 15
      lib/views/contactsview.dart
  3. 2
      lib/views/messageview.dart
  4. 3
      lib/widgets/messagerow.dart

@ -21,7 +21,7 @@ class ContactListState extends ChangeNotifier {
}
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();
}

@ -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(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
Provider.of<AppState>(context, listen: false).initialScrollIndex = unread;
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(
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) {
return tiles.elementAt(index);
},

@ -144,7 +144,7 @@ class _MessageViewState extends State<MessageView> {
onPressed: () {
Provider.of<AppState>(context, listen: false).initialScrollIndex = 0;
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,
appBar: AppBar(

@ -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<MessageRow> with SingleTickerProviderStateMi
// Can't happen
} else {
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);
}
}

Loading…
Cancel
Save