InsertIntoListInFunction class

Adds an element at the start of a list literal passed as a named argument, such as the providers of a MultiProvider built in main.

The target is the first top-level function named function. In its body, the candidates are the lists passed as a listVariableMatch argument, nested ones included, to a call or widget creation that matches parentExpressionMatch; index picks one of them in source order, and insert goes first in it, above the comments that lead up to its first element, with a comma after it.

Throws an Exception when no top-level function is named function, when its body is an expression, or when there is no candidate at index.

When the list already has every element of insert, as the parser prints them, the file is returned as it is, so running it again changes nothing. Comments in the file are kept, but the whole file is reformatted.

Inheritance

Constructors

InsertIntoListInFunction({required String file, required String function, required String listVariableMatch, required String parentExpressionMatch, required String insert, int index = 0})
Creates a contribution that adds insert to a list in function.
const

Properties

dartFormater → DartFormatter
The formatter contributions run over the code they produce.
no setterinherited
file → String
The path of the file to change, relative to the project root.
finalinherited
function → String
The name of the top-level function that holds the list, such as main.
final
hashCode → int
The hash code for this object.
no setterinherited
index → int
Which of the matching lists to change, counting from zero in source order.
final
insert → String
The element to add, such as Provider(create: (_) => Logger()),; the comma after it is added when it has none. PatchEngine renders its placeholders.
final
listVariableMatch → String
The name of the argument that takes the list, such as providers; a trailing colon is ignored.
final
parentExpressionMatch → String
Text that the call or widget creation taking the list, or one around it, has before its arguments, such as MultiProvider.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

apply(String original) → Future<String>
Returns original, the content of file, with this change applied.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited