mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-15 16:03:34 +08:00

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.
59 lines
1.6 KiB
Dart
59 lines
1.6 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.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';
|
|
|
|
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
|
|
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],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
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) {
|
|
var note = folder.notes[index];
|
|
return NoteTile(note, noteSelectedFunction);
|
|
},
|
|
maxCrossAxisExtent: 200.0,
|
|
staggeredTileBuilder: (int i) => stagTile,
|
|
mainAxisSpacing: 8.0,
|
|
crossAxisSpacing: 8.0,
|
|
padding: const EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 16.0),
|
|
);
|
|
|
|
return gridView;
|
|
}
|
|
}
|