From cd05dfaeb8ec3d3a860ba0bc8ccc563728d7eba8 Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Sat, 27 Mar 2021 18:06:58 +0100 Subject: [PATCH 1/6] Avoid redundant argument values (#114) If it's ok, I would spend the day enabling linter rules so that the codebase is more compliant with [Effective Dart](https://dart.dev/guides/language/effective-dart) and thus more readable for new developers. --- analysis_options.yaml | 1 + example/lib/pages/home_page.dart | 1 - example/lib/pages/read_only_page.dart | 1 - lib/models/documents/document.dart | 6 +++--- lib/models/quill_delta.dart | 2 +- lib/widgets/controller.dart | 1 - lib/widgets/editor.dart | 4 +--- lib/widgets/raw_editor.dart | 2 -- lib/widgets/text_block.dart | 2 +- lib/widgets/toolbar.dart | 3 --- 10 files changed, 7 insertions(+), 16 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 57f3028e..33b1634a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -8,3 +8,4 @@ analyzer: linter: rules: - avoid_print + - avoid_redundant_argument_values diff --git a/example/lib/pages/home_page.dart b/example/lib/pages/home_page.dart index 2e044fd7..9e91cde4 100644 --- a/example/lib/pages/home_page.dart +++ b/example/lib/pages/home_page.dart @@ -110,7 +110,6 @@ class _HomePageState extends State { autoFocus: false, readOnly: false, placeholder: 'Add content', - enableInteractiveSelection: true, expands: false, padding: EdgeInsets.zero, customStyles: DefaultStyles( diff --git a/example/lib/pages/read_only_page.dart b/example/lib/pages/read_only_page.dart index 8f03d45c..6e2ec0e0 100644 --- a/example/lib/pages/read_only_page.dart +++ b/example/lib/pages/read_only_page.dart @@ -42,7 +42,6 @@ class _ReadOnlyPageState extends State { focusNode: _focusNode, autoFocus: true, readOnly: !_edit, - enableInteractiveSelection: true, expands: false, padding: EdgeInsets.zero, ), diff --git a/lib/models/documents/document.dart b/lib/models/documents/document.dart index d52e89a4..126ff32b 100644 --- a/lib/models/documents/document.dart +++ b/lib/models/documents/document.dart @@ -183,7 +183,7 @@ class Document { bool nextOpIsImage = i + 1 < ops.length && ops[i + 1].isInsert && ops[i + 1].data is! String; if (nextOpIsImage && !(op.data as String).endsWith('\n')) { - res.push(Operation.insert('\n', null)); + res.push(Operation.insert('\n')); } // Currently embed is equivalent to image and hence `is! String` bool opInsertImage = op.isInsert && op.data is! String; @@ -193,7 +193,7 @@ class Document { (ops[i + 1].data as String).startsWith('\n'); if (opInsertImage && (i + 1 == ops.length - 1 || !nextOpIsLineBreak)) { // automatically append '\n' for image - res.push(Operation.insert('\n', null)); + res.push(Operation.insert('\n')); } } @@ -213,7 +213,7 @@ class Document { _history.clear(); } - String toPlainText() => _root.children.map((e) => e.toPlainText()).join(''); + String toPlainText() => _root.children.map((e) => e.toPlainText()).join(); void _loadDocument(Delta doc) { assert((doc.last.data as String).endsWith('\n')); diff --git a/lib/models/quill_delta.dart b/lib/models/quill_delta.dart index bced9b88..a1fe1f0f 100644 --- a/lib/models/quill_delta.dart +++ b/lib/models/quill_delta.dart @@ -520,7 +520,7 @@ class Delta { if (op.isInsert) { inverted.delete(op.length!); } else if (op.isRetain && op.isPlain) { - inverted.retain(op.length!, null); + inverted.retain(op.length!); baseIndex += op.length!; } else if (op.isDelete || (op.isRetain && op.isNotPlain)) { final length = op.length!; diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index 29206059..f613af69 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -31,7 +31,6 @@ class QuillController extends ChangeNotifier { TextEditingValue get plainTextEditingValue => TextEditingValue( text: document.toPlainText(), selection: selection, - composing: TextRange.empty, ); Style getSelectionStyle() { diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 305a58c8..f3d3bd1a 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -200,7 +200,6 @@ class QuillEditor extends StatefulWidget { focusNode: FocusNode(), autoFocus: true, readOnly: readOnly, - enableInteractiveSelection: true, expands: false, padding: EdgeInsets.zero); } @@ -726,8 +725,7 @@ class RenderEditor extends RenderEditableContainerBox ); if (position.offset - word.start <= 1) { _handleSelectionChange( - TextSelection.collapsed( - offset: word.start, affinity: TextAffinity.downstream), + TextSelection.collapsed(offset: word.start), cause, ); } else { diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 04b4aaf8..11c9c568 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -382,8 +382,6 @@ class RawEditorState extends EditorState TextInputConfiguration( inputType: TextInputType.multiline, readOnly: widget.readOnly, - obscureText: false, - autocorrect: true, inputAction: TextInputAction.newline, keyboardAppearance: widget.keyboardAppearance, textCapitalization: widget.textCapitalization, diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index 4d2a5cc3..1b085957 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -623,7 +623,7 @@ class _NumberPoint extends StatelessWidget { n = (n / 26).floor(); } - return result.toString().split('').reversed.join(''); + return result.toString().split('').reversed.join(); } String _intToRoman(int input) { diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index cb23a19e..0859cad3 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -525,7 +525,6 @@ class _ImageButtonState extends State { Future _pickImageWeb() async { _paths = (await FilePicker.platform.pickFiles( type: _pickingType, - allowMultiple: false, allowedExtensions: (_extension?.isNotEmpty ?? false) ? _extension?.replaceAll(' ', '').split(',') : null, @@ -1163,7 +1162,6 @@ class QuillIconButton extends StatelessWidget { child: RawMaterialButton( visualDensity: VisualDensity.compact, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(2)), - padding: EdgeInsets.zero, fillColor: fillColor, elevation: 0, hoverElevation: hoverElevation, @@ -1209,7 +1207,6 @@ class _QuillDropdownButtonState extends State> { child: RawMaterialButton( visualDensity: VisualDensity.compact, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(2)), - padding: EdgeInsets.zero, fillColor: widget.fillColor, elevation: 0, hoverElevation: widget.hoverElevation, From 25f1582f70f11c5e0ff643f3f33b5a84e7cdbbab Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Sat, 27 Mar 2021 18:08:16 +0100 Subject: [PATCH 2/6] Always put required named parameters first (#115) --- analysis_options.yaml | 1 + lib/widgets/default_styles.dart | 2 +- lib/widgets/editor.dart | 4 +- lib/widgets/responsive_widget.dart | 12 +-- lib/widgets/text_block.dart | 6 +- lib/widgets/text_line.dart | 17 ++-- lib/widgets/text_selection.dart | 6 +- lib/widgets/toolbar.dart | 127 +++++++++++++++-------------- 8 files changed, 89 insertions(+), 86 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 33b1634a..451c1799 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,5 +7,6 @@ analyzer: unsafe_html: ignore linter: rules: + - always_put_required_named_parameters_first - avoid_print - avoid_redundant_argument_values diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index bbe8db10..30b6b7fe 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -6,9 +6,9 @@ class QuillStyles extends InheritedWidget { final DefaultStyles data; QuillStyles({ - Key? key, required this.data, required Widget child, + Key? key, }) : super(key: key, child: child); @override diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index f3d3bd1a..ef2221c0 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -176,14 +176,14 @@ class QuillEditor extends StatefulWidget { required this.scrollable, required this.padding, required this.autoFocus, - this.showCursor, required this.readOnly, + required this.expands, + this.showCursor, this.placeholder, this.enableInteractiveSelection = true, this.minHeight, this.maxHeight, this.customStyles, - required this.expands, this.textCapitalization = TextCapitalization.sentences, this.keyboardAppearance = Brightness.light, this.scrollPhysics, diff --git a/lib/widgets/responsive_widget.dart b/lib/widgets/responsive_widget.dart index 806883ec..dbfec8d5 100644 --- a/lib/widgets/responsive_widget.dart +++ b/lib/widgets/responsive_widget.dart @@ -5,12 +5,12 @@ class ResponsiveWidget extends StatelessWidget { final Widget? mediumScreen; final Widget? smallScreen; - const ResponsiveWidget( - {Key? key, - required this.largeScreen, - this.mediumScreen, - this.smallScreen}) - : super(key: key); + const ResponsiveWidget({ + required this.largeScreen, + this.mediumScreen, + this.smallScreen, + Key? key, + }) : super(key: key); static bool isSmallScreen(BuildContext context) { return MediaQuery.of(context).size.width < 800; diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index 1b085957..ef226b1e 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -253,11 +253,11 @@ class EditableTextBlock extends StatelessWidget { class RenderEditableTextBlock extends RenderEditableContainerBox implements RenderEditableBox { RenderEditableTextBlock({ - List? children, required Block block, required TextDirection textDirection, required EdgeInsetsGeometry padding, required Decoration decoration, + List? children, ImageConfiguration configuration = ImageConfiguration.empty, EdgeInsets contentPadding = EdgeInsets.zero, }) : _decoration = decoration, @@ -558,7 +558,6 @@ class _NumberPoint extends StatelessWidget { final double padding; const _NumberPoint({ - Key? key, required this.index, required this.indentLevelCounts, required this.count, @@ -567,6 +566,7 @@ class _NumberPoint extends StatelessWidget { required this.attrs, this.withDot = true, this.padding = 0.0, + Key? key, }) : super(key: key); @override @@ -656,9 +656,9 @@ class _BulletPoint extends StatelessWidget { final double width; const _BulletPoint({ - Key? key, required this.style, required this.width, + Key? key, }) : super(key: key); @override diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 0da1e64f..82418ca3 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -27,13 +27,13 @@ class TextLine extends StatelessWidget { final EmbedBuilder embedBuilder; final DefaultStyles styles; - const TextLine( - {Key? key, - required this.line, - this.textDirection, - required this.embedBuilder, - required this.styles}) - : super(key: key); + const TextLine({ + required this.line, + required this.embedBuilder, + required this.styles, + this.textDirection, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context) { @@ -839,7 +839,8 @@ class _TextLineElement extends RenderObjectElement { } @override - void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) { + void moveRenderObjectChild( + RenderObject child, dynamic oldSlot, dynamic newSlot) { throw UnimplementedError(); } diff --git a/lib/widgets/text_selection.dart b/lib/widgets/text_selection.dart index 4d9cb564..99f381fa 100644 --- a/lib/widgets/text_selection.dart +++ b/lib/widgets/text_selection.dart @@ -245,7 +245,6 @@ class EditorTextSelectionOverlay { class _TextSelectionHandleOverlay extends StatefulWidget { const _TextSelectionHandleOverlay({ - Key? key, required this.selection, required this.position, required this.startHandleLayerLink, @@ -255,6 +254,7 @@ class _TextSelectionHandleOverlay extends StatefulWidget { required this.onSelectionHandleTapped, required this.selectionControls, this.dragStartBehavior = DragStartBehavior.start, + Key? key, }) : super(key: key); final TextSelection selection; @@ -468,7 +468,7 @@ class _TextSelectionHandleOverlayState class EditorTextSelectionGestureDetector extends StatefulWidget { const EditorTextSelectionGestureDetector({ - Key? key, + required this.child, this.onTapDown, this.onForcePressStart, this.onForcePressEnd, @@ -482,7 +482,7 @@ class EditorTextSelectionGestureDetector extends StatefulWidget { this.onDragSelectionUpdate, this.onDragSelectionEnd, this.behavior, - required this.child, + Key? key, }) : super(key: key); final GestureTapDownCallback? onTapDown; diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 0859cad3..8eeb35ae 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -25,9 +25,9 @@ class InsertEmbedButton extends StatelessWidget { final IconData icon; const InsertEmbedButton({ - Key? key, required this.controller, required this.icon, + Key? key, }) : super(key: key); @override @@ -56,9 +56,9 @@ class LinkStyleButton extends StatefulWidget { final IconData? icon; const LinkStyleButton({ - Key? key, required this.controller, this.icon, + Key? key, }) : super(key: key); @override @@ -183,11 +183,11 @@ class ToggleStyleButton extends StatefulWidget { final ToggleStyleButtonBuilder childBuilder; ToggleStyleButton({ - Key? key, required this.attribute, required this.icon, required this.controller, this.childBuilder = defaultToggleStyleButtonBuilder, + Key? key, }) : super(key: key); @override @@ -267,11 +267,11 @@ class ToggleCheckListButton extends StatefulWidget { final Attribute attribute; ToggleCheckListButton({ - Key? key, required this.icon, required this.controller, - this.childBuilder = defaultToggleStyleButtonBuilder, required this.attribute, + this.childBuilder = defaultToggleStyleButtonBuilder, + Key? key, }) : super(key: key); @override @@ -371,7 +371,7 @@ Widget defaultToggleStyleButtonBuilder( class SelectHeaderStyleButton extends StatefulWidget { final QuillController controller; - const SelectHeaderStyleButton({Key? key, required this.controller}) + const SelectHeaderStyleButton({required this.controller, Key? key}) : super(key: key); @override @@ -494,14 +494,14 @@ class ImageButton extends StatefulWidget { final ImageSource imageSource; - ImageButton( - {Key? key, - required this.icon, - required this.controller, - required this.imageSource, - this.onImagePickCallback, - this.imagePickImpl}) - : super(key: key); + ImageButton({ + required this.icon, + required this.controller, + required this.imageSource, + this.onImagePickCallback, + this.imagePickImpl, + Key? key, + }) : super(key: key); @override _ImageButtonState createState() => _ImageButtonState(); @@ -600,12 +600,12 @@ class ColorButton extends StatefulWidget { final bool background; final QuillController controller; - ColorButton( - {Key? key, - required this.icon, - required this.controller, - required this.background}) - : super(key: key); + ColorButton({ + required this.icon, + required this.controller, + required this.background, + Key? key, + }) : super(key: key); @override _ColorButtonState createState() => _ColorButtonState(); @@ -738,12 +738,12 @@ class HistoryButton extends StatefulWidget { final bool undo; final QuillController controller; - HistoryButton( - {Key? key, - required this.icon, - required this.controller, - required this.undo}) - : super(key: key); + HistoryButton({ + required this.icon, + required this.controller, + required this.undo, + Key? key, + }) : super(key: key); @override _HistoryButtonState createState() => _HistoryButtonState(); @@ -810,12 +810,12 @@ class IndentButton extends StatefulWidget { final QuillController controller; final bool isIncrease; - IndentButton( - {Key? key, - required this.icon, - required this.controller, - required this.isIncrease}) - : super(key: key); + IndentButton({ + required this.icon, + required this.controller, + required this.isIncrease, + Key? key, + }) : super(key: key); @override _IndentButtonState createState() => _IndentButtonState(); @@ -865,7 +865,7 @@ class ClearFormatButton extends StatefulWidget { final QuillController controller; - ClearFormatButton({Key? key, required this.icon, required this.controller}) + ClearFormatButton({required this.icon, required this.controller, Key? key}) : super(key: key); @override @@ -896,30 +896,31 @@ class _ClearFormatButtonState extends State { class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { final List children; - const QuillToolbar({Key? key, required this.children}) : super(key: key); - - factory QuillToolbar.basic( - {Key? key, - required QuillController controller, - double toolbarIconSize = 18.0, - bool showBoldButton = true, - bool showItalicButton = true, - bool showUnderLineButton = true, - bool showStrikeThrough = true, - bool showColorButton = true, - bool showBackgroundColorButton = true, - bool showClearFormat = true, - bool showHeaderStyle = true, - bool showListNumbers = true, - bool showListBullets = true, - bool showListCheck = true, - bool showCodeBlock = true, - bool showQuote = true, - bool showIndent = true, - bool showLink = true, - bool showHistory = true, - bool showHorizontalRule = false, - OnImagePickCallback? onImagePickCallback}) { + const QuillToolbar({required this.children, Key? key}) : super(key: key); + + factory QuillToolbar.basic({ + required QuillController controller, + double toolbarIconSize = 18.0, + bool showBoldButton = true, + bool showItalicButton = true, + bool showUnderLineButton = true, + bool showStrikeThrough = true, + bool showColorButton = true, + bool showBackgroundColorButton = true, + bool showClearFormat = true, + bool showHeaderStyle = true, + bool showListNumbers = true, + bool showListBullets = true, + bool showListCheck = true, + bool showCodeBlock = true, + bool showQuote = true, + bool showIndent = true, + bool showLink = true, + bool showHistory = true, + bool showHorizontalRule = false, + OnImagePickCallback? onImagePickCallback, + Key? key, + }) { iconSize = toolbarIconSize; return QuillToolbar(key: key, children: [ Visibility( @@ -1146,13 +1147,13 @@ class QuillIconButton extends StatelessWidget { final double highlightElevation; const QuillIconButton({ - Key? key, required this.onPressed, this.icon, this.size = 40, this.fillColor, this.hoverElevation = 1, this.highlightElevation = 1, + Key? key, }) : super(key: key); @override @@ -1184,15 +1185,15 @@ class QuillDropdownButton extends StatefulWidget { final ValueChanged onSelected; const QuillDropdownButton({ - Key? key, - this.height = 40, - this.fillColor, - this.hoverElevation = 1, - this.highlightElevation = 1, required this.child, required this.initialValue, required this.items, required this.onSelected, + this.height = 40, + this.fillColor, + this.hoverElevation = 1, + this.highlightElevation = 1, + Key? key, }) : super(key: key); @override From ace4fd4deb929e37128f78252a9d5310dafe7d33 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Sat, 27 Mar 2021 10:46:52 -0700 Subject: [PATCH 3/6] Fix selection not working --- lib/widgets/toolbar.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 8eeb35ae..514946a3 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -1248,6 +1248,7 @@ class _QuillDropdownButtonState extends State> { // if (widget.onCanceled != null) widget.onCanceled(); return null; } + widget.onSelected(newValue); }); } From 1cf37c1824197f4907cf820705de07cf92c77b2d Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Sat, 27 Mar 2021 18:57:40 +0100 Subject: [PATCH 4/6] Rebuild editor when keyboard is already open (#111) * Rebuild editor when keyboard is already open If the keyboard is already open, but the editor thinks that the keyboard is not open, the text will not be updated when writing. This can easily happen if one has a `TabBarView` with two children, each with an `QuillEditor`, see the code for an example:
Example ```dart import 'package:flutter/material.dart'; import 'package:flutter_quill/widgets/controller.dart'; import 'package:flutter_quill/widgets/editor.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { late QuillController _controller1; late QuillController _controller2; @override void initState() { _controller1 = QuillController.basic(); _controller2 = QuillController.basic(); super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: DefaultTabController( length: 2, child: Scaffold( appBar: AppBar( title: Text('Flutter Quill tabs demo'), bottom: TabBar( tabs: [ Tab(text: 'First'), Tab(text: 'Second'), ], ), ), body: TabBarView( children: [ QuillEditor.basic(controller: _controller1, readOnly: false), QuillEditor.basic(controller: _controller2, readOnly: false), ], ), ), ), ); } }
Video
* Add documentation comment for getOffsetToRevealCursor * Set initial keyboard visibility --- lib/widgets/editor.dart | 5 +++++ lib/widgets/raw_editor.dart | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index ef2221c0..0913ffe0 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -864,6 +864,11 @@ class RenderEditor extends RenderEditableContainerBox ); } + /// Returns the y-offset of the editor at which [selection] is visible. + /// + /// The offset is the distance from the top of the editor and is the minimum + /// from the current scroll position until [selection] becomes visible. + /// Returns null if [selection] is already visible. double? getOffsetToRevealCursor( double viewportHeight, double scrollOffset, double offsetInViewport) { List endpoints = getEndpointsForSelection(selection); diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 11c9c568..73a17e25 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -700,6 +700,7 @@ class RawEditorState extends EditorState _keyboardVisible = true; } else { _keyboardVisibilityController = KeyboardVisibilityController(); + _keyboardVisible = _keyboardVisibilityController!.isVisible; _keyboardVisibilitySubscription = _keyboardVisibilityController?.onChange.listen((bool visible) { _keyboardVisible = visible; From d6b21586a41e57e74309ad604da97d4d2185c1aa Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Sat, 27 Mar 2021 19:08:34 +0100 Subject: [PATCH 5/6] Prefer const constructors (#116) --- analysis_options.yaml | 1 + lib/models/documents/history.dart | 2 +- lib/models/quill_delta.dart | 2 +- lib/models/rules/insert.dart | 2 +- lib/models/rules/rule.dart | 30 ++++++++++----------- lib/widgets/controller.dart | 7 +++-- lib/widgets/cursor.dart | 10 ++++--- lib/widgets/default_styles.dart | 44 +++++++++++++++---------------- lib/widgets/proxy.dart | 2 +- lib/widgets/raw_editor.dart | 32 +++++++++++----------- lib/widgets/text_block.dart | 9 ++++--- lib/widgets/text_line.dart | 7 ++--- lib/widgets/text_selection.dart | 17 ++++++------ lib/widgets/toolbar.dart | 36 ++++++++++++------------- 14 files changed, 106 insertions(+), 95 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 451c1799..74ce67a1 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 32e780c9..6d89b389 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 a1fe1f0f..72d26846 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 62585ec3..5ea7f215 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 bff58b44..8141aaf3 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 f613af69..da876bf1 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 8fa45437..4195d947 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 30b6b7fe..2e3ad80c 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 f3e38c4e..7b918b9d 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 73a17e25..9ba3587a 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 ef226b1e..7edb3add 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 82418ca3..73090786 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 99f381fa..366c7d0b 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 514946a3..bff3ff9e 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) ], ), ), From dfeae914b169a65b92ef987aa2be0e70540ba58d Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Sat, 27 Mar 2021 19:17:22 +0100 Subject: [PATCH 6/6] Prefer const constructors in immutables (#117) --- analysis_options.yaml | 1 + lib/widgets/default_styles.dart | 2 +- lib/widgets/editor.dart | 2 +- lib/widgets/proxy.dart | 6 +++--- lib/widgets/raw_editor.dart | 2 +- lib/widgets/text_block.dart | 2 +- lib/widgets/text_line.dart | 2 +- lib/widgets/toolbar.dart | 15 ++++++++------- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 74ce67a1..8f139635 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -11,3 +11,4 @@ linter: - avoid_print - avoid_redundant_argument_values - prefer_const_constructors + - prefer_const_constructors_in_immutables diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 2e3ad80c..5583307d 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -5,7 +5,7 @@ import 'package:tuple/tuple.dart'; class QuillStyles extends InheritedWidget { final DefaultStyles data; - QuillStyles({ + const QuillStyles({ required this.data, required Widget child, Key? key, diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 0913ffe0..84a4c9d5 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -169,7 +169,7 @@ class QuillEditor extends StatefulWidget { final ValueChanged? onLaunchUrl; final EmbedBuilder embedBuilder; - QuillEditor( + const QuillEditor( {required this.controller, required this.focusNode, required this.scrollController, diff --git a/lib/widgets/proxy.dart b/lib/widgets/proxy.dart index 7b918b9d..8717d12a 100644 --- a/lib/widgets/proxy.dart +++ b/lib/widgets/proxy.dart @@ -7,7 +7,7 @@ class BaselineProxy extends SingleChildRenderObjectWidget { final TextStyle? textStyle; final EdgeInsets? padding; - BaselineProxy({Key? key, Widget? child, this.textStyle, this.padding}) + const BaselineProxy({Key? key, Widget? child, this.textStyle, this.padding}) : super(key: key, child: child); @override @@ -73,7 +73,7 @@ class RenderBaselineProxy extends RenderProxyBox { } class EmbedProxy extends SingleChildRenderObjectWidget { - EmbedProxy(Widget child) : super(child: child); + const EmbedProxy(Widget child) : super(child: child); @override RenderEmbedProxy createRenderObject(BuildContext context) => @@ -145,7 +145,7 @@ class RichTextProxy extends SingleChildRenderObjectWidget { textHeightBehavior); } - RichTextProxy( + const RichTextProxy( RichText child, this.textStyle, this.textAlign, diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 9ba3587a..b922f2be 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -55,7 +55,7 @@ class RawEditor extends StatefulWidget { final ScrollPhysics? scrollPhysics; final EmbedBuilder embedBuilder; - RawEditor( + const RawEditor( Key key, this.controller, this.focusNode, diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index 7edb3add..92b82ae5 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -61,7 +61,7 @@ class EditableTextBlock extends StatelessWidget { final CursorCont cursorCont; final Map indentLevelCounts; - EditableTextBlock( + const EditableTextBlock( this.block, this.textDirection, this.verticalSpacing, diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 73090786..1b2be8e6 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -206,7 +206,7 @@ class EditableTextLine extends RenderObjectWidget { final double devicePixelRatio; final CursorCont cursorCont; - EditableTextLine( + const EditableTextLine( this.line, this.leading, this.body, diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index bff3ff9e..47a490d8 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -182,7 +182,7 @@ class ToggleStyleButton extends StatefulWidget { final ToggleStyleButtonBuilder childBuilder; - ToggleStyleButton({ + const ToggleStyleButton({ required this.attribute, required this.icon, required this.controller, @@ -266,7 +266,7 @@ class ToggleCheckListButton extends StatefulWidget { final Attribute attribute; - ToggleCheckListButton({ + const ToggleCheckListButton({ required this.icon, required this.controller, required this.attribute, @@ -494,7 +494,7 @@ class ImageButton extends StatefulWidget { final ImageSource imageSource; - ImageButton({ + const ImageButton({ required this.icon, required this.controller, required this.imageSource, @@ -600,7 +600,7 @@ class ColorButton extends StatefulWidget { final bool background; final QuillController controller; - ColorButton({ + const ColorButton({ required this.icon, required this.controller, required this.background, @@ -738,7 +738,7 @@ class HistoryButton extends StatefulWidget { final bool undo; final QuillController controller; - HistoryButton({ + const HistoryButton({ required this.icon, required this.controller, required this.undo, @@ -810,7 +810,7 @@ class IndentButton extends StatefulWidget { final QuillController controller; final bool isIncrease; - IndentButton({ + const IndentButton({ required this.icon, required this.controller, required this.isIncrease, @@ -865,7 +865,8 @@ class ClearFormatButton extends StatefulWidget { final QuillController controller; - ClearFormatButton({required this.icon, required this.controller, Key? key}) + const ClearFormatButton( + {required this.icon, required this.controller, Key? key,}) : super(key: key); @override