diff --git a/analysis_options.yaml b/analysis_options.yaml index 451c1799c..74ce67a1e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -10,3 +10,4 @@ linter: - always_put_required_named_parameters_first - avoid_print - avoid_redundant_argument_values + - prefer_const_constructors diff --git a/lib/models/documents/history.dart b/lib/models/documents/history.dart index 32e780c94..6d89b3895 100644 --- a/lib/models/documents/history.dart +++ b/lib/models/documents/history.dart @@ -86,7 +86,7 @@ class History { Tuple2 _change(Document doc, List source, List dest) { if (source.isEmpty) { - return Tuple2(false, 0); + return const Tuple2(false, 0); } Delta delta = source.removeLast(); // look for insert or delete diff --git a/lib/models/quill_delta.dart b/lib/models/quill_delta.dart index a1fe1f0f2..72d268461 100644 --- a/lib/models/quill_delta.dart +++ b/lib/models/quill_delta.dart @@ -294,7 +294,7 @@ class Delta { if (other is! Delta) return false; Delta typedOther = other; final comparator = - ListEquality(const DefaultEquality()); + const ListEquality(DefaultEquality()); return comparator.equals(_operations, typedOther._operations); } diff --git a/lib/models/rules/insert.dart b/lib/models/rules/insert.dart index 62585ec34..5ea7f215e 100644 --- a/lib/models/rules/insert.dart +++ b/lib/models/rules/insert.dart @@ -378,5 +378,5 @@ Tuple2 _getNextNewLine(DeltaIterator iterator) { return Tuple2(op, skipped); } } - return Tuple2(null, null); + return const Tuple2(null, null); } diff --git a/lib/models/rules/rule.dart b/lib/models/rules/rule.dart index bff58b449..8141aaf32 100644 --- a/lib/models/rules/rule.dart +++ b/lib/models/rules/rule.dart @@ -29,21 +29,21 @@ abstract class Rule { class Rules { final List _rules; static final Rules _instance = Rules([ - FormatLinkAtCaretPositionRule(), - ResolveLineFormatRule(), - ResolveInlineFormatRule(), - InsertEmbedsRule(), - ForceNewlineForInsertsAroundEmbedRule(), - AutoExitBlockRule(), - PreserveBlockStyleOnInsertRule(), - PreserveLineStyleOnSplitRule(), - ResetLineFormatOnNewLineRule(), - AutoFormatLinksRule(), - PreserveInlineStylesRule(), - CatchAllInsertRule(), - EnsureEmbedLineRule(), - PreserveLineStyleOnMergeRule(), - CatchAllDeleteRule(), + const FormatLinkAtCaretPositionRule(), + const ResolveLineFormatRule(), + const ResolveInlineFormatRule(), + const InsertEmbedsRule(), + const ForceNewlineForInsertsAroundEmbedRule(), + const AutoExitBlockRule(), + const PreserveBlockStyleOnInsertRule(), + const PreserveLineStyleOnSplitRule(), + const ResetLineFormatOnNewLineRule(), + const AutoFormatLinksRule(), + const PreserveInlineStylesRule(), + const CatchAllInsertRule(), + const EnsureEmbedLineRule(), + const PreserveLineStyleOnMergeRule(), + const CatchAllDeleteRule(), ]); Rules(this._rules); diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index f613af69e..da876bf1b 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -18,7 +18,9 @@ class QuillController extends ChangeNotifier { factory QuillController.basic() { return QuillController( - document: Document(), selection: TextSelection.collapsed(offset: 0)); + document: Document(), + selection: const TextSelection.collapsed(offset: 0), + ); } // item1: Document state before [change]. @@ -72,7 +74,8 @@ class QuillController extends ChangeNotifier { bool get hasRedo => document.hasRedo; - void replaceText(int index, int len, Object? data, TextSelection? textSelection) { + void replaceText( + int index, int len, Object? data, TextSelection? textSelection) { assert(data is String || data is Embeddable); Delta? delta; diff --git a/lib/widgets/cursor.dart b/lib/widgets/cursor.dart index 8fa454372..4195d947f 100644 --- a/lib/widgets/cursor.dart +++ b/lib/widgets/cursor.dart @@ -109,7 +109,8 @@ class CursorCont extends ChangeNotifier { void _cursorWaitForStart(Timer timer) { _cursorTimer?.cancel(); - _cursorTimer = Timer.periodic(Duration(milliseconds: 500), _cursorTick); + _cursorTimer = + Timer.periodic(const Duration(milliseconds: 500), _cursorTick); } void startCursorTimer() { @@ -117,10 +118,11 @@ class CursorCont extends ChangeNotifier { _blinkOpacityCont.value = 1.0; if (style.opacityAnimates) { - _cursorTimer = - Timer.periodic(Duration(milliseconds: 150), _cursorWaitForStart); + _cursorTimer = Timer.periodic( + const Duration(milliseconds: 150), _cursorWaitForStart); } else { - _cursorTimer = Timer.periodic(Duration(milliseconds: 500), _cursorTick); + _cursorTimer = + Timer.periodic(const Duration(milliseconds: 500), _cursorTick); } } diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 30b6b7fef..2e3ad80c1 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -86,7 +86,7 @@ class DefaultStyles { fontSize: 16.0, height: 1.3, ); - Tuple2 baseSpacing = Tuple2(6.0, 0); + Tuple2 baseSpacing = const Tuple2(6.0, 0); String fontFamily; switch (themeData.platform) { case TargetPlatform.iOS: @@ -111,8 +111,8 @@ class DefaultStyles { height: 1.15, fontWeight: FontWeight.w300, ), - Tuple2(16.0, 0.0), - Tuple2(0.0, 0.0), + const Tuple2(16.0, 0.0), + const Tuple2(0.0, 0.0), null), h2: DefaultTextBlockStyle( defaultTextStyle.style.copyWith( @@ -121,8 +121,8 @@ class DefaultStyles { height: 1.15, fontWeight: FontWeight.normal, ), - Tuple2(8.0, 0.0), - Tuple2(0.0, 0.0), + const Tuple2(8.0, 0.0), + const Tuple2(0.0, 0.0), null), h3: DefaultTextBlockStyle( defaultTextStyle.style.copyWith( @@ -131,15 +131,15 @@ class DefaultStyles { height: 1.25, fontWeight: FontWeight.w500, ), - Tuple2(8.0, 0.0), - Tuple2(0.0, 0.0), + const Tuple2(8.0, 0.0), + const Tuple2(0.0, 0.0), null), paragraph: DefaultTextBlockStyle( - baseStyle, Tuple2(0.0, 0.0), Tuple2(0.0, 0.0), null), - bold: TextStyle(fontWeight: FontWeight.bold), - italic: TextStyle(fontStyle: FontStyle.italic), - underline: TextStyle(decoration: TextDecoration.underline), - strikeThrough: TextStyle(decoration: TextDecoration.lineThrough), + baseStyle, const Tuple2(0.0, 0.0), const Tuple2(0.0, 0.0), null), + bold: const TextStyle(fontWeight: FontWeight.bold), + italic: const TextStyle(fontStyle: FontStyle.italic), + underline: const TextStyle(decoration: TextDecoration.underline), + strikeThrough: const TextStyle(decoration: TextDecoration.lineThrough), link: TextStyle( color: themeData.accentColor, decoration: TextDecoration.underline, @@ -150,15 +150,15 @@ class DefaultStyles { height: 1.5, color: Colors.grey.withOpacity(0.6), ), - Tuple2(0.0, 0.0), - Tuple2(0.0, 0.0), + const Tuple2(0.0, 0.0), + const Tuple2(0.0, 0.0), null), lists: DefaultTextBlockStyle( - baseStyle, baseSpacing, Tuple2(0.0, 6.0), null), + baseStyle, baseSpacing, const Tuple2(0.0, 6.0), null), quote: DefaultTextBlockStyle( TextStyle(color: baseStyle.color!.withOpacity(0.6)), baseSpacing, - Tuple2(6.0, 2.0), + const Tuple2(6.0, 2.0), BoxDecoration( border: Border( left: BorderSide(width: 4, color: Colors.grey.shade300), @@ -172,18 +172,18 @@ class DefaultStyles { height: 1.15, ), baseSpacing, - Tuple2(0.0, 0.0), + const Tuple2(0.0, 0.0), BoxDecoration( color: Colors.grey.shade50, borderRadius: BorderRadius.circular(2), )), indent: DefaultTextBlockStyle( - baseStyle, baseSpacing, Tuple2(0.0, 6.0), null), + baseStyle, baseSpacing, const Tuple2(0.0, 6.0), null), align: DefaultTextBlockStyle( - baseStyle, Tuple2(0.0, 0.0), Tuple2(0.0, 0.0), null), - sizeSmall: TextStyle(fontSize: 10.0), - sizeLarge: TextStyle(fontSize: 18.0), - sizeHuge: TextStyle(fontSize: 22.0)); + baseStyle, const Tuple2(0.0, 0.0), const Tuple2(0.0, 0.0), null), + sizeSmall: const TextStyle(fontSize: 10.0), + sizeLarge: const TextStyle(fontSize: 18.0), + sizeHuge: const TextStyle(fontSize: 22.0)); } DefaultStyles merge(DefaultStyles other) { diff --git a/lib/widgets/proxy.dart b/lib/widgets/proxy.dart index f3e38c4ed..7b918b9dd 100644 --- a/lib/widgets/proxy.dart +++ b/lib/widgets/proxy.dart @@ -113,7 +113,7 @@ class RenderEmbedProxy extends RenderProxyBox implements RenderContentProxyBox { @override TextRange getWordBoundary(TextPosition position) => - TextRange(start: 0, end: 1); + const TextRange(start: 0, end: 1); @override double getPreferredLineHeight() { diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 73a17e254..9ba3587a8 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -552,7 +552,7 @@ class RawEditorState extends EditorState } BoxConstraints constraints = widget.expands - ? BoxConstraints.expand() + ? const BoxConstraints.expand() : BoxConstraints( minHeight: widget.minHeight ?? 0.0, maxHeight: widget.maxHeight ?? double.infinity); @@ -600,7 +600,7 @@ class RawEditorState extends EditorState widget.enableInteractiveSelection, _hasFocus, attrs.containsKey(Attribute.codeBlock.key) - ? EdgeInsets.all(16.0) + ? const EdgeInsets.all(16.0) : null, widget.embedBuilder, _cursorCont, @@ -816,7 +816,8 @@ class RawEditorState extends EditorState String plainText = textEditingValue.text; if (shortcut == InputShortcut.COPY) { if (!selection.isCollapsed) { - await Clipboard.setData(ClipboardData(text: selection.textInside(plainText))); + await Clipboard.setData( + ClipboardData(text: selection.textInside(plainText))); } return; } @@ -984,7 +985,7 @@ class RawEditorState extends EditorState final viewport = RenderAbstractViewport.of(getRenderEditor())!; final editorOffset = getRenderEditor()! - .localToGlobal(Offset(0.0, 0.0), ancestor: viewport); + .localToGlobal(const Offset(0.0, 0.0), ancestor: viewport); final offsetInViewport = _scrollController!.offset + editorOffset.dy; final offset = getRenderEditor()!.getOffsetToRevealCursor( @@ -996,7 +997,7 @@ class RawEditorState extends EditorState if (offset != null) { _scrollController!.animateTo( offset, - duration: Duration(milliseconds: 100), + duration: const Duration(milliseconds: 100), curve: Curves.fastOutSlowIn, ); } @@ -1150,16 +1151,17 @@ class _Editor extends MultiChildRenderObjectWidget { @override RenderEditor createRenderObject(BuildContext context) { return RenderEditor( - null, - textDirection, - padding, - document, - selection, - hasFocus, - onSelectionChanged, - startHandleLayerLink, - endHandleLayerLink, - EdgeInsets.fromLTRB(4, 4, 4, 5)); + null, + textDirection, + padding, + document, + selection, + hasFocus, + onSelectionChanged, + startHandleLayerLink, + endHandleLayerLink, + const EdgeInsets.fromLTRB(4, 4, 4, 5), + ); } @override diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index ef226b1ef..7edb3add0 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -84,7 +84,7 @@ class EditableTextBlock extends StatelessWidget { block, textDirection, verticalSpacing as Tuple2, - _getDecorationForBlock(block, defaultStyles) ?? BoxDecoration(), + _getDecorationForBlock(block, defaultStyles) ?? const BoxDecoration(), contentPadding, _buildChildren(context, indentLevelCounts)); } @@ -402,7 +402,8 @@ class RenderEditableTextBlock extends RenderEditableContainerBox } Offset caretOffset = child.getOffsetForCaret(childLocalPosition); - Offset testOffset = sibling.getOffsetForCaret(TextPosition(offset: 0)); + Offset testOffset = + sibling.getOffsetForCaret(const TextPosition(offset: 0)); Offset finalOffset = Offset(caretOffset.dx, testOffset.dy); return TextPosition( offset: sibling.getContainer().getOffset() + @@ -666,7 +667,7 @@ class _BulletPoint extends StatelessWidget { return Container( alignment: AlignmentDirectional.topEnd, width: width, - padding: EdgeInsetsDirectional.only(end: 13.0), + padding: const EdgeInsetsDirectional.only(end: 13.0), child: Text('•', style: style), ); } @@ -707,7 +708,7 @@ class __CheckboxState extends State<_Checkbox> { return Container( alignment: AlignmentDirectional.topEnd, width: widget.width, - padding: EdgeInsetsDirectional.only(end: 13.0), + padding: const EdgeInsetsDirectional.only(end: 13.0), child: Checkbox( value: widget.isChecked, onChanged: _onCheckboxClicked, diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 82418ca31..730907869 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -87,7 +87,7 @@ class TextLine extends StatelessWidget { .map((node) => _getTextSpanFromNode(defaultStyles, node)) .toList(growable: false); - TextStyle textStyle = TextStyle(); + TextStyle textStyle = const TextStyle(); if (line.style.containsKey(Attribute.placeholder.key)) { textStyle = defaultStyles.placeHolder!.style; @@ -121,7 +121,7 @@ class TextLine extends StatelessWidget { TextSpan _getTextSpanFromNode(DefaultStyles defaultStyles, Node node) { leaf.Text textNode = node as leaf.Text; Style style = textNode.style; - TextStyle res = TextStyle(); + TextStyle res = const TextStyle(); Map m = { Attribute.bold.key: defaultStyles.bold, @@ -534,7 +534,8 @@ class RenderEditableTextLine extends RenderEditableBox { double get cursorWidth => cursorCont.style.width; double get cursorHeight => - cursorCont.style.height ?? preferredLineHeight(TextPosition(offset: 0)); + cursorCont.style.height ?? + preferredLineHeight(const TextPosition(offset: 0)); void _computeCaretPrototype() { switch (defaultTargetPlatform) { diff --git a/lib/widgets/text_selection.dart b/lib/widgets/text_selection.dart index 99f381fad..366c7d0b4 100644 --- a/lib/widgets/text_selection.dart +++ b/lib/widgets/text_selection.dart @@ -58,7 +58,7 @@ class EditorTextSelectionOverlay { OverlayState overlay = Overlay.of(context, rootOverlay: true)!; _toolbarController = AnimationController( - duration: Duration(milliseconds: 150), vsync: overlay); + duration: const Duration(milliseconds: 150), vsync: overlay); } TextSelection get _selection => value.selection; @@ -143,13 +143,14 @@ class EditorTextSelectionOverlay { TextPosition textPosition; switch (position) { case _TextSelectionHandlePosition.START: - textPosition = - newSelection != null ? newSelection.base : TextPosition(offset: 0); + textPosition = newSelection != null + ? newSelection.base + : const TextPosition(offset: 0); break; case _TextSelectionHandlePosition.END: textPosition = newSelection != null ? newSelection.extent - : TextPosition(offset: 0); + : const TextPosition(offset: 0); break; default: throw ('Invalid position'); @@ -198,7 +199,7 @@ class EditorTextSelectionOverlay { endpoints, selectionDelegate, clipboardStatus, - Offset(0, 0)), + const Offset(0, 0)), ), ); } @@ -292,8 +293,8 @@ class _TextSelectionHandleOverlayState void initState() { super.initState(); - _controller = - AnimationController(duration: Duration(milliseconds: 150), vsync: this); + _controller = AnimationController( + duration: const Duration(milliseconds: 150), vsync: this); _handleVisibilityChanged(); widget._visibility!.addListener(_handleVisibilityChanged); @@ -579,7 +580,7 @@ class _EditorTextSelectionGestureDetectorState void _handleDragUpdate(DragUpdateDetails details) { _lastDragUpdateDetails = details; _dragUpdateThrottleTimer ??= - Timer(Duration(milliseconds: 50), _handleDragUpdateThrottled); + Timer(const Duration(milliseconds: 50), _handleDragUpdateThrottled); } void _handleDragUpdateThrottled() { diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 514946a35..bff3ff9e0 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -114,7 +114,7 @@ class _LinkStyleButtonState extends State { showDialog( context: context, builder: (ctx) { - return _LinkDialog(); + return const _LinkDialog(); }, ).then(_linkSubmitted); } @@ -141,14 +141,14 @@ class _LinkDialogState extends State<_LinkDialog> { Widget build(BuildContext context) { return AlertDialog( content: TextField( - decoration: InputDecoration(labelText: 'Paste a link'), + decoration: const InputDecoration(labelText: 'Paste a link'), autofocus: true, onChanged: _linkChanged, ), actions: [ TextButton( onPressed: _link.isNotEmpty ? _applyLink : null, - child: Text('Apply'), + child: const Text('Apply'), ), ], ); @@ -430,7 +430,7 @@ class _SelectHeaderStyleButtonState extends State { Widget _selectHeadingStyleButtonBuilder(BuildContext context, Attribute? value, ValueChanged onSelected) { - final style = TextStyle(fontSize: 13); + final style = const TextStyle(fontSize: 13); final Map _valueToText = { Attribute.header: 'Normal text', @@ -478,7 +478,7 @@ Widget _selectHeadingStyleButtonBuilder(BuildContext context, Attribute? value, : (value.key == 'h2') ? Attribute.h2 : Attribute.h3]!, - style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600), + style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600), ), ); } @@ -725,7 +725,7 @@ class _ColorButtonState extends State { backgroundColor: Theme.of(context).canvasColor, content: SingleChildScrollView( child: MaterialPicker( - pickerColor: Color(0x00000000), + pickerColor: const Color(0x00000000), onColorChanged: _changeColor, ), )), @@ -939,7 +939,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { undo: false, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: showBoldButton, child: ToggleStyleButton( @@ -948,7 +948,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { controller: controller, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: showItalicButton, child: ToggleStyleButton( @@ -957,7 +957,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { controller: controller, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: showUnderLineButton, child: ToggleStyleButton( @@ -966,7 +966,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { controller: controller, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: showStrikeThrough, child: ToggleStyleButton( @@ -975,7 +975,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { controller: controller, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: showColorButton, child: ColorButton( @@ -984,7 +984,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { background: false, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: showBackgroundColorButton, child: ColorButton( @@ -993,7 +993,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { background: true, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: showClearFormat, child: ClearFormatButton( @@ -1001,7 +1001,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { controller: controller, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: onImagePickCallback != null, child: ImageButton( @@ -1011,7 +1011,7 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { onImagePickCallback: onImagePickCallback, ), ), - SizedBox(width: 0.6), + const SizedBox(width: 0.6), Visibility( visible: onImagePickCallback != null, child: ImageButton( @@ -1119,7 +1119,7 @@ class _QuillToolbarState extends State { @override Widget build(BuildContext context) { return Container( - padding: EdgeInsets.symmetric(horizontal: 8), + padding: const EdgeInsets.symmetric(horizontal: 8), constraints: BoxConstraints.tightFor(height: widget.preferredSize.height), color: Theme.of(context).canvasColor, child: CustomScrollView( @@ -1254,14 +1254,14 @@ class _QuillDropdownButtonState extends State> { Widget _buildContent(BuildContext context) { return ConstrainedBox( - constraints: BoxConstraints.tightFor(width: 110), + constraints: const BoxConstraints.tightFor(width: 110), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Row( children: [ widget.child, Expanded(child: Container()), - Icon(Icons.arrow_drop_down, size: 15) + const Icon(Icons.arrow_drop_down, size: 15) ], ), ),