diff --git a/analysis_options.yaml b/analysis_options.yaml index ff3e70e7..74ce67a1 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,5 +7,7 @@ analyzer: unsafe_html: ignore linter: rules: + - always_put_required_named_parameters_first - avoid_print + - avoid_redundant_argument_values - prefer_const_constructors 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 ec0c68cc..72d26846 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 70a77942..da876bf1 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -33,7 +33,6 @@ class QuillController extends ChangeNotifier { TextEditingValue get plainTextEditingValue => TextEditingValue( text: document.toPlainText(), selection: selection, - composing: TextRange.empty, ); Style getSelectionStyle() { diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 2b83ec8e..2e3ad80c 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 305a58c8..0913ffe0 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, @@ -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 { @@ -866,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 eb35ed82..9ba3587a 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, @@ -702,6 +700,7 @@ class RawEditorState extends EditorState _keyboardVisible = true; } else { _keyboardVisibilityController = KeyboardVisibilityController(); + _keyboardVisible = _keyboardVisibilityController!.isVisible; _keyboardVisibilitySubscription = _keyboardVisibilityController?.onChange.listen((bool visible) { _keyboardVisible = visible; 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 15e80603..7edb3add 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, @@ -559,7 +559,6 @@ class _NumberPoint extends StatelessWidget { final double padding; const _NumberPoint({ - Key? key, required this.index, required this.indentLevelCounts, required this.count, @@ -568,6 +567,7 @@ class _NumberPoint extends StatelessWidget { required this.attrs, this.withDot = true, this.padding = 0.0, + Key? key, }) : super(key: key); @override @@ -624,7 +624,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) { @@ -657,9 +657,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 f6df80ff..73090786 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) { diff --git a/lib/widgets/text_selection.dart b/lib/widgets/text_selection.dart index 162d457f..366c7d0b 100644 --- a/lib/widgets/text_selection.dart +++ b/lib/widgets/text_selection.dart @@ -246,7 +246,6 @@ class EditorTextSelectionOverlay { class _TextSelectionHandleOverlay extends StatefulWidget { const _TextSelectionHandleOverlay({ - Key? key, required this.selection, required this.position, required this.startHandleLayerLink, @@ -256,6 +255,7 @@ class _TextSelectionHandleOverlay extends StatefulWidget { required this.onSelectionHandleTapped, required this.selectionControls, this.dragStartBehavior = DragStartBehavior.start, + Key? key, }) : super(key: key); final TextSelection selection; @@ -469,7 +469,7 @@ class _TextSelectionHandleOverlayState class EditorTextSelectionGestureDetector extends StatefulWidget { const EditorTextSelectionGestureDetector({ - Key? key, + required this.child, this.onTapDown, this.onForcePressStart, this.onForcePressEnd, @@ -483,7 +483,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 f3caa6c9..bff3ff9e 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(); @@ -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, @@ -601,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(); @@ -739,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(); @@ -811,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(); @@ -866,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 @@ -897,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( @@ -1147,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 @@ -1163,7 +1163,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, @@ -1186,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 @@ -1209,7 +1208,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, @@ -1250,6 +1248,7 @@ class _QuillDropdownButtonState extends State> { // if (widget.onCanceled != null) widget.onCanceled(); return null; } + widget.onSelected(newValue); }); }