Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable autoformating Flutter project in Android Studio?

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?

like image 813
rozerro Avatar asked Dec 01 '19 19:12

rozerro


People also ask

How do you use formatter in flutter?

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.

Does prettier work with flutter?

VSCode: Prettier does not work with Dart Flutter.


1 Answers

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

like image 117
janstol Avatar answered Sep 30 '22 04:09

janstol