Skip to content

dart fix does not apply to factory constructors #47995

@Piinks

Description

@Piinks

I wrote this transform:

version: 1
transforms:
  # Changes made in https://github.com/flutter/flutter/pull/73352
  - title: "Migrate to 'TextButton.icon'"
    date: 2021-01-08
    element:
      uris: [ 'material.dart' ]
      constructor: 'icon'
      inClass: 'FlatButton'
    changes:
      - kind: 'removeParameter'
        name: 'onHighlightChanged'
      - kind: 'removeParameter'
        name: 'textTheme'
      - kind: 'removeParameter'
        name: 'highlightColor'
      - kind: 'removeParameter'
        name: 'colorBrightness'
      - kind: 'replacedBy'
        newElement:
          uris: [ 'material.dart' ]
          constructor: 'icon'
          inClass: 'TextButton'

with the expectation that it would take this snippet of code:

var myIconButton = FlatButton.icon(
    key: UniqueKey(),
    icon: Icon(Icons.ten_k_outlined),
    label: Text('FlatButton'),
    onPressed: (){},
    onLongPress: (){},
    clipBehavior: Clip.hardEdge,
    focusNode: FocusNode(),
    autofocus: true,
    onHighlightChanged: (_) {},
    textTheme: ButtonTextTheme(),
    highlightColor: Colors.blue,
    colorBrightness: Brightness.dark,
  );

and transform it into this:

var myIconButton = TextButton.icon(
    key: UniqueKey(),
    icon: Icon(Icons.ten_k_outlined),
    label: Text('FlatButton'),
    onPressed: (){},
    onLongPress: (){},
    clipBehavior: Clip.hardEdge,
    focusNode: FocusNode(),
    autofocus: true,
  );

but none of the changes are being applied when it is run:

var myIconButton = FlatButton.icon(
    key: UniqueKey(),
    icon: Icon(Icons.ten_k_outlined),
    label: Text('FlatButton'),
    onPressed: (){},
    onLongPress: (){},
    clipBehavior: Clip.hardEdge,
    focusNode: FocusNode(),
    autofocus: true,
    onHighlightChanged: (_) {},
    textTheme: ButtonTextTheme(),
    highlightColor: Colors.blue,
    colorBrightness: Brightness.dark,
  );

There are other FlatButton transforms defined in the file, not sure if they are related. See WIP PR: flutter/flutter#95641

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestdevexp-dartfixIssues with the dartfix packagelegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions