From 8c326399bd253a33fd49ddc7a3f4528ee18614a4 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Tue, 25 May 2021 16:33:48 +0200 Subject: [PATCH] null safety++ --- lib/screens/folder_listing.dart | 28 +++++++-------- lib/screens/onboarding_screens.dart | 10 +++--- lib/setup/loading_error.dart | 12 +++---- lib/setup/sshkey.dart | 54 ++++++++++++++--------------- lib/widgets/note_viewer.dart | 8 ++--- 5 files changed, 51 insertions(+), 61 deletions(-) diff --git a/lib/screens/folder_listing.dart b/lib/screens/folder_listing.dart index 337a3a12..deaef1cb 100644 --- a/lib/screens/folder_listing.dart +++ b/lib/screens/folder_listing.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - /* Copyright 2020-2021 Vishesh Handa @@ -38,7 +36,7 @@ class FolderListingScreen extends StatefulWidget { class _FolderListingScreenState extends State { final _folderTreeViewKey = GlobalKey(); - NotesFolderFS selectedFolder; + NotesFolderFS? selectedFolder; @override Widget build(BuildContext context) { @@ -78,7 +76,7 @@ class _FolderListingScreenState extends State { }, ); - Widget action; + Widget? action; if (selectedFolder != null) { action = PopupMenuButton( itemBuilder: (context) { @@ -99,25 +97,25 @@ class _FolderListingScreenState extends State { }, onSelected: (String value) async { if (value == "Rename") { - if (selectedFolder.pathSpec().isEmpty) { + if (selectedFolder!.pathSpec().isEmpty) { await showDialog( context: context, builder: (_) => RenameFolderErrorDialog(), ); - _folderTreeViewKey.currentState.resetSelection(); + _folderTreeViewKey.currentState!.resetSelection(); return; } var folderName = await showDialog( context: context, builder: (_) => RenameDialog( - oldPath: selectedFolder.folderPath, + oldPath: selectedFolder!.folderPath, inputDecoration: tr("screens.folders.actions.decoration"), dialogTitle: tr("screens.folders.actions.rename"), ), ); if (folderName is String) { var container = context.read(); - container.renameFolder(selectedFolder, folderName); + container.renameFolder(selectedFolder!, folderName); } } else if (value == "Create") { var folderName = await showDialog( @@ -126,21 +124,21 @@ class _FolderListingScreenState extends State { ); if (folderName is String) { var container = context.read(); - container.createFolder(selectedFolder, folderName); + container.createFolder(selectedFolder!, folderName); } } else if (value == "Delete") { - if (selectedFolder.hasNotesRecursive) { + if (selectedFolder!.hasNotesRecursive) { await showDialog( context: context, builder: (_) => DeleteFolderErrorDialog(), ); } else { var container = context.read(); - container.removeFolder(selectedFolder); + container.removeFolder(selectedFolder!); } } - _folderTreeViewKey.currentState.resetSelection(); + _folderTreeViewKey.currentState!.resetSelection(); }, ); } @@ -148,7 +146,7 @@ class _FolderListingScreenState extends State { var backButton = IconButton( icon: const Icon(Icons.arrow_back), onPressed: () { - _folderTreeViewKey.currentState.resetSelection(); + _folderTreeViewKey.currentState!.resetSelection(); }, ); @@ -162,7 +160,7 @@ class _FolderListingScreenState extends State { title: title, leading: selectedFolder == null ? GJAppBarMenuButton() : backButton, actions: [ - if (selectedFolder != null) action, + if (selectedFolder != null) action!, ], ), body: Scrollbar(child: treeView), @@ -215,7 +213,7 @@ class _CreateFolderAlertDialogState extends State { labelText: tr("screens.folders.actions.decoration"), ), validator: (value) { - if (value.isEmpty) return tr("screens.folders.actions.empty"); + if (value!.isEmpty) return tr("screens.folders.actions.empty"); return ""; }, autofocus: true, diff --git a/lib/screens/onboarding_screens.dart b/lib/screens/onboarding_screens.dart index 88ec1cbb..2ed32452 100644 --- a/lib/screens/onboarding_screens.dart +++ b/lib/screens/onboarding_screens.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:flutter/material.dart'; import 'package:auto_size_text/auto_size_text.dart'; @@ -153,9 +151,9 @@ class OnBoardingBottomButton extends StatelessWidget { final String text; OnBoardingBottomButton({ - Key key, - @required this.text, - @required this.onPressed, + Key? key, + required this.text, + required this.onPressed, }) : super(key: key); @override @@ -177,7 +175,7 @@ class OnBoardingPage1 extends StatelessWidget { @override Widget build(BuildContext context) { var textTheme = Theme.of(context).textTheme; - var headerTextStyle = textTheme.headline2.copyWith(fontFamily: "Lato"); + var headerTextStyle = textTheme.headline2!.copyWith(fontFamily: "Lato"); var header = Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, diff --git a/lib/setup/loading_error.dart b/lib/setup/loading_error.dart index 00e5e3c8..fb609161 100644 --- a/lib/setup/loading_error.dart +++ b/lib/setup/loading_error.dart @@ -1,25 +1,23 @@ -// @dart=2.9 - import 'package:flutter/material.dart'; import 'error.dart'; import 'loading.dart'; class GitHostSetupLoadingErrorPage extends StatelessWidget { - final String errorMessage; + final String? errorMessage; final String loadingMessage; GitHostSetupLoadingErrorPage({ - @required this.errorMessage, - @required this.loadingMessage, + required this.errorMessage, + required this.loadingMessage, }); @override Widget build(BuildContext context) { - if (errorMessage == null || errorMessage.isEmpty) { + if (errorMessage == null || errorMessage!.isEmpty) { return GitHostSetupLoadingPage(loadingMessage); } - return GitHostSetupErrorPage(errorMessage); + return GitHostSetupErrorPage(errorMessage!); } } diff --git a/lib/setup/sshkey.dart b/lib/setup/sshkey.dart index cee9c4b6..b4195969 100644 --- a/lib/setup/sshkey.dart +++ b/lib/setup/sshkey.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:flutter/material.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -13,21 +11,21 @@ class GitHostSetupSshKeyKnownProvider extends StatelessWidget { final Func0 doneFunction; final Func0 regenerateFunction; final Func1 copyKeyFunction; - final String publicKey; + final String? publicKey; final Func0 openDeployKeyPage; GitHostSetupSshKeyKnownProvider({ - @required this.doneFunction, - @required this.regenerateFunction, - @required this.copyKeyFunction, - @required this.openDeployKeyPage, - @required this.publicKey, + required this.doneFunction, + required this.regenerateFunction, + required this.copyKeyFunction, + required this.openDeployKeyPage, + required this.publicKey, }); @override Widget build(BuildContext context) { - if (publicKey == null || publicKey.isEmpty) { + if (publicKey == null || publicKey!.isEmpty) { return GitHostSetupLoadingPage(tr("setup.sshKey.generate")); } @@ -47,7 +45,7 @@ class GitHostSetupSshKeyKnownProvider extends StatelessWidget { style: Theme.of(context).textTheme.subtitle2, ), const SizedBox(height: 8.0), - PublicKeyWidget(publicKey), + PublicKeyWidget(publicKey!), const SizedBox(height: 8.0), GitHostSetupButton( @@ -97,18 +95,18 @@ class GitHostSetupSshKeyUnknownProvider extends StatelessWidget { final Func0 doneFunction; final Func0 regenerateFunction; final Func1 copyKeyFunction; - final String publicKey; + final String? publicKey; GitHostSetupSshKeyUnknownProvider({ - @required this.doneFunction, - @required this.regenerateFunction, - @required this.copyKeyFunction, - @required this.publicKey, + required this.doneFunction, + required this.regenerateFunction, + required this.copyKeyFunction, + required this.publicKey, }); @override Widget build(BuildContext context) { - if (publicKey == null || publicKey.isEmpty) { + if (publicKey == null || publicKey!.isEmpty) { return GitHostSetupLoadingPage(tr("setup.sshKey.generate")); } @@ -128,7 +126,7 @@ class GitHostSetupSshKeyUnknownProvider extends StatelessWidget { style: Theme.of(context).textTheme.subtitle2, ), const SizedBox(height: 8.0), - PublicKeyWidget(publicKey), + PublicKeyWidget(publicKey!), const SizedBox(height: 8.0), GitHostSetupButton( @@ -174,8 +172,8 @@ class GitHostSetupKeyChoice extends StatelessWidget { final Func0 onUserProvidedKeys; GitHostSetupKeyChoice({ - @required this.onGenerateKeys, - @required this.onUserProvidedKeys, + required this.onGenerateKeys, + required this.onUserProvidedKeys, }); @override @@ -211,7 +209,7 @@ class GitHostUserProvidedKeys extends StatefulWidget { final String saveText; GitHostUserProvidedKeys({ - @required this.doneFunction, + required this.doneFunction, this.saveText = "", }); @@ -221,13 +219,13 @@ class GitHostUserProvidedKeys extends StatefulWidget { } class _GitHostUserProvidedKeysState extends State { - GlobalKey _publicFormKey; - GlobalKey _privateFormKey; - TextEditingController _publicKeyController; - TextEditingController _privateKeyController; - TextEditingController _passwordController; + late GlobalKey _publicFormKey; + late GlobalKey _privateFormKey; + late TextEditingController _publicKeyController; + late TextEditingController _privateKeyController; + late TextEditingController _passwordController; - String saveText; + late String saveText; @override void initState() { @@ -282,8 +280,8 @@ class _GitHostUserProvidedKeysState extends State { GitHostSetupButton( text: saveText, onPressed: () { - var publicValid = _publicFormKey.currentState.validate(); - var privateValid = _privateFormKey.currentState.validate(); + var publicValid = _publicFormKey.currentState!.validate(); + var privateValid = _privateFormKey.currentState!.validate(); if (!publicValid || !privateValid) { return; diff --git a/lib/widgets/note_viewer.dart b/lib/widgets/note_viewer.dart index f36e9463..577e33d8 100644 --- a/lib/widgets/note_viewer.dart +++ b/lib/widgets/note_viewer.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -17,9 +15,9 @@ class NoteViewer extends StatelessWidget { final Note note; final NotesFolder parentFolder; const NoteViewer({ - Key key, - @required this.note, - @required this.parentFolder, + Key? key, + required this.note, + required this.parentFolder, }) : super(key: key); @override