Repository: flutter
Issue: WidgetsApp: Changing supportedLocales fails to update the locale
Labels: framework,f: material design,a: internationalization,has reproducible steps,found in release: 3.3,found in release: 3.7,team-design,triaged-design

When providing `supportedLocales` to a WidgetsApp (in this case, a MaterialApp), it doesn't update the internal `_locale` field in `didUpdateWidget`.

The workaround is to provide a specific locale via the `locale` field. (as to be seen on line 23)

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. Execute `flutter run` on the code sample <!-- (see "Code sample" section below) -->
2. Press button on page
3. Observe that the text above the button doesn't change.
4. Uncomment workaround in line 23 and try again.

**Expected results:** Text respectively the Locale (`_locale` in WidgetsApp) changes.

**Actual results:** `_locale` in WidgetsApp is still the same, nothing changes.

<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

```dart
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<Locale> supportedLocales = [const Locale("de")];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      // Workaround: Overrides the _locale from WidgetsApp
      // locale: supportedLocales[0],
      supportedLocales: supportedLocales,
      localizationsDelegates: GlobalMaterialLocalizations.delegates,
      routes: {
        '/': (context) => MyHomePage(onPress: () {
              setState(() {
                supportedLocales = [const Locale("en")];
              });
            }),
      },
      initialRoute: "/",
    );
  }
}

class MyHomePage extends StatelessWidget {
  final VoidCallback onPress;

  const MyHomePage({super.key, required this.onPress});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Flutter Demo Home Page")),
      body: Center(
        child: Column(
          children: [
            Text("Current locale: ${Localizations.localeOf(context)}"),
            ElevatedButton(
              onPressed: () => onPress.call(),
              child: const Text("Press me to change locale"),
            ),
          ],
        ),
      ),
    );
  }
}

```

</details>

<details>
  <summary>flutter doctor -v</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue. If there is a crash, please include
      the entirety of the crash log including the backtrace.
-->

```
[✓] Flutter (Channel stable, 3.3.9, on Manjaro Linux 6.0.11-1-MANJARO, locale de_AT.UTF-8)
    • Flutter version 3.3.9 on channel stable at /home/shamader/tools/flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (vor 3 Wochen), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /mnt/Daten/tools/Android/Sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /home/shamader/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /usr/bin/chromium

[✗] Linux toolchain - develop for Linux desktop
    • clang version 14.0.6
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
    • pkg-config version 1.8.0

[✓] Android Studio (version 2021.3)
    • Android Studio at /home/shamader/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335
    • Flutter plugin version 71.1.3
    • Dart plugin version 213.7433
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[!] Android Studio (version 2022.1)
    • Android Studio at /home/shamader/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-1/221.6008.13.2211.9301383
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[!] Android Studio (version 2022.2)
    • Android Studio at /home/shamader/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-2/222.4345.14.2221.9321504
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Connected device (4 available)
    • SM T500 (mobile)    • R9AR800H8RK      • android-arm64  • Android 12 (API 31)
    • M2103K19PG (mobile) • xwcm955djrrslnpj • android-arm64  • Android 12 (API 31)
    • Linux (desktop)     • linux            • linux-x64      • Manjaro Linux 6.0.11-1-MANJARO
    • Chrome (web)        • chrome           • web-javascript • Chromium 108.0.5359.94 Arch Linux

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 3 categories.
```

</details>

## Missing statement location

WidgetsApp Code which is missing an update statement taking `supportedLocales` into account.

https://github.com/flutter/flutter/blob/da7b8327e484f2ce036244bff4880bb771dd636c/packages/flutter/lib/src/widgets/app.dart#L1335-L1347