Sdk: Analyzer: convert StatelessWidget to StatefulWidget

Created on 10 Jan 2018  路  4Comments  路  Source: dart-lang/sdk

Not sure if this is the right component to file this, but it would be nice to have an automated refactor mechanism to convert an existing StatelessWidget and split it into a StatefulWidget and a State with one click.

P2 analyzer-refactoring analyzer-server area-analyzer type-enhancement

Most helpful comment

class KeyRow extends StatelessWidget {
  const KeyRow(this.keys);

  final List<Widget> keys;

  @override
  Widget build(BuildContext context) {
    return new Expanded(
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: keys
      )
    );
  }
}

Is converted into:

class KeyRow extends StatefulWidget {
  const KeyRow(this.keys);

  final List<Widget> keys;

  @override
  KeyRowState createState() {
    return new KeyRowState();
  }
}

class KeyRowState extends State<KeyRow> {
  @override
  Widget build(BuildContext context) {
    return new Expanded(
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: widget.keys
      )
    );
  }
}

All 4 comments

I think there should be an anaylzer plugin for Flutter like https://github.com/dart-lang/angular_analyzer_plugin

@devoncarew @scheglov

class KeyRow extends StatelessWidget {
  const KeyRow(this.keys);

  final List<Widget> keys;

  @override
  Widget build(BuildContext context) {
    return new Expanded(
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: keys
      )
    );
  }
}

Is converted into:

class KeyRow extends StatefulWidget {
  const KeyRow(this.keys);

  final List<Widget> keys;

  @override
  KeyRowState createState() {
    return new KeyRowState();
  }
}

class KeyRowState extends State<KeyRow> {
  @override
  Widget build(BuildContext context) {
    return new Expanded(
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: widget.keys
      )
    );
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gspencergoog picture gspencergoog  路  3Comments

DartBot picture DartBot  路  3Comments

matanlurey picture matanlurey  路  3Comments

brooth picture brooth  路  3Comments

jmesserly picture jmesserly  路  3Comments