Search code examples
formattingindentation

Dart-Flutter autoformat vscode is not accordance with indent convention


I have setup dart autoformatting to flutter, but unfortunately when I press CTRL+S It was formatting in one line

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  static const String _judul = 'Private Chat';

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(title: _judul, home: MyHomePage());
  }
}

While I expect dart format like this

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  static const String _judul = 'Private Chat';

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: _judul, 
      home: MyHomePage()
    );
  }
}

Solution

  • Solved, It was because flutter format command which default of maximum col in a line is 80. Since my case is not reached 80 col, dart didn't autoformat make new line.