Skip to content

The asynchronous execution order is inconsistent between Android and the web. #151579

@Stitch-Taotao

Description

@Stitch-Taotao

Steps to reproduce

Run code bellow in Android platform and web individually.
Click floatingButton and see result.
Execution order should same in different platform,otherwise, it could potentially lead to critical bugs, or we may have to discuss implementing different logic for different platforms(But I'm not sure if the specific behavior will change with different versions. And I think it should not be handled this way).

Expected results

Console log result should be same.

Actual results

  1. On Web:
    res:0
    res:2

  2. On Android :
    res:0
    res:0

Code sample

Code sample
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

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

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          test1();
          res = 2;
        },
        child: Icon(Icons.add),
      ),
    );
  }

  int res = 0;
  void test1() async {
    print("res:$res");
    await syncAction();
    print("res:$res");
  }

  Future<int> syncAction() {
    return SynchronousFuture(1);
  }
}

Screenshots or Video

No response

Logs

flutter version : 3.22.2 stable

Flutter Doctor output

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [版本 10.0.22631.3737], locale zh-CN)
• Flutter version 3.22.2 on channel stable at C:\Users\letpub_it_data\fvm\versions\3.13.9
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 761747b (5 weeks ago), 2024-06-05 22:15:13 +0200
• Engine revision edd8546116
• Dart version 3.4.3
• DevTools version 2.34.3
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn

[√] Windows Version (Installed version of Windows is version 10 or higher)

Metadata

Metadata

Assignees

Labels

Bot is counting down the days until it unassigns the issuedependency: dartDart team may need to help usdependency:dart-triagedTriaged by Dart teamfound in release: 3.22Found to occur in 3.22found in release: 3.24Found to occur in 3.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-webOwned by Web platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions