Have a class like this
class Test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container();
}
}
Now hover your cursor to StatelessWidget and use option + return, IDE will show you to convert this class to a Stateful Widget. Tap that option and following code is generated for you.
class Test extends StatefulWidget {
@override
TestState createState() {
return new TestState(); // there is no need of new here, we are already using Dart 2.0 +
}
}
class TestState extends State<Test> {
@override
Widget build(BuildContext context) {
return Container();
}
}
[✓] Flutter (Channel beta, v1.0.1-pre.1, on Mac OS X 10.14 18A389, locale en-GB)
• Flutter version 1.0.1-pre.1 at /flutter
• Framework revision 2f60afca7a (2 weeks ago), 2018-12-29 14:11:09 +0530
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at /Users/chocolate/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
• ios-deploy 2.0.0
• CocoaPods version 1.5.3
[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• No issues found!
Thanks for the report!
@scheglov : do we support optional new in Flutter codegeneration in general?
No, we should never generate new, Flutter or not.
I will fix this.
Thanks @scheglov !
Most helpful comment
https://dart-review.googlesource.com/c/sdk/+/89720