mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
Add the first iterator of a different Notes View
This view is similar to the classical Google Keep style of showing notes. It's still very bare-bones though
This commit is contained in:
89
lib/widgets/notes_list.dart
Normal file
89
lib/widgets/notes_list.dart
Normal file
@ -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<Note> 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),
|
||||
);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user