mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-14 07:00:50 +08:00
GridView: Use CardView internally
Just with a fixed height card. This way we save on lots of code duplication, specially as each of these views will become more complex as we add dismissable, animations and selectable notes.
This commit is contained in:
@ -1,21 +1,20 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/folder_views/note_tile.dart';
|
||||
|
||||
typedef void NoteSelectedFunction(Note note);
|
||||
|
||||
class CardView extends StatelessWidget {
|
||||
final NoteSelectedFunction noteSelectedFunction;
|
||||
final NotesFolder folder;
|
||||
final String emptyText;
|
||||
final bool fixedHeight;
|
||||
|
||||
CardView({
|
||||
@required this.folder,
|
||||
@required this.noteSelectedFunction,
|
||||
@required this.emptyText,
|
||||
this.fixedHeight = false,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -34,6 +33,13 @@ class CardView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
StaggeredTile stagTile;
|
||||
if (fixedHeight) {
|
||||
stagTile = const StaggeredTile.extent(1, 200.0);
|
||||
} else {
|
||||
stagTile = const StaggeredTile.fit(1);
|
||||
}
|
||||
|
||||
var gridView = StaggeredGridView.extentBuilder(
|
||||
itemCount: folder.notes.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
@ -41,7 +47,7 @@ class CardView extends StatelessWidget {
|
||||
return NoteTile(note, noteSelectedFunction);
|
||||
},
|
||||
maxCrossAxisExtent: 200.0,
|
||||
staggeredTileBuilder: (int i) => const StaggeredTile.fit(1),
|
||||
staggeredTileBuilder: (int i) => stagTile,
|
||||
mainAxisSpacing: 8.0,
|
||||
crossAxisSpacing: 8.0,
|
||||
padding: const EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 16.0),
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/folder_views/card_view.dart';
|
||||
import 'package:gitjournal/folder_views/note_tile.dart';
|
||||
|
||||
class GridFolderView extends StatelessWidget {
|
||||
@ -16,42 +17,11 @@ class GridFolderView 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 CardView(
|
||||
folder: folder,
|
||||
noteSelectedFunction: noteSelectedFunction,
|
||||
emptyText: emptyText,
|
||||
fixedHeight: true,
|
||||
);
|
||||
}
|
||||
|
||||
var gridView = GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 200.0,
|
||||
mainAxisSpacing: 10.0,
|
||||
crossAxisSpacing: 10.0,
|
||||
childAspectRatio: 1 / 1.1,
|
||||
),
|
||||
itemBuilder: _buildItem,
|
||||
itemCount: folder.notes.length,
|
||||
padding: const EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 16.0),
|
||||
);
|
||||
|
||||
return gridView;
|
||||
}
|
||||
|
||||
Widget _buildItem(BuildContext context, int i) {
|
||||
// vHanda FIXME: Why does this method get called with i >= length ?
|
||||
if (i >= folder.notes.length) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
var note = folder.notes[i];
|
||||
return NoteTile(note, noteSelectedFunction);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user