From 7d4952655c671d432a08a256bd16dcf474d15a94 Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Fri, 26 Mar 2021 14:58:39 +0100 Subject: [PATCH] Remove prints This close #108 and adds a rule to the analyzer that this problems can no longer occur. Also, remove unnecessary catches and catches where the exceptions occur in the user code and therefore should be handled by the user instead of being swallowed by this library. --- analysis_options.yaml | 5 ++- lib/models/rules/rule.dart | 1 - lib/widgets/controller.dart | 36 +++++++------------ lib/widgets/toolbar.dart | 69 +++++++++++-------------------------- 4 files changed, 37 insertions(+), 74 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 4679e597..57f3028e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -4,4 +4,7 @@ analyzer: errors: undefined_prefixed_name: ignore omit_local_variable_types: ignore - unsafe_html: ignore \ No newline at end of file + unsafe_html: ignore +linter: + rules: + - avoid_print diff --git a/lib/models/rules/rule.dart b/lib/models/rules/rule.dart index da83797b..bff58b44 100644 --- a/lib/models/rules/rule.dart +++ b/lib/models/rules/rule.dart @@ -61,7 +61,6 @@ class Rules { final result = rule.apply(delta, index, len: len, data: data, attribute: attribute); if (result != null) { - print('Rule $rule applied'); return result..trim(); } } catch (e) { diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index d36a73b5..29206059 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -78,12 +78,7 @@ class QuillController extends ChangeNotifier { Delta? delta; if (len > 0 || data is! String || data.isNotEmpty) { - try { - delta = document.replace(index, len, data); - } catch (e) { - print('document.replace failed: $e'); - rethrow; - } + delta = document.replace(index, len, data); bool shouldRetainDelta = toggledStyle.isNotEmpty && delta.isNotEmpty && delta.length <= 2 && @@ -112,23 +107,18 @@ class QuillController extends ChangeNotifier { if (delta == null || delta.isEmpty) { _updateSelection(textSelection, ChangeSource.LOCAL); } else { - try { - Delta user = Delta() - ..retain(index) - ..insert(data) - ..delete(len); - int positionDelta = getPositionDelta(user, delta); - _updateSelection( - textSelection.copyWith( - baseOffset: textSelection.baseOffset + positionDelta, - extentOffset: textSelection.extentOffset + positionDelta, - ), - ChangeSource.LOCAL, - ); - } catch (e) { - print('getPositionDelta or getPositionDelta error: $e'); - rethrow; - } + Delta user = Delta() + ..retain(index) + ..insert(data) + ..delete(len); + int positionDelta = getPositionDelta(user, delta); + _updateSelection( + textSelection.copyWith( + baseOffset: textSelection.baseOffset + positionDelta, + extentOffset: textSelection.extentOffset + positionDelta, + ), + ChangeSource.LOCAL, + ); } } notifyListeners(); diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 3a6a72b5..cb23a19e 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -4,7 +4,6 @@ import 'package:file_picker/file_picker.dart'; import 'package:filesystem_picker/filesystem_picker.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import 'package:flutter_quill/models/documents/attribute.dart'; import 'package:flutter_quill/models/documents/nodes/embed.dart'; @@ -520,46 +519,25 @@ class _ImageButtonState extends State { final File file = File(pickedFile.path); - // We simply return the absolute path to selected file. - try { - String url = await widget.onImagePickCallback!(file); - print('Image uploaded and its url is $url'); - return url; - } catch (error) { - print('Upload image error $error'); - } - return null; + return widget.onImagePickCallback!(file); } Future _pickImageWeb() async { - try { - _paths = (await FilePicker.platform.pickFiles( - type: _pickingType, - allowMultiple: false, - allowedExtensions: (_extension?.isNotEmpty ?? false) - ? _extension?.replaceAll(' ', '').split(',') - : null, - )) - ?.files; - } on PlatformException catch (e) { - print('Unsupported operation' + e.toString()); - } catch (ex) { - print(ex); - } + _paths = (await FilePicker.platform.pickFiles( + type: _pickingType, + allowMultiple: false, + allowedExtensions: (_extension?.isNotEmpty ?? false) + ? _extension?.replaceAll(' ', '').split(',') + : null, + )) + ?.files; var _fileName = _paths != null ? _paths!.map((e) => e.name).toString() : '...'; if (_paths != null) { File file = File(_fileName); // We simply return the absolute path to selected file. - try { - String url = await widget.onImagePickCallback!(file); - print('Image uploaded and its url is $url'); - return url; - } catch (error) { - print('Upload image error $error'); - } - return null; + return widget.onImagePickCallback!(file); } else { // User canceled the picker } @@ -567,23 +545,16 @@ class _ImageButtonState extends State { } Future _pickImageDesktop() async { - try { - var filePath = await FilesystemPicker.open( - context: context, - rootDirectory: await getApplicationDocumentsDirectory(), - fsType: FilesystemType.file, - fileTileSelectMode: FileTileSelectMode.wholeTile, - ); - if (filePath != null && filePath.isEmpty) return ''; - - final File file = File(filePath!); - String url = await widget.onImagePickCallback!(file); - print('Image uploaded and its url is $url'); - return url; - } catch (error) { - print('Upload image error $error'); - } - return ''; + var filePath = await FilesystemPicker.open( + context: context, + rootDirectory: await getApplicationDocumentsDirectory(), + fsType: FilesystemType.file, + fileTileSelectMode: FileTileSelectMode.wholeTile, + ); + if (filePath != null && filePath.isEmpty) return ''; + + final File file = File(filePath!); + return widget.onImagePickCallback!(file); } @override