For example, there is a sample flutter code. This code is not properly formatted.
import 'package:flutter/material.dart';
void main() => runApp(SampleApp());
class SampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Container(
child: const Text('123'),), // this line isn't properly formatted
),
),
);
}
}
I've heard that Android Studio is able to autoformat flutter code when a code saved in editor. In that case, certain conditions had to be respected, - all the commas should be present in code like it is in the above sample code. But I didn't find how to do that. So if it's true (i.e. if it's possible to do that) how to achive that?
Install the Flutter extension (see Editor setup) to get automatic formatting of code in VS Code. To automatically format the code in the current source code window, right-click in the code window and select Format Document . You can add a keyboard shortcut to this VS Code Preferences.
VSCode: Prettier does not work with Dart Flutter.
Go to Settings -> Languages & Frameworks -> Flutter and check Format code on save.
You can also use Reformat code shortcut manually:
Windows/Linux: Ctrl + Alt + L
Mac: Command + Option + L
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With