mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 09:06:43 +08:00
Null Safety++
This is exhausting
This commit is contained in:
53
lib/app.dart
53
lib/app.dart
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
@ -116,7 +114,7 @@ class JournalApp extends StatefulWidget {
|
|||||||
Log.i("Running on ios", props: readIosDeviceInfo(info));
|
Log.i("Running on ios", props: readIosDeviceInfo(info));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.d(e);
|
Log.d(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPhysicalDevice == false) {
|
if (isPhysicalDevice == false) {
|
||||||
@ -176,11 +174,11 @@ class JournalApp extends StatefulWidget {
|
|||||||
|
|
||||||
class _JournalAppState extends State<JournalApp> {
|
class _JournalAppState extends State<JournalApp> {
|
||||||
final _navigatorKey = GlobalKey<NavigatorState>();
|
final _navigatorKey = GlobalKey<NavigatorState>();
|
||||||
String _pendingShortcut;
|
String? _pendingShortcut;
|
||||||
|
|
||||||
StreamSubscription _intentDataStreamSubscription;
|
StreamSubscription? _intentDataStreamSubscription;
|
||||||
String _sharedText;
|
var _sharedText = "";
|
||||||
List<String> _sharedImages;
|
var _sharedImages = <String>[];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -195,14 +193,14 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
Log.i("Quick Action Open: $shortcutType");
|
Log.i("Quick Action Open: $shortcutType");
|
||||||
if (_navigatorKey.currentState == null) {
|
if (_navigatorKey.currentState == null) {
|
||||||
Log.i("Quick Action delegating for after build");
|
Log.i("Quick Action delegating for after build");
|
||||||
WidgetsBinding.instance
|
WidgetsBinding.instance!
|
||||||
.addPostFrameCallback((_) => _afterBuild(context));
|
.addPostFrameCallback((_) => _afterBuild(context));
|
||||||
setState(() {
|
setState(() {
|
||||||
_pendingShortcut = shortcutType;
|
_pendingShortcut = shortcutType;
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_navigatorKey.currentState.pushNamed("/newNote/$shortcutType");
|
_navigatorKey.currentState!.pushNamed("/newNote/$shortcutType");
|
||||||
});
|
});
|
||||||
|
|
||||||
quickActions.setShortcutItems(<ShortcutItem>[
|
quickActions.setShortcutItems(<ShortcutItem>[
|
||||||
@ -228,7 +226,7 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
|
|
||||||
void _afterBuild(BuildContext context) {
|
void _afterBuild(BuildContext context) {
|
||||||
if (_pendingShortcut != null) {
|
if (_pendingShortcut != null) {
|
||||||
_navigatorKey.currentState.pushNamed("/newNote/$_pendingShortcut");
|
_navigatorKey.currentState!.pushNamed("/newNote/$_pendingShortcut");
|
||||||
_pendingShortcut = null;
|
_pendingShortcut = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,36 +237,34 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var handleShare = () {
|
var handleShare = () {
|
||||||
var noText = _sharedText == null || _sharedText.isEmpty;
|
var noText = _sharedText.isEmpty;
|
||||||
var noImages = _sharedImages == null || _sharedImages.isEmpty;
|
var noImages = _sharedImages.isEmpty;
|
||||||
if (noText && noImages) {
|
if (noText && noImages) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var settings = Provider.of<Settings>(context, listen: false);
|
||||||
var editor = settings.defaultEditor.toInternalString();
|
var editor = settings.defaultEditor.toInternalString();
|
||||||
_navigatorKey.currentState.pushNamed("/newNote/$editor");
|
_navigatorKey.currentState!.pushNamed("/newNote/$editor");
|
||||||
};
|
};
|
||||||
|
|
||||||
// For sharing images coming from outside the app while the app is in the memory
|
// For sharing images coming from outside the app while the app is in the memory
|
||||||
_intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream()
|
_intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream()
|
||||||
.listen((List<SharedMediaFile> value) {
|
.listen((List<SharedMediaFile> value) {
|
||||||
if (value == null) return;
|
|
||||||
Log.d("Received Share $value");
|
Log.d("Received Share $value");
|
||||||
|
|
||||||
_sharedImages = value.map((f) => f.path)?.toList();
|
_sharedImages = value.map((f) => f.path).toList();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => handleShare());
|
WidgetsBinding.instance!.addPostFrameCallback((_) => handleShare());
|
||||||
}, onError: (err) {
|
}, onError: (err) {
|
||||||
Log.e("getIntentDataStream error: $err");
|
Log.e("getIntentDataStream error: $err");
|
||||||
});
|
});
|
||||||
|
|
||||||
// For sharing images coming from outside the app while the app is closed
|
// For sharing images coming from outside the app while the app is closed
|
||||||
ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
|
ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
|
||||||
if (value == null) return;
|
|
||||||
Log.d("Received Share with App (media): $value");
|
Log.d("Received Share with App (media): $value");
|
||||||
|
|
||||||
_sharedImages = value.map((f) => f.path)?.toList();
|
_sharedImages = value.map((f) => f.path).toList();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => handleShare());
|
WidgetsBinding.instance!.addPostFrameCallback((_) => handleShare());
|
||||||
});
|
});
|
||||||
|
|
||||||
// For sharing or opening text coming from outside the app while the app is in the memory
|
// For sharing or opening text coming from outside the app while the app is in the memory
|
||||||
@ -276,22 +272,23 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
ReceiveSharingIntent.getTextStream().listen((String value) {
|
ReceiveSharingIntent.getTextStream().listen((String value) {
|
||||||
Log.d("Received Share $value");
|
Log.d("Received Share $value");
|
||||||
_sharedText = value;
|
_sharedText = value;
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => handleShare());
|
WidgetsBinding.instance!.addPostFrameCallback((_) => handleShare());
|
||||||
}, onError: (err) {
|
}, onError: (err) {
|
||||||
Log.e("getLinkStream error: $err");
|
Log.e("getLinkStream error: $err");
|
||||||
});
|
});
|
||||||
|
|
||||||
// For sharing or opening text coming from outside the app while the app is closed
|
// For sharing or opening text coming from outside the app while the app is closed
|
||||||
ReceiveSharingIntent.getInitialText().then((String value) {
|
ReceiveSharingIntent.getInitialText().then((String? value) {
|
||||||
|
if (value == null) return;
|
||||||
Log.d("Received Share with App (text): $value");
|
Log.d("Received Share with App (text): $value");
|
||||||
_sharedText = value;
|
_sharedText = value;
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => handleShare());
|
WidgetsBinding.instance!.addPostFrameCallback((_) => handleShare());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_intentDataStreamSubscription.cancel();
|
_intentDataStreamSubscription?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,9 +323,9 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
navigatorKey: _navigatorKey,
|
navigatorKey: _navigatorKey,
|
||||||
title: 'GitJournal',
|
title: 'GitJournal',
|
||||||
|
|
||||||
localizationsDelegates: EasyLocalization.of(context).delegates,
|
localizationsDelegates: EasyLocalization.of(context)!.delegates,
|
||||||
supportedLocales: EasyLocalization.of(context).supportedLocales,
|
supportedLocales: EasyLocalization.of(context)!.supportedLocales,
|
||||||
locale: EasyLocalization.of(context).locale,
|
locale: EasyLocalization.of(context)!.locale,
|
||||||
|
|
||||||
theme: Themes.light,
|
theme: Themes.light,
|
||||||
darkTheme: Themes.dark,
|
darkTheme: Themes.dark,
|
||||||
@ -344,8 +341,8 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
onGenerateRoute: (rs) {
|
onGenerateRoute: (rs) {
|
||||||
var r = router
|
var r = router
|
||||||
.generateRoute(rs, stateContainer, _sharedText, _sharedImages, () {
|
.generateRoute(rs, stateContainer, _sharedText, _sharedImages, () {
|
||||||
_sharedText = null;
|
_sharedText = "";
|
||||||
_sharedImages = null;
|
_sharedImages = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
@ -56,7 +54,7 @@ class AppRouter {
|
|||||||
final AppSettings appSettings;
|
final AppSettings appSettings;
|
||||||
final Settings settings;
|
final Settings settings;
|
||||||
|
|
||||||
AppRouter({@required this.appSettings, @required this.settings});
|
AppRouter({required this.appSettings, required this.settings});
|
||||||
|
|
||||||
String initialRoute() {
|
String initialRoute() {
|
||||||
var route = '/';
|
var route = '/';
|
||||||
@ -76,7 +74,7 @@ class AppRouter {
|
|||||||
List<String> sharedImages,
|
List<String> sharedImages,
|
||||||
Function callbackIfUsedShared,
|
Function callbackIfUsedShared,
|
||||||
) {
|
) {
|
||||||
var route = routeSettings.name;
|
var route = routeSettings.name ?? "";
|
||||||
if (route == AppRoute.AllFolders ||
|
if (route == AppRoute.AllFolders ||
|
||||||
route == AppRoute.AllTags ||
|
route == AppRoute.AllTags ||
|
||||||
route == AppRoute.FileSystem) {
|
route == AppRoute.FileSystem) {
|
||||||
@ -89,7 +87,7 @@ class AppRouter {
|
|||||||
sharedText,
|
sharedText,
|
||||||
sharedImages,
|
sharedImages,
|
||||||
callbackIfUsedShared,
|
callbackIfUsedShared,
|
||||||
),
|
)!,
|
||||||
transitionsBuilder: (_, anim, __, child) {
|
transitionsBuilder: (_, anim, __, child) {
|
||||||
return FadeTransition(opacity: anim, child: child);
|
return FadeTransition(opacity: anim, child: child);
|
||||||
},
|
},
|
||||||
@ -105,11 +103,11 @@ class AppRouter {
|
|||||||
sharedText,
|
sharedText,
|
||||||
sharedImages,
|
sharedImages,
|
||||||
callbackIfUsedShared,
|
callbackIfUsedShared,
|
||||||
),
|
)!,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget screenForRoute(
|
Widget? screenForRoute(
|
||||||
String route,
|
String route,
|
||||||
GitJournalRepo repository,
|
GitJournalRepo repository,
|
||||||
Settings settings,
|
Settings settings,
|
||||||
|
@ -56,10 +56,10 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
int numChanges = 0;
|
int numChanges = 0;
|
||||||
|
|
||||||
bool get hasJournalEntries {
|
bool get hasJournalEntries {
|
||||||
return notesFolder!.hasNotes;
|
return notesFolder.hasNotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
NotesFolderFS? notesFolder;
|
late NotesFolderFS notesFolder;
|
||||||
|
|
||||||
bool remoteGitRepoConfigured = false;
|
bool remoteGitRepoConfigured = false;
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _loadFromCache() async {
|
void _loadFromCache() async {
|
||||||
await _notesCache.load(notesFolder!);
|
await _notesCache.load(notesFolder);
|
||||||
Log.i("Finished loading the notes cache");
|
Log.i("Finished loading the notes cache");
|
||||||
|
|
||||||
await _loadNotes();
|
await _loadNotes();
|
||||||
@ -179,8 +179,8 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
Future<void> _loadNotes() async {
|
Future<void> _loadNotes() async {
|
||||||
// FIXME: We should report the notes that failed to load
|
// FIXME: We should report the notes that failed to load
|
||||||
return _loadLock.synchronized(() async {
|
return _loadLock.synchronized(() async {
|
||||||
await notesFolder!.loadRecursively();
|
await notesFolder.loadRecursively();
|
||||||
await _notesCache.buildCache(notesFolder!);
|
await _notesCache.buildCache(notesFolder);
|
||||||
|
|
||||||
var changes = await _gitRepo.numChanges();
|
var changes = await _gitRepo.numChanges();
|
||||||
numChanges = changes != null ? changes : 0;
|
numChanges = changes != null ? changes : 0;
|
||||||
@ -448,7 +448,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
|
|
||||||
_notesCache.clear();
|
_notesCache.clear();
|
||||||
remoteGitRepoConfigured = true;
|
remoteGitRepoConfigured = true;
|
||||||
notesFolder!.reset(repoPath);
|
notesFolder.reset(repoPath);
|
||||||
|
|
||||||
settings.folderName = repoFolderName;
|
settings.folderName = repoFolderName;
|
||||||
settings.save();
|
settings.save();
|
||||||
@ -483,7 +483,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
||||||
|
|
||||||
_notesCache.clear();
|
_notesCache.clear();
|
||||||
notesFolder!.reset(repoPath);
|
notesFolder.reset(repoPath);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
_loadNotes();
|
_loadNotes();
|
||||||
@ -531,7 +531,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
print("Done checking out $branchName");
|
print("Done checking out $branchName");
|
||||||
|
|
||||||
await _notesCache.clear();
|
await _notesCache.clear();
|
||||||
notesFolder!.reset(repoPath);
|
notesFolder.reset(repoPath);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
_loadNotes();
|
_loadNotes();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -15,16 +13,16 @@ class RepositoryManager with ChangeNotifier {
|
|||||||
var repoIds = <String>[];
|
var repoIds = <String>[];
|
||||||
var currentId = DEFAULT_ID;
|
var currentId = DEFAULT_ID;
|
||||||
|
|
||||||
GitJournalRepo _repo;
|
late GitJournalRepo _repo;
|
||||||
|
|
||||||
final String gitBaseDir;
|
final String gitBaseDir;
|
||||||
final String cacheDir;
|
final String cacheDir;
|
||||||
final SharedPreferences pref;
|
final SharedPreferences pref;
|
||||||
|
|
||||||
RepositoryManager({
|
RepositoryManager({
|
||||||
@required this.gitBaseDir,
|
required this.gitBaseDir,
|
||||||
@required this.cacheDir,
|
required this.cacheDir,
|
||||||
@required this.pref,
|
required this.pref,
|
||||||
}) {
|
}) {
|
||||||
_load();
|
_load();
|
||||||
Log.i("Repo Ids $repoIds");
|
Log.i("Repo Ids $repoIds");
|
||||||
|
@ -49,8 +49,8 @@ import 'package:gitjournal/widgets/rename_dialog.dart';
|
|||||||
class ShowUndoSnackbar {}
|
class ShowUndoSnackbar {}
|
||||||
|
|
||||||
class NoteEditor extends StatefulWidget {
|
class NoteEditor extends StatefulWidget {
|
||||||
final Note note;
|
final Note/*!*/ note;
|
||||||
final NotesFolderFS notesFolder;
|
final NotesFolderFS/*!*/ notesFolder;
|
||||||
final NotesFolder parentFolderView;
|
final NotesFolder parentFolderView;
|
||||||
final EditorType defaultEditorType;
|
final EditorType defaultEditorType;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user