From 811cb341bf25e17291ee9512be800da2bbea9c80 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 24 Mar 2021 23:48:23 -0700 Subject: [PATCH] Add pedantic --- CHANGELOG.md | 3 ++ analysis_options.yaml | 2 + example/main.dart | 2 +- lib/models/documents/document.dart | 6 +-- lib/models/documents/history.dart | 16 +++--- lib/models/documents/nodes/block.dart | 2 +- lib/utils/universal_ui/fake_ui.dart | 2 +- lib/utils/universal_ui/real_ui.dart | 4 +- lib/utils/universal_ui/universal_ui.dart | 5 +- lib/widgets/text_line.dart | 6 +-- lib/widgets/text_selection.dart | 55 ++++++++++---------- lib/widgets/toolbar.dart | 66 ++++++++++++------------ pubspec.yaml | 5 +- 13 files changed, 89 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03fbb31d..61e2cf0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.1.2] +* Add pedantic. + ## [1.1.1] * Base64 image support. diff --git a/analysis_options.yaml b/analysis_options.yaml index cb1ea33c..98c97294 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,5 @@ +include: package:pedantic/analysis_options.yaml + analyzer: errors: undefined_prefixed_name: ignore \ No newline at end of file diff --git a/example/main.dart b/example/main.dart index a523c5a6..1b31b0bb 100644 --- a/example/main.dart +++ b/example/main.dart @@ -9,7 +9,7 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - QuillController _controller = QuillController.basic(); + final QuillController _controller = QuillController.basic(); @override Widget build(BuildContext context) { diff --git a/lib/models/documents/document.dart b/lib/models/documents/document.dart index 38813510..2e715f3f 100644 --- a/lib/models/documents/document.dart +++ b/lib/models/documents/document.dart @@ -117,7 +117,7 @@ class Document { return block.queryChild(res.offset, true); } - compose(Delta delta, ChangeSource changeSource) { + void compose(Delta delta, ChangeSource changeSource) { assert(!_observer.isClosed); delta.trim(); assert(delta.isNotEmpty); @@ -208,14 +208,14 @@ class Document { return Embeddable.fromJson(data as Map); } - close() { + void close() { _observer.close(); _history.clear(); } String toPlainText() => _root.children.map((e) => e.toPlainText()).join(''); - _loadDocument(Delta doc) { + void _loadDocument(Delta doc) { assert((doc.last.data as String).endsWith('\n')); int offset = 0; for (final op in doc.toList()) { diff --git a/lib/models/documents/history.dart b/lib/models/documents/history.dart index 1bb92105..99798d71 100644 --- a/lib/models/documents/history.dart +++ b/lib/models/documents/history.dart @@ -69,8 +69,8 @@ class History { ///It will override pre local undo delta,replaced by remote change /// void transform(Delta delta) { - transformStack(this.stack.undo, delta); - transformStack(this.stack.redo, delta); + transformStack(stack.undo, delta); + transformStack(stack.redo, delta); } void transformStack(List stack, Delta delta) { @@ -85,8 +85,8 @@ class History { } Tuple2 _change(Document doc, List source, List dest) { - if (source.length == 0) { - return new Tuple2(false, 0); + if (source.isEmpty) { + return Tuple2(false, 0); } Delta delta = source.removeLast(); // look for insert or delete @@ -102,11 +102,11 @@ class History { Delta base = Delta.from(doc.toDelta()); Delta inverseDelta = delta.invert(base); dest.add(inverseDelta); - this.lastRecorded = 0; - this.ignoreChange = true; + lastRecorded = 0; + ignoreChange = true; doc.compose(delta, ChangeSource.LOCAL); - this.ignoreChange = false; - return new Tuple2(true, len); + ignoreChange = false; + return Tuple2(true, len); } Tuple2 undo(Document doc) { diff --git a/lib/models/documents/nodes/block.dart b/lib/models/documents/nodes/block.dart index 6ab8d331..4d569cc7 100644 --- a/lib/models/documents/nodes/block.dart +++ b/lib/models/documents/nodes/block.dart @@ -16,7 +16,7 @@ class Block extends Container { } @override - adjust() { + void adjust() { if (isEmpty) { Node? sibling = previous; unlink(); diff --git a/lib/utils/universal_ui/fake_ui.dart b/lib/utils/universal_ui/fake_ui.dart index da0f9a32..3c59b5d2 100644 --- a/lib/utils/universal_ui/fake_ui.dart +++ b/lib/utils/universal_ui/fake_ui.dart @@ -1,3 +1,3 @@ -class platformViewRegistry { +class PlatformViewRegistry { static registerViewFactory(String viewId, dynamic cb) {} } diff --git a/lib/utils/universal_ui/real_ui.dart b/lib/utils/universal_ui/real_ui.dart index c2b8ea23..f699c9c0 100644 --- a/lib/utils/universal_ui/real_ui.dart +++ b/lib/utils/universal_ui/real_ui.dart @@ -1,9 +1,7 @@ import 'dart:ui' as ui; -// ignore: camel_case_types -class platformViewRegistry { +class PlatformViewRegistry { static registerViewFactory(String viewId, dynamic cb) { - // ignore:undefined_prefixed_name ui.platformViewRegistry.registerViewFactory(viewId, cb); } } diff --git a/lib/utils/universal_ui/universal_ui.dart b/lib/utils/universal_ui/universal_ui.dart index d97aff1f..307520c5 100644 --- a/lib/utils/universal_ui/universal_ui.dart +++ b/lib/utils/universal_ui/universal_ui.dart @@ -6,12 +6,11 @@ import 'fake_ui.dart' if (dart.library.html) 'real_ui.dart' as ui_instance; class PlatformViewRegistryFix { registerViewFactory(dynamic x, dynamic y) { if (kIsWeb) { - // ignore: undefined_prefixed_name - ui_instance.platformViewRegistry.registerViewFactory( + ui_instance.PlatformViewRegistry.registerViewFactory( x, y, ); - } else {} + } } } diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index ea676d64..e7f0975c 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -843,7 +843,7 @@ class _TextLineElement extends RenderObjectElement { throw UnimplementedError(); } - _mountChild(Widget? widget, TextLineSlot slot) { + void _mountChild(Widget? widget, TextLineSlot slot) { Element? oldChild = _slotToChildren[slot]; Element? newChild = updateChild(oldChild, widget, slot); if (oldChild != null) { @@ -854,7 +854,7 @@ class _TextLineElement extends RenderObjectElement { } } - _updateRenderObject(RenderBox? child, TextLineSlot? slot) { + void _updateRenderObject(RenderBox? child, TextLineSlot? slot) { switch (slot) { case TextLineSlot.LEADING: renderObject.setLeading(child); @@ -867,7 +867,7 @@ class _TextLineElement extends RenderObjectElement { } } - _updateChild(Widget? widget, TextLineSlot slot) { + void _updateChild(Widget? widget, TextLineSlot slot) { Element? oldChild = _slotToChildren[slot]; Element? newChild = updateChild(oldChild, widget, slot); if (oldChild != null) { diff --git a/lib/widgets/text_selection.dart b/lib/widgets/text_selection.dart index 2b625e90..4d9cb564 100644 --- a/lib/widgets/text_selection.dart +++ b/lib/widgets/text_selection.dart @@ -65,7 +65,7 @@ class EditorTextSelectionOverlay { Animation get _toolbarOpacity => _toolbarController.view; - setHandlesVisible(bool visible) { + void setHandlesVisible(bool visible) { if (handlesVisible == visible) { return; } @@ -78,7 +78,7 @@ class EditorTextSelectionOverlay { } } - hideHandles() { + void hideHandles() { if (_handles == null) { return; } @@ -87,14 +87,14 @@ class EditorTextSelectionOverlay { _handles = null; } - hideToolbar() { + void hideToolbar() { assert(toolbar != null); _toolbarController.stop(); toolbar!.remove(); toolbar = null; } - showToolbar() { + void showToolbar() { assert(toolbar == null); toolbar = OverlayEntry(builder: _buildToolbar); Overlay.of(context, rootOverlay: true, debugRequiredFor: debugRequiredFor)! @@ -125,7 +125,7 @@ class EditorTextSelectionOverlay { )); } - update(TextEditingValue newValue) { + void update(TextEditingValue newValue) { if (value == newValue) { return; } @@ -138,7 +138,7 @@ class EditorTextSelectionOverlay { } } - _handleSelectionHandleChanged( + void _handleSelectionHandleChanged( TextSelection? newSelection, _TextSelectionHandlePosition position) { TextPosition textPosition; switch (position) { @@ -203,7 +203,7 @@ class EditorTextSelectionOverlay { ); } - markNeedsBuild([Duration? duration]) { + void markNeedsBuild([Duration? duration]) { if (_handles != null) { _handles![0].markNeedsBuild(); _handles![1].markNeedsBuild(); @@ -211,7 +211,7 @@ class EditorTextSelectionOverlay { toolbar?.markNeedsBuild(); } - hide() { + void hide() { if (_handles != null) { _handles![0].remove(); _handles![1].remove(); @@ -222,7 +222,7 @@ class EditorTextSelectionOverlay { } } - dispose() { + void dispose() { hide(); _toolbarController.dispose(); } @@ -299,7 +299,7 @@ class _TextSelectionHandleOverlayState widget._visibility!.addListener(_handleVisibilityChanged); } - _handleVisibilityChanged() { + void _handleVisibilityChanged() { if (widget._visibility!.value) { _controller.forward(); } else { @@ -308,7 +308,7 @@ class _TextSelectionHandleOverlayState } @override - didUpdateWidget(_TextSelectionHandleOverlay oldWidget) { + void didUpdateWidget(_TextSelectionHandleOverlay oldWidget) { super.didUpdateWidget(oldWidget); oldWidget._visibility!.removeListener(_handleVisibilityChanged); _handleVisibilityChanged(); @@ -322,9 +322,9 @@ class _TextSelectionHandleOverlayState super.dispose(); } - _handleDragStart(DragStartDetails details) {} + void _handleDragStart(DragStartDetails details) {} - _handleDragUpdate(DragUpdateDetails details) { + void _handleDragUpdate(DragUpdateDetails details) { TextPosition position = widget.renderObject!.getPositionForOffset(details.globalPosition); if (widget.selection.isCollapsed) { @@ -357,9 +357,10 @@ class _TextSelectionHandleOverlayState widget.onSelectionHandleChanged(newSelection); } - _handleTap() { - if (widget.onSelectionHandleTapped != null) + void _handleTap() { + if (widget.onSelectionHandleTapped != null) { widget.onSelectionHandleTapped!(); + } } @override @@ -530,7 +531,7 @@ class _EditorTextSelectionGestureDetectorState super.dispose(); } - _handleTapDown(TapDownDetails details) { + void _handleTapDown(TapDownDetails details) { if (widget.onTapDown != null) { widget.onTapDown!(details); } @@ -546,7 +547,7 @@ class _EditorTextSelectionGestureDetectorState } } - _handleTapUp(TapUpDetails details) { + void _handleTapUp(TapUpDetails details) { if (!_isDoubleTap) { if (widget.onSingleTapUp != null) { widget.onSingleTapUp!(details); @@ -557,7 +558,7 @@ class _EditorTextSelectionGestureDetectorState _isDoubleTap = false; } - _handleTapCancel() { + void _handleTapCancel() { if (widget.onSingleTapCancel != null) { widget.onSingleTapCancel!(); } @@ -567,7 +568,7 @@ class _EditorTextSelectionGestureDetectorState DragUpdateDetails? _lastDragUpdateDetails; Timer? _dragUpdateThrottleTimer; - _handleDragStart(DragStartDetails details) { + void _handleDragStart(DragStartDetails details) { assert(_lastDragStartDetails == null); _lastDragStartDetails = details; if (widget.onDragSelectionStart != null) { @@ -575,13 +576,13 @@ class _EditorTextSelectionGestureDetectorState } } - _handleDragUpdate(DragUpdateDetails details) { + void _handleDragUpdate(DragUpdateDetails details) { _lastDragUpdateDetails = details; _dragUpdateThrottleTimer ??= Timer(Duration(milliseconds: 50), _handleDragUpdateThrottled); } - _handleDragUpdateThrottled() { + void _handleDragUpdateThrottled() { assert(_lastDragStartDetails != null); assert(_lastDragUpdateDetails != null); if (widget.onDragSelectionUpdate != null) { @@ -592,7 +593,7 @@ class _EditorTextSelectionGestureDetectorState _lastDragUpdateDetails = null; } - _handleDragEnd(DragEndDetails details) { + void _handleDragEnd(DragEndDetails details) { assert(_lastDragStartDetails != null); if (_dragUpdateThrottleTimer != null) { _dragUpdateThrottleTimer!.cancel(); @@ -606,7 +607,7 @@ class _EditorTextSelectionGestureDetectorState _lastDragUpdateDetails = null; } - _forcePressStarted(ForcePressDetails details) { + void _forcePressStarted(ForcePressDetails details) { _doubleTapTimer?.cancel(); _doubleTapTimer = null; if (widget.onForcePressStart != null) { @@ -614,25 +615,25 @@ class _EditorTextSelectionGestureDetectorState } } - _forcePressEnded(ForcePressDetails details) { + void _forcePressEnded(ForcePressDetails details) { if (widget.onForcePressEnd != null) { widget.onForcePressEnd!(details); } } - _handleLongPressStart(LongPressStartDetails details) { + void _handleLongPressStart(LongPressStartDetails details) { if (!_isDoubleTap && widget.onSingleLongTapStart != null) { widget.onSingleLongTapStart!(details); } } - _handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { + void _handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { if (!_isDoubleTap && widget.onSingleLongTapMoveUpdate != null) { widget.onSingleLongTapMoveUpdate!(details); } } - _handleLongPressEnd(LongPressEndDetails details) { + void _handleLongPressEnd(LongPressEndDetails details) { if (!_isDoubleTap && widget.onSingleLongTapEnd != null) { widget.onSingleLongTapEnd!(details); } diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 58f367d5..3a6a72b5 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -251,7 +251,7 @@ class _ToggleStyleButtonState extends State { _isToggled, isEnabled ? _toggleAttribute : null); } - _toggleAttribute() { + void _toggleAttribute() { widget.controller.formatSelection(_isToggled! ? Attribute.clone(widget.attribute, null) : widget.attribute); @@ -336,7 +336,7 @@ class _ToggleCheckListButtonState extends State { _isToggled, isEnabled ? _toggleAttribute : null); } - _toggleAttribute() { + void _toggleAttribute() { widget.controller.formatSelection(_isToggled! ? Attribute.clone(Attribute.unchecked, null) : Attribute.unchecked); @@ -445,42 +445,42 @@ Widget _selectHeadingStyleButtonBuilder(BuildContext context, Attribute? value, hoverElevation: 0, height: iconSize * 1.77, fillColor: Theme.of(context).canvasColor, - child: Text( - !kIsWeb - ? _valueToText[value!]! - : _valueToText[value!.key == "header" - ? Attribute.header - : (value.key == "h1") - ? Attribute.h1 - : (value.key == "h2") - ? Attribute.h2 - : Attribute.h3]!, - style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600), - ), initialValue: value, items: [ PopupMenuItem( - child: Text(_valueToText[Attribute.header]!, style: style), value: Attribute.header, height: iconSize * 1.77, + child: Text(_valueToText[Attribute.header]!, style: style), ), PopupMenuItem( - child: Text(_valueToText[Attribute.h1]!, style: style), value: Attribute.h1, height: iconSize * 1.77, + child: Text(_valueToText[Attribute.h1]!, style: style), ), PopupMenuItem( - child: Text(_valueToText[Attribute.h2]!, style: style), value: Attribute.h2, height: iconSize * 1.77, + child: Text(_valueToText[Attribute.h2]!, style: style), ), PopupMenuItem( - child: Text(_valueToText[Attribute.h3]!, style: style), value: Attribute.h3, height: iconSize * 1.77, + child: Text(_valueToText[Attribute.h3]!, style: style), ), ], onSelected: onSelected, + child: Text( + !kIsWeb + ? _valueToText[value!]! + : _valueToText[value!.key == 'header' + ? Attribute.header + : (value.key == 'h1') + ? Attribute.h1 + : (value.key == 'h2') + ? Attribute.h2 + : Attribute.h3]!, + style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600), + ), ); } @@ -512,7 +512,7 @@ class _ImageButtonState extends State { List? _paths; String? _extension; final _picker = ImagePicker(); - FileType _pickingType = FileType.any; + final FileType _pickingType = FileType.any; Future _pickImage(ImageSource source) async { final PickedFile? pickedFile = await _picker.getImage(source: source); @@ -542,7 +542,7 @@ class _ImageButtonState extends State { )) ?.files; } on PlatformException catch (e) { - print("Unsupported operation" + e.toString()); + print('Unsupported operation' + e.toString()); } catch (ex) { print(ex); } @@ -656,9 +656,9 @@ class _ColorButtonState extends State { _isToggledBackground = _getIsToggledBackground( widget.controller.getSelectionStyle().attributes); _isWhite = _isToggledColor && - _selectionStyle.attributes["color"]!.value == '#ffffff'; + _selectionStyle.attributes['color']!.value == '#ffffff'; _isWhitebackground = _isToggledBackground && - _selectionStyle.attributes["background"]!.value == '#ffffff'; + _selectionStyle.attributes['background']!.value == '#ffffff'; }); } @@ -668,9 +668,9 @@ class _ColorButtonState extends State { _isToggledColor = _getIsToggledColor(_selectionStyle.attributes); _isToggledBackground = _getIsToggledBackground(_selectionStyle.attributes); _isWhite = _isToggledColor && - _selectionStyle.attributes["color"]!.value == '#ffffff'; + _selectionStyle.attributes['color']!.value == '#ffffff'; _isWhitebackground = _isToggledBackground && - _selectionStyle.attributes["background"]!.value == '#ffffff'; + _selectionStyle.attributes['background']!.value == '#ffffff'; widget.controller.addListener(_didChangeEditingValue); } @@ -692,9 +692,9 @@ class _ColorButtonState extends State { _isToggledBackground = _getIsToggledBackground(_selectionStyle.attributes); _isWhite = _isToggledColor && - _selectionStyle.attributes["color"]!.value == '#ffffff'; + _selectionStyle.attributes['color']!.value == '#ffffff'; _isWhitebackground = _isToggledBackground && - _selectionStyle.attributes["background"]!.value == '#ffffff'; + _selectionStyle.attributes['background']!.value == '#ffffff'; } } @@ -708,12 +708,12 @@ class _ColorButtonState extends State { Widget build(BuildContext context) { final theme = Theme.of(context); Color? iconColor = _isToggledColor && !widget.background && !_isWhite - ? stringToColor(_selectionStyle.attributes["color"]!.value) + ? stringToColor(_selectionStyle.attributes['color']!.value) : theme.iconTheme.color; - Color? iconColorBackground = + var iconColorBackground = _isToggledBackground && widget.background && !_isWhitebackground - ? stringToColor(_selectionStyle.attributes["background"]!.value) + ? stringToColor(_selectionStyle.attributes['background']!.value) : theme.iconTheme.color; Color fillColor = _isToggledColor && !widget.background && _isWhite @@ -747,7 +747,7 @@ class _ColorButtonState extends State { Navigator.of(context).pop(); } - _showColorPicker() { + void _showColorPicker() { showDialog( context: context, builder: (_) => AlertDialog( @@ -755,7 +755,7 @@ class _ColorButtonState extends State { backgroundColor: Theme.of(context).canvasColor, content: SingleChildScrollView( child: MaterialPicker( - pickerColor: Color(0), + pickerColor: Color(0x00000000), onColorChanged: _changeColor, ), )), @@ -1190,7 +1190,6 @@ class QuillIconButton extends StatelessWidget { return ConstrainedBox( constraints: BoxConstraints.tightFor(width: size, height: size), child: RawMaterialButton( - child: icon, visualDensity: VisualDensity.compact, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(2)), padding: EdgeInsets.zero, @@ -1199,6 +1198,7 @@ class QuillIconButton extends StatelessWidget { hoverElevation: hoverElevation, highlightElevation: hoverElevation, onPressed: onPressed, + child: icon, ), ); } @@ -1236,7 +1236,6 @@ class _QuillDropdownButtonState extends State> { return ConstrainedBox( constraints: BoxConstraints.tightFor(height: widget.height), child: RawMaterialButton( - child: _buildContent(context), visualDensity: VisualDensity.compact, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(2)), padding: EdgeInsets.zero, @@ -1245,6 +1244,7 @@ class _QuillDropdownButtonState extends State> { hoverElevation: widget.hoverElevation, highlightElevation: widget.hoverElevation, onPressed: _showMenu, + child: _buildContent(context), ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index e54c69ee..7fb8925c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill -description: One client and affiliated collaborator of Flutter Quill is Bullet Journal App. -version: 1.1.1 +description: Rich text editor (Demo App https://bulletjournal.us/home/index.html ). +version: 1.1.2 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill @@ -25,6 +25,7 @@ dependencies: tuple: ^2.0.0 universal_html: ^2.0.4 url_launcher: ^6.0.2 + pedantic: ^1.11.0 dev_dependencies: flutter_test: