diff --git a/lib/widgets/notes_list.dart b/lib/widgets/notes_list.dart new file mode 100644 index 00000000..235393de --- /dev/null +++ b/lib/widgets/notes_list.dart @@ -0,0 +1,89 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:gitjournal/note.dart'; +import 'package:gitjournal/utils/markdown.dart'; +import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; + +typedef void NoteSelectedFunction(int noteIndex); + +class NotesList extends StatelessWidget { + final NoteSelectedFunction noteSelectedFunction; + final List notes; + final String emptyText; + + NotesList({ + @required this.notes, + @required this.noteSelectedFunction, + @required this.emptyText, + }); + + @override + Widget build(BuildContext context) { + if (notes.isEmpty) { + return Center( + child: Text( + emptyText, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 28.0, + fontWeight: FontWeight.w300, + color: Colors.grey[350], + ), + ), + ); + } + + var gridView = StaggeredGridView.countBuilder( + crossAxisCount: 4, + itemCount: notes.length, + itemBuilder: (BuildContext context, int index) { + var note = notes[index]; + return _buildNoteCard(context, note, index); + }, + staggeredTileBuilder: (int i) => const StaggeredTile.fit(2), + mainAxisSpacing: 8.0, + crossAxisSpacing: 8.0, + ); + + return Padding( + padding: const EdgeInsets.all(8.0), + child: gridView, + ); + } + + Widget _buildNoteCard(BuildContext context, Note journal, int noteIndex) { + var body = stripMarkdownFormatting(journal.body); + + var textTheme = Theme.of(context).textTheme; + var tileContent = Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + body, + maxLines: 30, + overflow: TextOverflow.ellipsis, + style: textTheme.body1, + ), + ); + + const borderRadius = BorderRadius.all(Radius.circular(8)); + var tile = Material( + borderRadius: borderRadius, + type: MaterialType.card, + child: tileContent, + ); + + /*var tile = Container( + decoration: BoxDecoration( + border: Border.all(color: Colors.grey[200]), + color: Colors.white, + borderRadius: borderRadius, + child: tileContent, + );*/ + + return InkWell( + child: tile, + borderRadius: borderRadius, + //onTap: () => noteSelectedFunction(noteIndex), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 57fe41b8..0cd6377f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -172,6 +172,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.0" + flutter_staggered_grid_view: + dependency: "direct main" + description: + name: flutter_staggered_grid_view + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" flutter_test: dependency: "direct dev" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index a909f0b3..4f50f837 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: fimber: ^0.3.0 dynamic_theme: ^1.0.0 flushbar: ^1.9.0 + flutter_staggered_grid_view: ^0.3.0 dev_dependencies: flutter_launcher_icons: "^0.7.2"