Could anyone explain to me why dart formats the code in a way it does it? I have the dart plugin installed and have used the 'Dart: Use recommended settings'.

Future<void> addProduct(Product product) {
    return http
        .post(
      '$url.json',
      body: json.encode(
        {
          'title': product.title,
          'description': product.description,
          'imageUrl': product.imageUrl,
          'price': product.price,
          'isFavorite': product.isFavorite,
        },
      ),
    )
        .then((response) {
      var id = json.decode(response.body)['name'];
      var newProduct = Product(
        description: product.description,
        title: product.title,
        price: product.price,
        imageUrl: product.imageUrl,
        id: id,
      );
      _items.add(newProduct);
      notifyListeners();
    }).catchError((err) {});
  }


Solution 1: Danny Tuppeny

As mentioned in the comments, the Dart extension just delegates formatting to dartfmt so the formatting is based on its conventions, including 2-spaces for indenting and 4-space indenting for line continuations.

dartfmt is an opinionated formatter so there's not much that can be controlled, though trailing commas will affect how it formats some code:

https://flutter.dev/docs/development/tools/formatting


(source: flutter.dev)


(source: flutter.dev)