diff --git a/lib/folder_views/card_view.dart b/lib/folder_views/card_view.dart index 900b700f..58de8216 100644 --- a/lib/folder_views/card_view.dart +++ b/lib/folder_views/card_view.dart @@ -4,6 +4,7 @@ import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/notes_folder.dart'; +import 'package:gitjournal/folder_views/empty_text_sliver.dart'; import 'package:gitjournal/folder_views/note_tile.dart'; class CardView extends StatelessWidget { @@ -30,17 +31,7 @@ class CardView extends StatelessWidget { @override Widget build(BuildContext context) { if (folder.isEmpty) { - return Center( - child: Text( - emptyText, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 28.0, - fontWeight: FontWeight.w300, - color: Colors.grey[350], - ), - ), - ); + return EmptyTextSliver(emptyText: emptyText); } StaggeredTile stagTile; @@ -50,7 +41,7 @@ class CardView extends StatelessWidget { stagTile = const StaggeredTile.fit(1); } - var gridView = StaggeredGridView.extentBuilder( + var gridView = SliverStaggeredGrid.extentBuilder( itemCount: folder.notes.length, itemBuilder: (BuildContext context, int index) { var note = folder.notes[index]; @@ -66,9 +57,11 @@ class CardView extends StatelessWidget { staggeredTileBuilder: (int i) => stagTile, mainAxisSpacing: 8.0, crossAxisSpacing: 8.0, - padding: const EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 16.0), ); - return gridView; + return SliverPadding( + sliver: gridView, + padding: const EdgeInsets.fromLTRB(8.0, 12.0, 8.0, 12.0 + 48.0), + ); } } diff --git a/lib/folder_views/empty_text_sliver.dart b/lib/folder_views/empty_text_sliver.dart new file mode 100644 index 00000000..dd0a66d4 --- /dev/null +++ b/lib/folder_views/empty_text_sliver.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; + +// FIXME: Why are you scrollable!! +class EmptyTextSliver extends StatelessWidget { + const EmptyTextSliver({ + Key? key, + required this.emptyText, + }) : super(key: key); + + final String emptyText; + + @override + Widget build(BuildContext context) { + return SliverFillRemaining( + child: Center( + child: Text( + emptyText, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 28.0, + fontWeight: FontWeight.w300, + color: Colors.grey[350], + ), + ), + ), + hasScrollBody: false, + fillOverscroll: false, + ); + } +} diff --git a/lib/folder_views/folder_view.dart b/lib/folder_views/folder_view.dart index cc488972..50937e97 100644 --- a/lib/folder_views/folder_view.dart +++ b/lib/folder_views/folder_view.dart @@ -94,40 +94,38 @@ class _FolderViewState extends State { title = NumberFormat.compact().format(1); } - Widget folderView = Builder( - builder: (BuildContext context) { - return buildFolderView( - viewType: _viewType, - folder: sortedNotesFolder, - emptyText: tr('screens.folder_view.empty'), - header: _headerType, - showSummary: _showSummary, - noteTapped: (Note note) { - if (!inSelectionMode) { - openNoteEditor(context, note, widget.notesFolder); - } else { - _resetSelection(); - } - }, - noteLongPressed: (Note note) { - setState(() { - inSelectionMode = true; - selectedNote = note; - }); - }, - isNoteSelected: (n) => n == selectedNote, - searchTerm: "", - ); + // vHanda: Fixme the openNoteEditor will fail! Wrong context! + var folderView = buildFolderView( + viewType: _viewType, + folder: sortedNotesFolder, + emptyText: tr('screens.folder_view.empty'), + header: _headerType, + showSummary: _showSummary, + noteTapped: (Note note) { + if (!inSelectionMode) { + openNoteEditor(context, note, widget.notesFolder); + } else { + _resetSelection(); + } }, + noteLongPressed: (Note note) { + setState(() { + inSelectionMode = true; + selectedNote = note; + }); + }, + isNoteSelected: (n) => n == selectedNote, + searchTerm: "", ); + // assert(folderView is SliverWithKeepAliveWidget); var settings = Provider.of(context); final showButtomMenuBar = settings.bottomMenuBar; // So the FAB doesn't hide parts of the last entry if (!showButtomMenuBar) { - folderView = Padding( - child: folderView, + folderView = SliverPadding( + sliver: folderView, padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 48.0), ); } @@ -138,14 +136,22 @@ class _FolderViewState extends State { ); return Scaffold( - appBar: AppBar( - title: Text(title), - leading: inSelectionMode ? backButton : GJAppBarMenuButton(), - actions: inSelectionMode - ? _buildInSelectionNoteActions() - : _buildNoteActions(), + body: CustomScrollView( + slivers: [ + SliverAppBar( + title: Text(title), + leading: inSelectionMode ? backButton : GJAppBarMenuButton(), + actions: inSelectionMode + ? _buildInSelectionNoteActions() + : _buildNoteActions(), + floating: true, + forceElevated: true, + ), + folderView, + ], ), - body: Center( + /* + Center( child: Builder( builder: (context) { var child = Scrollbar(child: folderView); @@ -159,6 +165,7 @@ class _FolderViewState extends State { }, ), ), + */ extendBody: true, drawer: AppDrawer(), floatingActionButton: createButton, diff --git a/lib/folder_views/list_view.dart b/lib/folder_views/list_view.dart index 74271dcd..23b9bddd 100644 --- a/lib/folder_views/list_view.dart +++ b/lib/folder_views/list_view.dart @@ -9,6 +9,7 @@ import 'package:gitjournal/repository.dart'; import 'package:gitjournal/settings/settings.dart'; import 'package:gitjournal/utils/utils.dart'; import 'package:gitjournal/widgets/icon_dismissable.dart'; +import 'empty_text_sliver.dart'; typedef Widget NoteTileBuilder(BuildContext context, Note note); @@ -97,25 +98,14 @@ class _FolderListViewState extends State { @override Widget build(BuildContext context) { - if (widget.folder.notes.isEmpty) { - return Center( - child: Text( - widget.emptyText, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 28.0, - fontWeight: FontWeight.w300, - color: Colors.grey[350], - ), - ), - ); + if (widget.folder.isEmpty) { + return EmptyTextSliver(emptyText: widget.emptyText); } - return AnimatedList( + return SliverAnimatedList( key: _listKey, itemBuilder: _buildItem, initialItemCount: widget.folder.notes.length, - padding: const EdgeInsets.fromLTRB(0, 0, 0, 48), ); } diff --git a/lib/folder_views/note_tile.dart b/lib/folder_views/note_tile.dart index ec8e51ad..f8182dc9 100644 --- a/lib/folder_views/note_tile.dart +++ b/lib/folder_views/note_tile.dart @@ -81,6 +81,7 @@ class NoteTile extends StatelessWidget { static const _maxLines = 12; + // FIXME: vHanda: This doesn't need to be computed again and again! String _displayText() { var foundSearchTerm = searchTerm.isEmpty ? true : false; var buffer = [];