Remove unnecessary checks

pull/87/head
Miller Adulu 4 years ago
parent cff918a88e
commit b14c1dc9dc
  1. 3
      lib/models/documents/nodes/embed.dart
  2. 4
      lib/models/documents/nodes/leaf.dart
  3. 3
      lib/models/documents/nodes/node.dart
  4. 9
      lib/models/quill_delta.dart
  5. 4
      lib/models/rules/insert.dart
  6. 2
      lib/models/rules/rule.dart
  7. 13
      lib/widgets/controller.dart
  8. 3
      lib/widgets/default_styles.dart
  9. 2
      lib/widgets/delegate.dart
  10. 38
      lib/widgets/editor.dart
  11. 4
      lib/widgets/keyboard_listener.dart
  12. 2
      lib/widgets/raw_editor.dart
  13. 21
      lib/widgets/text_block.dart
  14. 23
      lib/widgets/text_selection.dart
  15. 33
      lib/widgets/toolbar.dart

@ -3,8 +3,7 @@ class Embeddable {
final dynamic data;
Embeddable(this.type, this.data)
: assert(type != null),
assert(data != null);
;
Map<String, dynamic> toJson() {
Map<String, String> m = {type: data};

@ -27,7 +27,7 @@ abstract class Leaf extends Node {
@override
void applyStyle(Style value) {
assert(
value != null && (value.isInline || value.isIgnored || value.isEmpty),
(value.isInline || value.isIgnored || value.isEmpty),
'Unable to apply Style to leaf: $value');
super.applyStyle(value);
}
@ -52,7 +52,7 @@ abstract class Leaf extends Node {
@override
insert(int index, Object data, Style? style) {
assert(data != null && index >= 0 && index <= length);
assert(index >= 0 && index <= length);
Leaf node = Leaf(data);
if (index < length) {
splitAt(index)!.insertBefore(node);

@ -19,9 +19,6 @@ abstract class Node extends LinkedListEntry<Node> {
}
void applyStyle(Style value) {
if (value == null) {
throw ArgumentError('null value');
}
_style = _style.mergeAll(value);
}

@ -51,7 +51,7 @@ class Operation {
final Map<String, dynamic>? _attributes;
Operation._(this.key, this.length, this.data, Map? attributes)
: assert(key != null && length != null && data != null),
:
assert(_validKeys.contains(key), 'Invalid operation key "$key".'),
assert(() {
if (key != Operation.insertKey) return true;
@ -243,7 +243,7 @@ class Delta {
int _modificationCount = 0;
Delta._(List<Operation> operations)
: assert(operations != null),
:
_operations = operations;
/// Creates new empty [Delta].
@ -312,7 +312,6 @@ class Delta {
/// Insert [data] at current position.
void insert(dynamic data, [Map<String, dynamic>? attributes]) {
assert(data != null);
if (data is String && data.isEmpty) return; // no-op
push(Operation.insert(data, attributes));
}
@ -326,7 +325,7 @@ class Delta {
void _mergeWithTail(Operation operation) {
assert(isNotEmpty);
assert(operation != null && last.key == operation.key);
assert(last.key == operation.key);
assert(operation.data is String && last.data is String);
final length = operation.length! + last.length!;
@ -640,8 +639,6 @@ class DeltaIterator {
/// Optional [length] specifies maximum length of operation to return. Note
/// that actual length of returned operation may be less than specified value.
Operation next([int length = 4294967296]) {
assert(length != null);
if (_modificationCount != delta._modificationCount) {
throw ConcurrentModificationError(delta);
}

@ -341,9 +341,7 @@ class PreserveInlineStylesRule extends InsertRule {
..retain(index)
..insert(text, attributes.isEmpty ? null : attributes);
Operation next = itr.next();
if (next == null) {
return delta;
}
Map<String, dynamic> nextAttributes =
next.attributes ?? const <String, dynamic>{};
if (!nextAttributes.containsKey(Attribute.link.key)) {

@ -13,8 +13,6 @@ abstract class Rule {
Delta? apply(Delta document, int index,
{int? len, Object? data, Attribute? attribute}) {
assert(document != null);
assert(index != null);
validateArgs(len, data, attribute);
return applyRule(document, index,
len: len, data: data, attribute: attribute);

@ -15,8 +15,7 @@ class QuillController extends ChangeNotifier {
Style toggledStyle = Style();
QuillController({required this.document, required this.selection})
: assert(document != null),
assert(selection != null);
;
factory QuillController.basic() {
return QuillController(
@ -86,7 +85,7 @@ class QuillController extends ChangeNotifier {
print('document.replace failed: $e');
throw e;
}
bool shouldRetainDelta = delta != null &&
bool shouldRetainDelta =
toggledStyle.isNotEmpty &&
delta.isNotEmpty &&
delta.length <= 2 &&
@ -165,9 +164,7 @@ class QuillController extends ChangeNotifier {
if (delta.isNotEmpty) {
document.compose(delta, source);
}
if (textSelection != null) {
_updateSelection(textSelection, source);
} else {
textSelection = selection.copyWith(
baseOffset:
delta.transformPosition(selection.baseOffset, force: false),
@ -176,7 +173,7 @@ class QuillController extends ChangeNotifier {
if (selection != textSelection) {
_updateSelection(textSelection, source);
}
}
notifyListeners();
}
@ -187,8 +184,6 @@ class QuillController extends ChangeNotifier {
}
_updateSelection(TextSelection textSelection, ChangeSource source) {
assert(textSelection != null);
assert(source != null);
selection = textSelection;
int end = document.length - 1;
selection = selection.copyWith(

@ -9,8 +9,7 @@ class QuillStyles extends InheritedWidget {
Key? key,
required this.data,
required Widget child,
}) : assert(data != null),
assert(child != null),
}) :
super(key: key, child: child);
@override

@ -22,7 +22,7 @@ class EditorTextSelectionGestureDetectorBuilder {
bool shouldShowSelectionToolbar = true;
EditorTextSelectionGestureDetectorBuilder(this.delegate)
: assert(delegate != null);
;
EditorState? getEditor() {
return delegate.getEditableTextKey().currentState;

@ -182,13 +182,7 @@ class QuillEditor extends StatefulWidget {
this.onLaunchUrl,
this.embedBuilder =
kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder})
: assert(controller != null),
assert(scrollController != null),
assert(scrollable != null),
assert(focusNode != null),
assert(autoFocus != null),
assert(readOnly != null),
assert(embedBuilder != null);
;
factory QuillEditor.basic(
{required QuillController controller, required bool readOnly}) {
@ -559,10 +553,7 @@ class RenderEditor extends RenderEditableContainerBox
this._startHandleLayerLink,
this._endHandleLayerLink,
EdgeInsets floatingCursorAddedMargin)
: assert(document != null),
assert(textDirection != null),
assert(_hasFocus != null),
assert(floatingCursorAddedMargin != null),
:
super(
children,
document.root,
@ -571,7 +562,6 @@ class RenderEditor extends RenderEditableContainerBox
);
setDocument(Document doc) {
assert(doc != null);
if (document == doc) {
return;
}
@ -580,7 +570,6 @@ class RenderEditor extends RenderEditableContainerBox
}
setHasFocus(bool h) {
assert(h != null);
if (_hasFocus == h) {
return;
}
@ -615,7 +604,6 @@ class RenderEditor extends RenderEditableContainerBox
@override
List<TextSelectionPoint> getEndpointsForSelection(
TextSelection textSelection) {
assert(constraints != null);
if (textSelection.isCollapsed) {
RenderEditableBox child = childAtPosition(textSelection.extent);
@ -686,11 +674,6 @@ class RenderEditor extends RenderEditableContainerBox
Offset? to,
SelectionChangedCause cause,
) {
assert(cause != null);
assert(from != null);
if (onSelectionChanged == null) {
return;
}
TextPosition firstPosition = getPositionForOffset(from);
TextSelection firstWord = selectWordAtPosition(firstPosition);
TextSelection lastWord =
@ -718,18 +701,12 @@ class RenderEditor extends RenderEditableContainerBox
!focusingEmpty) {
return;
}
if (onSelectionChanged != null) {
onSelectionChanged(nextSelection, cause);
}
}
@override
selectWordEdge(SelectionChangedCause cause) {
assert(cause != null);
assert(_lastTapDownPosition != null);
if (onSelectionChanged == null) {
return;
}
TextPosition position = getPositionForOffset(_lastTapDownPosition!);
RenderEditableBox child = childAtPosition(position);
int nodeOffset = child.getContainer().getOffset();
@ -763,11 +740,6 @@ class RenderEditor extends RenderEditableContainerBox
Offset? to,
SelectionChangedCause cause,
) {
assert(cause != null);
assert(from != null);
if (onSelectionChanged == null) {
return;
}
TextPosition fromPosition = getPositionForOffset(from);
TextPosition? toPosition = to == null ? null : getPositionForOffset(to);
@ -932,9 +904,7 @@ class RenderEditableContainerBox extends RenderBox
RenderEditableContainerBox(List<RenderEditableBox>? children, this._container,
this.textDirection, this._padding)
: assert(_container != null),
assert(textDirection != null),
assert(_padding != null),
:
assert(_padding.isNonNegative) {
addAll(children);
}
@ -944,7 +914,6 @@ class RenderEditableContainerBox extends RenderBox
}
setContainer(containerNode.Container c) {
assert(c != null);
if (_container == c) {
return;
}
@ -955,7 +924,6 @@ class RenderEditableContainerBox extends RenderBox
EdgeInsetsGeometry getPadding() => _padding;
setPadding(EdgeInsetsGeometry value) {
assert(value != null);
assert(value.isNonNegative);
if (_padding == value) {
return;

@ -59,9 +59,7 @@ class KeyboardListener {
};
KeyboardListener(this.onCursorMove, this.onShortcut, this.onDelete)
: assert(onCursorMove != null),
assert(onShortcut != null),
assert(onDelete != null);
;
bool handleRawKeyEvent(RawKeyEvent event) {
if (event is! RawKeyDownEvent) {

@ -907,7 +907,6 @@ class RawEditorState extends EditorState
_selectionOverlay?.hide();
_selectionOverlay = null;
if (widget.selectionCtrls != null) {
_selectionOverlay = EditorTextSelectionOverlay(
textEditingValue,
false,
@ -926,7 +925,6 @@ class RawEditorState extends EditorState
_selectionOverlay!.showHandles();
}
}
}
_handleFocusChanged() {
openOrCloseConnection();

@ -74,9 +74,7 @@ class EditableTextBlock extends StatelessWidget {
this.embedBuilder,
this.cursorCont,
this.indentLevelCounts)
: assert(hasFocus != null),
assert(embedBuilder != null),
assert(cursorCont != null);
;
@override
Widget build(BuildContext context) {
@ -263,11 +261,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
required Decoration decoration,
ImageConfiguration configuration = ImageConfiguration.empty,
EdgeInsets contentPadding = EdgeInsets.zero,
}) : assert(block != null),
assert(textDirection != null),
assert(decoration != null),
assert(padding != null),
assert(contentPadding != null),
}) :
_decoration = decoration,
_configuration = configuration,
_savedPadding = padding,
@ -283,7 +277,6 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
EdgeInsets _contentPadding;
set contentPadding(EdgeInsets value) {
assert(value != null);
if (_contentPadding == value) return;
_contentPadding = value;
super.setPadding(_savedPadding.add(_contentPadding));
@ -301,7 +294,6 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
Decoration _decoration;
set decoration(Decoration value) {
assert(value != null);
if (value == _decoration) return;
_painter?.dispose();
_painter = null;
@ -313,7 +305,6 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
ImageConfiguration _configuration;
set configuration(ImageConfiguration value) {
assert(value != null);
if (value == _configuration) return;
_configuration = value;
markNeedsPaint();
@ -495,8 +486,6 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
}
_paintDecoration(PaintingContext context, Offset offset) {
assert(size.width != null);
assert(size.height != null);
_painter ??= _decoration.createBoxPainter(markNeedsPaint);
EdgeInsets decorationPadding = resolvedPadding! - _contentPadding;
@ -531,11 +520,7 @@ class _EditableBlock extends MultiChildRenderObjectWidget {
_EditableBlock(this.block, this.textDirection, this.padding, this.decoration,
this.contentPadding, List<Widget> children)
: assert(block != null),
assert(textDirection != null),
assert(padding != null),
assert(decoration != null),
assert(children != null),
:
super(children: children);
EdgeInsets get _padding =>

@ -55,13 +55,9 @@ class EditorTextSelectionOverlay {
this.dragStartBehavior,
this.onSelectionHandleTapped,
this.clipboardStatus)
: assert(value != null),
assert(context != null),
assert(handlesVisible != null) {
{
OverlayState overlay = Overlay.of(context, rootOverlay: true)!;
assert(
overlay != null,
);
_toolbarController = AnimationController(
duration: Duration(milliseconds: 150), vsync: overlay);
}
@ -71,7 +67,6 @@ class EditorTextSelectionOverlay {
Animation<double> get _toolbarOpacity => _toolbarController.view;
setHandlesVisible(bool visible) {
assert(visible != null);
if (handlesVisible == visible) {
return;
}
@ -111,8 +106,8 @@ class EditorTextSelectionOverlay {
Widget _buildHandle(
BuildContext context, _TextSelectionHandlePosition position) {
if ((_selection.isCollapsed &&
position == _TextSelectionHandlePosition.END) ||
selectionCtrls == null) {
position == _TextSelectionHandlePosition.END)
) {
return Container();
}
return Visibility(
@ -167,9 +162,7 @@ class EditorTextSelectionOverlay {
}
Widget _buildToolbar(BuildContext context) {
if (selectionCtrls == null) {
return Container();
}
List<TextSelectionPoint> endpoints =
renderObject!.getEndpointsForSelection(_selection);
@ -289,7 +282,6 @@ class _TextSelectionHandleOverlay extends StatefulWidget {
case _TextSelectionHandlePosition.END:
return renderObject!.selectionEndInViewport;
}
return null;
}
}
@ -468,14 +460,12 @@ class _TextSelectionHandleOverlayState
) {
if (widget.selection.isCollapsed) return TextSelectionHandleType.collapsed;
assert(textDirection != null);
switch (textDirection) {
case TextDirection.ltr:
return ltrType;
case TextDirection.rtl:
return rtlType;
}
return null;
}
}
@ -496,7 +486,7 @@ class EditorTextSelectionGestureDetector extends StatefulWidget {
this.onDragSelectionEnd,
this.behavior,
required this.child,
}) : assert(child != null),
}) :
super(key: key);
final GestureTapDownCallback? onTapDown;
@ -660,7 +650,6 @@ class _EditorTextSelectionGestureDetectorState
}
bool _isWithinDoubleTapTolerance(Offset secondTapOffset) {
assert(secondTapOffset != null);
if (_lastTapOffset == null) {
return false;
}

@ -186,11 +186,7 @@ class ToggleStyleButton extends StatefulWidget {
required this.icon,
required this.controller,
this.childBuilder = defaultToggleStyleButtonBuilder,
}) : assert(attribute.value != null),
assert(icon != null),
assert(controller != null),
assert(childBuilder != null),
super(key: key);
}) : super(key: key);
@override
_ToggleStyleButtonState createState() => _ToggleStyleButtonState();
@ -274,9 +270,7 @@ class ToggleCheckListButton extends StatefulWidget {
required this.controller,
this.childBuilder = defaultToggleStyleButtonBuilder,
required this.attribute,
}) : assert(icon != null),
assert(controller != null),
assert(childBuilder != null),
}) :
super(key: key);
@override
@ -502,8 +496,7 @@ class ImageButton extends StatefulWidget {
required this.controller,
required this.imageSource,
this.onImagePickCallback})
: assert(icon != null),
assert(controller != null),
:
super(key: key);
@override
@ -522,7 +515,6 @@ class _ImageButtonState extends State<ImageButton> {
final File file = File(pickedFile.path);
if (file == null || widget.onImagePickCallback == null) return null;
// We simply return the absolute path to selected file.
try {
String url = await widget.onImagePickCallback!(file);
@ -554,7 +546,6 @@ class _ImageButtonState extends State<ImageButton> {
if (_paths != null) {
File file = File(_fileName);
if (file == null || widget.onImagePickCallback == null) return null;
// We simply return the absolute path to selected file.
try {
String url = await widget.onImagePickCallback!(file);
@ -611,9 +602,7 @@ class ColorButton extends StatefulWidget {
required this.icon,
required this.controller,
required this.background})
: assert(icon != null),
assert(controller != null),
assert(background != null),
:
super(key: key);
@override
@ -752,9 +741,7 @@ class HistoryButton extends StatefulWidget {
required this.icon,
required this.controller,
required this.undo})
: assert(icon != null),
assert(controller != null),
assert(undo != null),
:
super(key: key);
@override
@ -827,9 +814,7 @@ class IndentButton extends StatefulWidget {
required this.icon,
required this.controller,
required this.isIncrease})
: assert(icon != null),
assert(controller != null),
assert(isIncrease != null),
:
super(key: key);
@override
@ -881,8 +866,7 @@ class ClearFormatButton extends StatefulWidget {
final QuillController controller;
ClearFormatButton({Key? key, required this.icon, required this.controller})
: assert(icon != null),
assert(controller != null),
:
super(key: key);
@override
@ -1265,9 +1249,6 @@ class _QuillDropdownButtonState<T> extends State<QuillDropdownButton<T>> {
// if (widget.onCanceled != null) widget.onCanceled();
return null;
}
if (widget.onSelected != null) {
widget.onSelected(newValue);
}
});
}

Loading…
Cancel
Save