Skip to content

Commit

Permalink
the best way to fix the scroll position issue in previous/next page
Browse files Browse the repository at this point in the history
  • Loading branch information
shukebeta committed Jun 26, 2024
1 parent 8b3bf2e commit 35b19c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lib/screens/components/note_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ class NoteList extends StatelessWidget {
final Function(Note)? onDoubleTap;
final Future<void> Function()? onRefresh;
final bool showDate;
final ScrollController _scrollController = ScrollController();

const NoteList({
NoteList({
Key? key,
required this.notes,
required this.onTap,
this.onDoubleTap,
this.onRefresh,
this.showDate = true,
}) : super(key: key);
}) : super(key: key) {
// Scroll to the top position when the widget is built or updated
WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollController.jumpTo(0);
});
}

@override
Widget build(BuildContext context) {
Expand All @@ -33,6 +39,7 @@ class NoteList extends StatelessWidget {
return RefreshIndicator(
onRefresh: onRefresh ?? () async {},
child: ListView.builder(
controller: _scrollController,
itemCount: notesByDate.keys.length,
itemBuilder: (context, index) {
final dateKey = notesByDate.keys.elementAt(index);
Expand All @@ -43,8 +50,7 @@ class NoteList extends StatelessWidget {
// Date header
if (showDate)
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 16.0),
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Align(
alignment: Alignment.center,
child: Text(
Expand All @@ -64,14 +70,11 @@ class NoteList extends StatelessWidget {
children: [
CombinedTimeSeparator(note: note),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 1.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 1.0),
child: NoteListItem(
note: note,
onTap: () => onTap(note),
onDoubleTap: onDoubleTap != null
? () => onDoubleTap!(note)
: null,
onDoubleTap: onDoubleTap != null ? () => onDoubleTap!(note) : null,
),
),
],
Expand Down
1 change: 0 additions & 1 deletion lib/screens/home_page/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import '../components/floating_pagination.dart';
import '../components/note_list.dart';
import '../components/pagination_controls.dart';
import '../../dependency_injection.dart';
import '../../utils/util.dart';
import '../account/user_session.dart';
import '../new_note/new_note.dart';
import 'home_page_controller.dart';
Expand Down

0 comments on commit 35b19c7

Please sign in to comment.