mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-25 16:19:58 +08:00
FolderViews: Hide the AppBar when scrolling
This breaks a number of other things, but this commit was becoming messy.
This commit is contained in:
@ -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/note.dart';
|
||||||
import 'package:gitjournal/core/notes_folder.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';
|
import 'package:gitjournal/folder_views/note_tile.dart';
|
||||||
|
|
||||||
class CardView extends StatelessWidget {
|
class CardView extends StatelessWidget {
|
||||||
@ -30,17 +31,7 @@ class CardView extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (folder.isEmpty) {
|
if (folder.isEmpty) {
|
||||||
return Center(
|
return EmptyTextSliver(emptyText: emptyText);
|
||||||
child: Text(
|
|
||||||
emptyText,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 28.0,
|
|
||||||
fontWeight: FontWeight.w300,
|
|
||||||
color: Colors.grey[350],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StaggeredTile stagTile;
|
StaggeredTile stagTile;
|
||||||
@ -50,7 +41,7 @@ class CardView extends StatelessWidget {
|
|||||||
stagTile = const StaggeredTile.fit(1);
|
stagTile = const StaggeredTile.fit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var gridView = StaggeredGridView.extentBuilder(
|
var gridView = SliverStaggeredGrid.extentBuilder(
|
||||||
itemCount: folder.notes.length,
|
itemCount: folder.notes.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
var note = folder.notes[index];
|
var note = folder.notes[index];
|
||||||
@ -66,9 +57,11 @@ class CardView extends StatelessWidget {
|
|||||||
staggeredTileBuilder: (int i) => stagTile,
|
staggeredTileBuilder: (int i) => stagTile,
|
||||||
mainAxisSpacing: 8.0,
|
mainAxisSpacing: 8.0,
|
||||||
crossAxisSpacing: 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),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
lib/folder_views/empty_text_sliver.dart
Normal file
30
lib/folder_views/empty_text_sliver.dart
Normal file
@ -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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -94,40 +94,38 @@ class _FolderViewState extends State<FolderView> {
|
|||||||
title = NumberFormat.compact().format(1);
|
title = NumberFormat.compact().format(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget folderView = Builder(
|
// vHanda: Fixme the openNoteEditor will fail! Wrong context!
|
||||||
builder: (BuildContext context) {
|
var folderView = buildFolderView(
|
||||||
return buildFolderView(
|
viewType: _viewType,
|
||||||
viewType: _viewType,
|
folder: sortedNotesFolder,
|
||||||
folder: sortedNotesFolder,
|
emptyText: tr('screens.folder_view.empty'),
|
||||||
emptyText: tr('screens.folder_view.empty'),
|
header: _headerType,
|
||||||
header: _headerType,
|
showSummary: _showSummary,
|
||||||
showSummary: _showSummary,
|
noteTapped: (Note note) {
|
||||||
noteTapped: (Note note) {
|
if (!inSelectionMode) {
|
||||||
if (!inSelectionMode) {
|
openNoteEditor(context, note, widget.notesFolder);
|
||||||
openNoteEditor(context, note, widget.notesFolder);
|
} else {
|
||||||
} else {
|
_resetSelection();
|
||||||
_resetSelection();
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
noteLongPressed: (Note note) {
|
|
||||||
setState(() {
|
|
||||||
inSelectionMode = true;
|
|
||||||
selectedNote = note;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
isNoteSelected: (n) => n == selectedNote,
|
|
||||||
searchTerm: "",
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
noteLongPressed: (Note note) {
|
||||||
|
setState(() {
|
||||||
|
inSelectionMode = true;
|
||||||
|
selectedNote = note;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
isNoteSelected: (n) => n == selectedNote,
|
||||||
|
searchTerm: "",
|
||||||
);
|
);
|
||||||
|
// assert(folderView is SliverWithKeepAliveWidget);
|
||||||
|
|
||||||
var settings = Provider.of<Settings>(context);
|
var settings = Provider.of<Settings>(context);
|
||||||
final showButtomMenuBar = settings.bottomMenuBar;
|
final showButtomMenuBar = settings.bottomMenuBar;
|
||||||
|
|
||||||
// So the FAB doesn't hide parts of the last entry
|
// So the FAB doesn't hide parts of the last entry
|
||||||
if (!showButtomMenuBar) {
|
if (!showButtomMenuBar) {
|
||||||
folderView = Padding(
|
folderView = SliverPadding(
|
||||||
child: folderView,
|
sliver: folderView,
|
||||||
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 48.0),
|
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 48.0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -138,14 +136,22 @@ class _FolderViewState extends State<FolderView> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
body: CustomScrollView(
|
||||||
title: Text(title),
|
slivers: [
|
||||||
leading: inSelectionMode ? backButton : GJAppBarMenuButton(),
|
SliverAppBar(
|
||||||
actions: inSelectionMode
|
title: Text(title),
|
||||||
? _buildInSelectionNoteActions()
|
leading: inSelectionMode ? backButton : GJAppBarMenuButton(),
|
||||||
: _buildNoteActions(),
|
actions: inSelectionMode
|
||||||
|
? _buildInSelectionNoteActions()
|
||||||
|
: _buildNoteActions(),
|
||||||
|
floating: true,
|
||||||
|
forceElevated: true,
|
||||||
|
),
|
||||||
|
folderView,
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: Center(
|
/*
|
||||||
|
Center(
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
var child = Scrollbar(child: folderView);
|
var child = Scrollbar(child: folderView);
|
||||||
@ -159,6 +165,7 @@ class _FolderViewState extends State<FolderView> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
*/
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
drawer: AppDrawer(),
|
drawer: AppDrawer(),
|
||||||
floatingActionButton: createButton,
|
floatingActionButton: createButton,
|
||||||
|
@ -9,6 +9,7 @@ import 'package:gitjournal/repository.dart';
|
|||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/settings.dart';
|
||||||
import 'package:gitjournal/utils/utils.dart';
|
import 'package:gitjournal/utils/utils.dart';
|
||||||
import 'package:gitjournal/widgets/icon_dismissable.dart';
|
import 'package:gitjournal/widgets/icon_dismissable.dart';
|
||||||
|
import 'empty_text_sliver.dart';
|
||||||
|
|
||||||
typedef Widget NoteTileBuilder(BuildContext context, Note note);
|
typedef Widget NoteTileBuilder(BuildContext context, Note note);
|
||||||
|
|
||||||
@ -97,25 +98,14 @@ class _FolderListViewState extends State<FolderListView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (widget.folder.notes.isEmpty) {
|
if (widget.folder.isEmpty) {
|
||||||
return Center(
|
return EmptyTextSliver(emptyText: widget.emptyText);
|
||||||
child: Text(
|
|
||||||
widget.emptyText,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 28.0,
|
|
||||||
fontWeight: FontWeight.w300,
|
|
||||||
color: Colors.grey[350],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return AnimatedList(
|
return SliverAnimatedList(
|
||||||
key: _listKey,
|
key: _listKey,
|
||||||
itemBuilder: _buildItem,
|
itemBuilder: _buildItem,
|
||||||
initialItemCount: widget.folder.notes.length,
|
initialItemCount: widget.folder.notes.length,
|
||||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 48),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ class NoteTile extends StatelessWidget {
|
|||||||
|
|
||||||
static const _maxLines = 12;
|
static const _maxLines = 12;
|
||||||
|
|
||||||
|
// FIXME: vHanda: This doesn't need to be computed again and again!
|
||||||
String _displayText() {
|
String _displayText() {
|
||||||
var foundSearchTerm = searchTerm.isEmpty ? true : false;
|
var foundSearchTerm = searchTerm.isEmpty ? true : false;
|
||||||
var buffer = <String>[];
|
var buffer = <String>[];
|
||||||
|
Reference in New Issue
Block a user