Flutter-intellij: Code formatting style

Created on 5 May 2019  路  9Comments  路  Source: flutter/flutter-intellij

Actual

Runs auto format and gets this crazy alignment with helper lines, see picture.
BAD

Expected

Runs auto format and gets helper lines that align properly.

Steps to Reproduce

Run auto format with "Reformat code with Dart fmt" or "Reformat code", on this code:

class _MyHomePageState extends State<MyHomePage> {
  int numTaps = 0, numDoubleTaps = 0, numLongPress = 0;
  double posX = 0.0, posY = 0.0, boxSize = 150.0;

  @override
  Widget build(BuildContext context) {
    if (posX == 0) {
      setCenter(context);
    }
    return Scaffold(
      appBar: AppBar(
        title: Text("Gestures and Animations"),
      ),
      bottomNavigationBar: Material(
        color: Theme.of(context).primaryColorLight,
        child: Padding(
          padding: EdgeInsets.all(15),
          child: Center(
              heightFactor: 1,
              child: Text(
                  "Taps: $numTaps - Double taps: $numDoubleTaps - Longpress: $numLongPress",
                  style: TextStyle(color: Colors.black, fontSize: 18))),
        ),
      ),
      body: GestureDetector(
        onTap: () {
          setState(() {
            numTaps++;
          });
        },
        onDoubleTap: () {
          setState(() {
            numDoubleTaps++;
          });
        },
        onLongPress: () {
          setState(() {
            numLongPress++;
          });
        },
        child: Stack(
          children: <Widget>[
            Positioned(
                top: posY,
                left: posX,
                child: Container(
                  width: boxSize,
                  height: boxSize,
                  decoration: BoxDecoration(color: Colors.orangeAccent),
                ))
          ],
        ),
      ),
    );
  }

  void setCenter(BuildContext context) {
    posX = (MediaQuery.of(context).size.width / 2 - boxSize / 2);
    posY = (MediaQuery.of(context).size.height / 2 -
        boxSize / 2 -
        80 /*Top- and bottom-size*/);
    setState(() {
      posX = posX;
      posY = posY;
    });
  }
}

_This issue happens more and more often and is very distracting._

Version info

Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17763.475], locale en-GB)
Android toolchain - develop for Android devices (Android SDK version 28.0.3)
Android Studio (version 3.4)
Flutter plugin 35.1
Dart v.183.6270

All 9 comments

Android Studio > settings > Languages & Frameworks > Flutter > UI Guides : disable it

Thank you for reporting the error. We'd like to track in down. The UI guides are supposed to never display broken guides like the ones you are seeing. Unfortunately, I'm having trouble reproducing the issue.
Can you upgrade your plugin to V35.2 and let me know if you still see the error? We fixed a bug it V35.1 that might be related.
Also watch for a flashing red icon in the bottom right corner of your screen indicating that our code threw an exception. If you can include a stack trace of what went wrong it will make it much easier for us to fix it.
When I run dartfmt on the example you gave everything looks good:
Screen Shot 2019-05-06 at 9 53 13 AM

Might be related #3462

Didn't get any exceptions. But we use the same version of Flutter Plugin and Dart Plugin on Android Studio 3.4.

Thank you for reporting the error. We'd like to track in down. The UI guides are supposed to never display broken guides like the ones you are seeing. Unfortunately, I'm having trouble reproducing the issue.
Can you upgrade your plugin to V35.2 and let me know if you still see the error? We fixed a bug it V35.1 that might be related.
Also watch for a flashing red icon in the bottom right corner of your screen indicating that our code threw an exception. If you can include a stack trace of what went wrong it will make it much easier for us to fix it.
When I run dartfmt on the example you gave everything looks good:
Screen Shot 2019-05-06 at 9 53 13 AM

I have updated the Flutter Plugin and will investigate if this happens again.

Might be related #3462

I've got the same error. Get the same exception in my IDE.

With 35.2 you may still see a flicker of strange indent guides after the format.
In the next release we will fix the flicker of strange indents as well.
Here's a beta plugin you can try to verify it helps.
With the beta plugin at worst you will see a few indent guides temporarily disappear on code format until a new valid "Flutter Outline" is computed.
repro
Android Studio 3.4 version of the Flutter plugin.
flutter-intellij.zip

With 35.2 you may still see a flicker of strange indent guides after the format.
In the next release we will fix the flicker of strange indents as well.
Here's a beta plugin you can try to verify it helps.
With the beta plugin at worst you will see a few indent guides temporarily disappear on code format until a new valid "Flutter Outline" is computed.
repro
Android Studio 3.4 version of the Flutter plugin.
flutter-intellij.zip

Ok thanks for the fast support, great work and looking forward to the next update.

Was this page helpful?
0 / 5 - 0 ratings