Skip to content

iOS keyboard cannot switch brightness automatically #167512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
QuncCccccc opened this issue Apr 21, 2025 · 2 comments
Open

iOS keyboard cannot switch brightness automatically #167512

QuncCccccc opened this issue Apr 21, 2025 · 2 comments
Labels
a: text input Entering text in a text field or keyboard related problems P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-text-input Owned by Text Input team triaged-text-input Triaged by Text Input team

Comments

@QuncCccccc
Copy link
Contributor

QuncCccccc commented Apr 21, 2025

Related to b/411543118

Steps to reproduce

  1. Tap the TextField and the keyboard shows up with correct brightness.
  2. Keep the keyboard showing and change to dark mode in Settings
  3. Go back to app

Expected results

The keyboard should show dark brightness.

Actual results

The keyboard still shows light brightness unless we close it and then reopen.

Code sample

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

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(),
      darkTheme: ThemeData.dark(),
      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> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              keyboardAppearance: MediaQuery.of(context).platformBrightness,
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
Screen.Recording.2025-04-21.at.3.00.05.PM.mov

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]
@QuncCccccc QuncCccccc added a: text input Entering text in a text field or keyboard related problems team-text-input Owned by Text Input team labels Apr 21, 2025
@justinmc
Copy link
Contributor

justinmc commented Apr 21, 2025

Does anyone know if there happens to be a native iOS API that would let us update the brightness of the keyboard? I'm doubting it, in which case we probably need to hide and reshow the keyboard. Maybe resetting the text input connection when the system brightness changes is the solution.

I tried this with a Flutter app on Android and the keyboard always hid itself when leaving and returning to the Flutter app (even without changing the brightness, likely a bug itself). But that meant that Android did not experience this bug directly.

It may be possible to work around this by clearing focus when didChangePlatformBrightness?

@justinmc justinmc added the platform-ios iOS applications specifically label Apr 21, 2025
@loic-sharma loic-sharma added the fyi-ios For the attention of iOS platform team label Apr 21, 2025
@loic-sharma
Copy link
Member

loic-sharma commented Apr 21, 2025

Interesting. On the iOS Notes app, the keyboard brightness updates immediately if I change the OS brightness. I wonder what Flutter is doing to prevent this.

Perhaps this is another bug that @LongCatIsLooong's go/flutter-textinputplugin-uitextview prototype might fix?

I'm doubting it, in which case we probably need to hide and reshow the keyboard. Maybe resetting the text input connection when the system brightness changes is the solution.
...
It may be possible to work around this by clearing focus when didChangePlatformBrightness?

It looks like iOS's logic to receive brightness changes is here:

#pragma mark - Set user settings
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self onUserSettingsChanged:nil];
}
- (void)onUserSettingsChanged:(NSNotification*)notification {
[self.engine.settingsChannel sendMessage:@{
@"textScaleFactor" : @(self.textScaleFactor),
@"alwaysUse24HourFormat" : @(FlutterHourFormat.isAlwaysUse24HourFormat),
@"platformBrightness" : self.brightnessMode,
@"platformContrast" : self.contrastMode,
@"nativeSpellCheckServiceDefined" : @YES,
@"supportsShowingSystemContextMenu" : @(self.supportsShowingSystemContextMenu)
}];
}

We could update this such that when the brightness changes, the view controller tells the engine's text input plugin to hide the keyboard if it is visible.

@justinmc justinmc added P2 Important issues not at the top of the work list triaged-text-input Triaged by Text Input team labels Apr 24, 2025
@vashworth vashworth added the triaged-ios Triaged by iOS platform team label May 15, 2025
@flutter-triage-bot flutter-triage-bot bot removed fyi-ios For the attention of iOS platform team triaged-ios Triaged by iOS platform team labels May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-text-input Owned by Text Input team triaged-text-input Triaged by Text Input team
Projects
None yet
Development

No branches or pull requests

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy