flutter-intellij icon indicating copy to clipboard operation
flutter-intellij copied to clipboard

[BUG] Debugger attached twice in intellij and MainApp widget executed twice after page refresh, on button click

Open iosif-bancioiu opened this issue 1 year ago • 0 comments

I'm trying to understand why under a new project, targeting web, the MainApp (Stateless widget) gets executed TWICE after browser refresh - simulating browser oauth2 redirect.

In the attached files you can view the logs of steps to reproduce before and after refresh. Once thing that I've noticed is that the debugger is attaching twice and all of those only in debug mode, only on web and ONLY in intellij / android studio, so from my point of view it looks like a plugin issue. This is not happening in release / profile mode or using debug mode in VS Code

Steps to reproduce

  1. Create a new Flutter project, targeting Android, iOS and Web (tried from IntelliJ with latest updates and Flutter SDK 3.19.3 (STABLE), Dart 3.3.1, DevTools 2.31.1)
  2. Under the newly created project edit the main.dart and add a print('app'); in the build method of the stateless widget MyApp
  3. In the generated statefull widget state class (_MyHomePageState) build method add another print('statefull').
  4. Deploy the app in debug mode targeting web (Chrome)
  5. Open console and set preserve log
  6. Click on increment Button once
  7. Hit refresh in browser (simulate an oauth2 redirect for example)
  8. Click on increment Button again

Expected results

Once the app is loaded after refresh i'm expecting to see one "app" and one "statefull" message in the console. After clicking increment button i'm expecting to see additional "statefull" messages

Actual results

Once the app is loaded after refresh i can see see one "app" and one "statefull" message in the console. After clicking increment button instead of repeated "statefull" messages, I see a repeated "app" message and a "statefull" message

The "app" message should not be there when clicking increment after refresh

This only happens on web and only after hitting browser refresh / simulating a redirect, again only using IntelliJ / Android Studio

Version info

[✓] Flutter (Channel stable, 3.19.3, on macOS 14.4 23E214 darwin-arm64, locale en-RO)
    • Flutter version 3.19.3 on channel stable at /Library/Flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (11 days ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/iosif.bancioiu/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.5)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 78.3.1
    • Dart plugin version 233.14888

Code

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    print('------- APP ------------');
    print(StackTrace.current);
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
     
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    print('------- STATEFULL ------------');
    print(StackTrace.current);
    
    return Scaffold(
      appBar: AppBar(
        
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
       
        title: Text(widget.title),
      ),
      body: Center(
       
        child: Column(
          
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

Logs

BEFORE REFRESH.txt AFTER REFRESH.txt

iosif-bancioiu avatar Mar 18 '24 17:03 iosif-bancioiu