ReplaceWidget class

Replaces the type name of a widget, such as MaterialApp with MaterialApp.router, keeping its arguments.

The scope narrows with className and methodName: with both, only that method of that class is searched; with just className, the whole class; with just methodName, the methods and top-level functions of that name; with neither, the whole file. Every instance of fromWidget in the scope, nested ones included, gets toWidget in place of its type name, so const, an import prefix and the arguments stay as written.

Without a matching widget nothing is edited, but the whole file is reformatted either way. Running it again changes nothing as long as toWidget doesn't match fromWidget itself, as MaterialApp.router doesn't match MaterialApp.

Inheritance

Constructors

ReplaceWidget({required String file, required String fromWidget, required String toWidget, String? className, String? methodName})
Creates a contribution that turns fromWidget into toWidget.
const

Properties

className → String?
The class to limit the search to, if any.
final
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
fromWidget → String
The name of the widget to replace, such as MaterialApp.
final
hashCode → int
The hash code for this object.
no setterinherited
methodName → String?
The method to limit the search to, if any. Without className, top-level functions of that name are searched too.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
toWidget → String
The source that takes the place of the type name, such as MaterialApp.router. PatchEngine renders its placeholders.
final

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