Skip to content

Commit

Permalink
Prefer const constructors (singerdmx#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
friebetill committed Mar 27, 2021
1 parent 1cf37c1 commit d6b2158
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 95 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ linter:
- always_put_required_named_parameters_first
- avoid_print
- avoid_redundant_argument_values
- prefer_const_constructors
2 changes: 1 addition & 1 deletion lib/models/documents/history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class History {

Tuple2 _change(Document doc, List<Delta> source, List<Delta> dest) {
if (source.isEmpty) {
return Tuple2(false, 0);
return const Tuple2(false, 0);
}
Delta delta = source.removeLast();
// look for insert or delete
Expand Down
2 changes: 1 addition & 1 deletion lib/models/quill_delta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Delta {
if (other is! Delta) return false;
Delta typedOther = other;
final comparator =
ListEquality<Operation>(const DefaultEquality<Operation>());
const ListEquality<Operation>(DefaultEquality<Operation>());
return comparator.equals(_operations, typedOther._operations);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/models/rules/insert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,5 @@ Tuple2<Operation?, int?> _getNextNewLine(DeltaIterator iterator) {
return Tuple2(op, skipped);
}
}
return Tuple2(null, null);
return const Tuple2(null, null);
}
30 changes: 15 additions & 15 deletions lib/models/rules/rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ abstract class Rule {
class Rules {
final List<Rule> _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);
Expand Down
7 changes: 5 additions & 2 deletions lib/widgets/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,20 @@ 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() {
_targetCursorVisibility = true;
_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);
}
}

Expand Down
44 changes: 22 additions & 22 deletions lib/widgets/default_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DefaultStyles {
fontSize: 16.0,
height: 1.3,
);
Tuple2<double, double> baseSpacing = Tuple2(6.0, 0);
Tuple2<double, double> baseSpacing = const Tuple2(6.0, 0);
String fontFamily;
switch (themeData.platform) {
case TargetPlatform.iOS:
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
32 changes: 17 additions & 15 deletions lib/widgets/raw_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand All @@ -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,
);
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lib/widgets/text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EditableTextBlock extends StatelessWidget {
block,
textDirection,
verticalSpacing as Tuple2<double, double>,
_getDecorationForBlock(block, defaultStyles) ?? BoxDecoration(),
_getDecorationForBlock(block, defaultStyles) ?? const BoxDecoration(),
contentPadding,
_buildChildren(context, indentLevelCounts));
}
Expand Down Expand Up @@ -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() +
Expand Down Expand Up @@ -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),
);
}
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions lib/widgets/text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, TextStyle?> m = {
Attribute.bold.key: defaultStyles.bold,
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit d6b2158

Please sign in to comment.