mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 20:43:20 +08:00
FolderViews: Null Safety++
This commit is contained in:
@ -317,11 +317,11 @@ class Note with NotesNotifier {
|
|||||||
return body.isEmpty;
|
return body.isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
String? get summary {
|
String get summary {
|
||||||
if (_loadState != NoteLoadState.Loaded) return "";
|
if (_loadState != NoteLoadState.Loaded) return "";
|
||||||
|
|
||||||
_summary ??= stripMarkdownFormatting(body);
|
_summary ??= stripMarkdownFormatting(body);
|
||||||
return _summary;
|
return _summary!;
|
||||||
}
|
}
|
||||||
|
|
||||||
NoteLoadState get loadState {
|
NoteLoadState get loadState {
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||||
@ -21,12 +18,12 @@ class CardView extends StatelessWidget {
|
|||||||
final String searchTerm;
|
final String searchTerm;
|
||||||
|
|
||||||
CardView({
|
CardView({
|
||||||
@required this.folder,
|
required this.folder,
|
||||||
@required this.noteTapped,
|
required this.noteTapped,
|
||||||
@required this.noteLongPressed,
|
required this.noteLongPressed,
|
||||||
@required this.isNoteSelected,
|
required this.isNoteSelected,
|
||||||
@required this.emptyText,
|
required this.emptyText,
|
||||||
@required this.searchTerm,
|
required this.searchTerm,
|
||||||
this.fixedHeight = false,
|
this.fixedHeight = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
@ -22,15 +20,15 @@ import 'standard_view.dart';
|
|||||||
export 'common_types.dart';
|
export 'common_types.dart';
|
||||||
|
|
||||||
Widget buildFolderView({
|
Widget buildFolderView({
|
||||||
@required FolderViewType viewType,
|
required FolderViewType viewType,
|
||||||
@required NotesFolder folder,
|
required NotesFolder folder,
|
||||||
@required String emptyText,
|
required String emptyText,
|
||||||
@required StandardViewHeader header,
|
required StandardViewHeader header,
|
||||||
@required bool showSummary,
|
required bool showSummary,
|
||||||
@required NoteSelectedFunction noteTapped,
|
required NoteSelectedFunction noteTapped,
|
||||||
@required NoteSelectedFunction noteLongPressed,
|
required NoteSelectedFunction noteLongPressed,
|
||||||
@required NoteBoolPropertyFunction isNoteSelected,
|
required NoteBoolPropertyFunction isNoteSelected,
|
||||||
@required String searchTerm,
|
required String searchTerm,
|
||||||
}) {
|
}) {
|
||||||
switch (viewType) {
|
switch (viewType) {
|
||||||
case FolderViewType.Standard:
|
case FolderViewType.Standard:
|
||||||
@ -72,9 +70,6 @@ Widget buildFolderView({
|
|||||||
searchTerm: searchTerm,
|
searchTerm: searchTerm,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false, "Code path should never be executed");
|
|
||||||
return Container();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void openNoteEditor(
|
void openNoteEditor(
|
||||||
@ -108,10 +103,11 @@ bool openNewNoteEditor(BuildContext context, String term) {
|
|||||||
|
|
||||||
var fileName = term;
|
var fileName = term;
|
||||||
if (fileName.contains(p.separator)) {
|
if (fileName.contains(p.separator)) {
|
||||||
parentFolder = rootFolder.getFolderWithSpec(p.dirname(fileName));
|
var pFolder = rootFolder.getFolderWithSpec(p.dirname(fileName));
|
||||||
if (parentFolder == null) {
|
if (pFolder == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
parentFolder = pFolder;
|
||||||
Log.i("New Note Parent Folder: ${parentFolder.folderPath}");
|
Log.i("New Note Parent Folder: ${parentFolder.folderPath}");
|
||||||
|
|
||||||
fileName = p.basename(term);
|
fileName = p.basename(term);
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:gitjournal/core/note.dart';
|
import 'package:gitjournal/core/note.dart';
|
||||||
@ -18,12 +15,12 @@ class GridFolderView extends StatelessWidget {
|
|||||||
final String searchTerm;
|
final String searchTerm;
|
||||||
|
|
||||||
GridFolderView({
|
GridFolderView({
|
||||||
@required this.folder,
|
required this.folder,
|
||||||
@required this.noteTapped,
|
required this.noteTapped,
|
||||||
@required this.noteLongPressed,
|
required this.noteLongPressed,
|
||||||
@required this.isNoteSelected,
|
required this.isNoteSelected,
|
||||||
@required this.emptyText,
|
required this.emptyText,
|
||||||
@required this.searchTerm,
|
required this.searchTerm,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
@ -25,12 +22,12 @@ class JournalView extends StatelessWidget {
|
|||||||
static final _timeFormat = DateFormat('Hm');
|
static final _timeFormat = DateFormat('Hm');
|
||||||
|
|
||||||
JournalView({
|
JournalView({
|
||||||
@required this.folder,
|
required this.folder,
|
||||||
@required this.noteTapped,
|
required this.noteTapped,
|
||||||
@required this.noteLongPressed,
|
required this.noteLongPressed,
|
||||||
@required this.isNoteSelected,
|
required this.isNoteSelected,
|
||||||
@required this.emptyText,
|
required this.emptyText,
|
||||||
@required this.searchTerm,
|
required this.searchTerm,
|
||||||
}) : searchTermLowerCase = searchTerm.toLowerCase();
|
}) : searchTermLowerCase = searchTerm.toLowerCase();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -48,7 +45,7 @@ class JournalView extends StatelessWidget {
|
|||||||
Widget titleWidget = Container();
|
Widget titleWidget = Container();
|
||||||
var textTheme = Theme.of(context).textTheme;
|
var textTheme = Theme.of(context).textTheme;
|
||||||
|
|
||||||
DateTime date;
|
DateTime? date;
|
||||||
var sortingField = folder.config.sortingMode.field;
|
var sortingField = folder.config.sortingMode.field;
|
||||||
if (sortingField == SortingField.Created) {
|
if (sortingField == SortingField.Created) {
|
||||||
date = note.created;
|
date = note.created;
|
||||||
@ -60,12 +57,12 @@ class JournalView extends StatelessWidget {
|
|||||||
var dateStr = _dateFormat.format(date);
|
var dateStr = _dateFormat.format(date);
|
||||||
var time = _timeFormat.format(date);
|
var time = _timeFormat.format(date);
|
||||||
|
|
||||||
var timeColor = textTheme.bodyText2.color.withAlpha(100);
|
var timeColor = textTheme.bodyText2!.color!.withAlpha(100);
|
||||||
|
|
||||||
titleWidget = Row(
|
titleWidget = Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(dateStr, style: textTheme.headline6),
|
Text(dateStr, style: textTheme.headline6),
|
||||||
Text(time, style: textTheme.bodyText2.copyWith(color: timeColor)),
|
Text(time, style: textTheme.bodyText2!.copyWith(color: timeColor)),
|
||||||
],
|
],
|
||||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||||
textBaseline: TextBaseline.alphabetic,
|
textBaseline: TextBaseline.alphabetic,
|
||||||
@ -78,7 +75,7 @@ class JournalView extends StatelessWidget {
|
|||||||
text: note.summary + '\n', // no minLines option
|
text: note.summary + '\n', // no minLines option
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: textTheme.bodyText2,
|
style: textTheme.bodyText2!,
|
||||||
highlightText: searchTerm,
|
highlightText: searchTerm,
|
||||||
highlightTextLowerCase: searchTermLowerCase,
|
highlightTextLowerCase: searchTermLowerCase,
|
||||||
),
|
),
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ -22,11 +20,11 @@ class FolderListView extends StatefulWidget {
|
|||||||
final String searchTerm;
|
final String searchTerm;
|
||||||
|
|
||||||
FolderListView({
|
FolderListView({
|
||||||
@required this.folder,
|
required this.folder,
|
||||||
@required this.noteTileBuilder,
|
required this.noteTileBuilder,
|
||||||
@required this.emptyText,
|
required this.emptyText,
|
||||||
@required this.isNoteSelected,
|
required this.isNoteSelected,
|
||||||
@required this.searchTerm,
|
required this.searchTerm,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -75,14 +73,14 @@ class _FolderListViewState extends State<FolderListView> {
|
|||||||
if (_listKey.currentState == null) {
|
if (_listKey.currentState == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_listKey.currentState.insertItem(index);
|
_listKey.currentState!.insertItem(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _noteRemoved(int index, Note note) {
|
void _noteRemoved(int index, Note note) {
|
||||||
if (_listKey.currentState == null) {
|
if (_listKey.currentState == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_listKey.currentState.removeItem(index, (context, animation) {
|
_listKey.currentState!.removeItem(index, (context, animation) {
|
||||||
var i = deletedViaDismissed.indexWhere((path) => path == note.filePath);
|
var i = deletedViaDismissed.indexWhere((path) => path == note.filePath);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
return _buildNote(note, widget.isNoteSelected(note), animation);
|
return _buildNote(note, widget.isNoteSelected(note), animation);
|
||||||
@ -152,7 +150,7 @@ class _FolderListViewState extends State<FolderListView> {
|
|||||||
viewItem = IconDismissable(
|
viewItem = IconDismissable(
|
||||||
key: ValueKey("FolderListView_" + note.filePath),
|
key: ValueKey("FolderListView_" + note.filePath),
|
||||||
child: viewItem,
|
child: viewItem,
|
||||||
backgroundColor: Colors.red[800],
|
backgroundColor: Colors.red[800]!,
|
||||||
iconData: Icons.delete,
|
iconData: Icons.delete,
|
||||||
onDismissed: (direction) {
|
onDismissed: (direction) {
|
||||||
deletedViaDismissed.add(note.filePath);
|
deletedViaDismissed.add(note.filePath);
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -17,11 +15,11 @@ class NoteTile extends StatelessWidget {
|
|||||||
final String searchTermLowerCase;
|
final String searchTermLowerCase;
|
||||||
|
|
||||||
NoteTile({
|
NoteTile({
|
||||||
@required this.note,
|
required this.note,
|
||||||
@required this.noteTapped,
|
required this.noteTapped,
|
||||||
@required this.noteLongPressed,
|
required this.noteLongPressed,
|
||||||
@required this.selected,
|
required this.selected,
|
||||||
@required this.searchTerm,
|
required this.searchTerm,
|
||||||
}) : searchTermLowerCase = searchTerm.toLowerCase();
|
}) : searchTermLowerCase = searchTerm.toLowerCase();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -47,18 +45,17 @@ class NoteTile extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
if (note.title != null && note.title.isNotEmpty)
|
if (note.title.isNotEmpty)
|
||||||
HighlightedText(
|
HighlightedText(
|
||||||
text: note.title,
|
text: note.title,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: textTheme.headline6
|
style: textTheme.headline6!
|
||||||
.copyWith(fontSize: textTheme.headline6.fontSize * 0.80),
|
.copyWith(fontSize: textTheme.headline6!.fontSize! * 0.80),
|
||||||
highlightText: searchTerm,
|
highlightText: searchTerm,
|
||||||
highlightTextLowerCase: searchTermLowerCase,
|
highlightTextLowerCase: searchTermLowerCase,
|
||||||
),
|
),
|
||||||
if (note.title != null && note.title.isNotEmpty)
|
if (note.title.isNotEmpty) const SizedBox(height: 8.0),
|
||||||
const SizedBox(height: 8.0),
|
|
||||||
Flexible(
|
Flexible(
|
||||||
flex: 1,
|
flex: 1,
|
||||||
child: _buildBody(context, body),
|
child: _buildBody(context, body),
|
||||||
@ -117,8 +114,8 @@ class NoteTile extends StatelessWidget {
|
|||||||
text: text,
|
text: text,
|
||||||
highlightText: searchTerm,
|
highlightText: searchTerm,
|
||||||
highlightTextLowerCase: searchTermLowerCase,
|
highlightTextLowerCase: searchTermLowerCase,
|
||||||
style: textTheme.subtitle1
|
style: textTheme.subtitle1!
|
||||||
.copyWith(fontSize: textTheme.subtitle1.fontSize * 0.90),
|
.copyWith(fontSize: textTheme.subtitle1!.fontSize! * 0.90),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
maxLines: _maxLines - 1,
|
maxLines: _maxLines - 1,
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
@ -34,14 +31,14 @@ class StandardView extends StatelessWidget {
|
|||||||
static final _dateFormat = DateFormat('dd MMM, yyyy');
|
static final _dateFormat = DateFormat('dd MMM, yyyy');
|
||||||
|
|
||||||
StandardView({
|
StandardView({
|
||||||
@required this.folder,
|
required this.folder,
|
||||||
@required this.noteTapped,
|
required this.noteTapped,
|
||||||
@required this.noteLongPressed,
|
required this.noteLongPressed,
|
||||||
@required this.emptyText,
|
required this.emptyText,
|
||||||
@required this.headerType,
|
required this.headerType,
|
||||||
@required this.showSummary,
|
required this.showSummary,
|
||||||
@required this.isNoteSelected,
|
required this.isNoteSelected,
|
||||||
@required this.searchTerm,
|
required this.searchTerm,
|
||||||
}) : searchTermLowerCase = searchTerm.toLowerCase();
|
}) : searchTermLowerCase = searchTerm.toLowerCase();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -62,7 +59,7 @@ class StandardView extends StatelessWidget {
|
|||||||
switch (headerType) {
|
switch (headerType) {
|
||||||
case StandardViewHeader.TitleOrFileName:
|
case StandardViewHeader.TitleOrFileName:
|
||||||
title = note.title;
|
title = note.title;
|
||||||
if (title == null || title.isEmpty) {
|
if (title.isEmpty) {
|
||||||
title = note.fileName;
|
title = note.fileName;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -73,25 +70,22 @@ class StandardView extends StatelessWidget {
|
|||||||
|
|
||||||
case StandardViewHeader.TitleGenerated:
|
case StandardViewHeader.TitleGenerated:
|
||||||
title = note.title;
|
title = note.title;
|
||||||
if (title == null || title.isEmpty) {
|
if (title.isEmpty) {
|
||||||
title = note.summary;
|
title = note.summary;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false, "StandardViewHeader must not be null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget titleWidget = HighlightedText(
|
Widget titleWidget = HighlightedText(
|
||||||
text: title,
|
text: title,
|
||||||
style: textTheme.headline6,
|
style: textTheme.headline6!,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
highlightText: searchTerm,
|
highlightText: searchTerm,
|
||||||
highlightTextLowerCase: searchTermLowerCase,
|
highlightTextLowerCase: searchTermLowerCase,
|
||||||
);
|
);
|
||||||
Widget trailing = Container();
|
Widget trailing = Container();
|
||||||
|
|
||||||
DateTime date;
|
DateTime? date;
|
||||||
var sortingField = folder.config.sortingMode.field;
|
var sortingField = folder.config.sortingMode.field;
|
||||||
if (sortingField == SortingField.Modified) {
|
if (sortingField == SortingField.Modified) {
|
||||||
date = note.modified;
|
date = note.modified;
|
||||||
@ -119,7 +113,7 @@ class StandardView extends StatelessWidget {
|
|||||||
text: note.summary + '\n', // no minLines option
|
text: note.summary + '\n', // no minLines option
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: textTheme.bodyText2,
|
style: textTheme.bodyText2!,
|
||||||
highlightText: searchTerm,
|
highlightText: searchTerm,
|
||||||
highlightTextLowerCase: searchTermLowerCase,
|
highlightTextLowerCase: searchTermLowerCase,
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user