-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
When changing the system ui mode using SystemChrome.setEnabledSystemUIMode, the keyboard opening animation is stuttery on devices that support the new smooth keyboard animation (I think starting Android 11, though I am encountering this bug on Android 12).
This issue can be reproduced in both latest stable and latest beta.
Steps to reproduce
- Run the code sample provided below on an Android device, preferably running Android 12 and using profile mode (to see the stutter more clearly).
- Switch through the different
SystemUiModes using the provided top buttons. - Press on the
TextFormFieldplaced in the middle of the app and observe the bottom red bar animating with the keyboard opening.
Expected results
- The whole bottom red bar is on the top of the keyboard during the entrance animation, without a sudden stutter in all the provided states.
Actual results
- When in the
Defaultstate, the bottom red bar is animating smoothly with the entrance of the keyboard, no stutters, as expected. - When in the other modes, you can observe that, while animating, a part of the bottom red bar is not visible, but towards the end, the bottom red bar suddenly and abruptly reappears in its full shape on the screen, resulting in a stuttery experience.
I'm thinking this is because of some bottom insets evaluation errors when running in a different from default SystemUiMode.
Code sample
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
// I discovered this bug when I wanted to make the color of the system navigation bar reflect the
// modern android behavior: showing the scaffold color.
// This is why I made the navigation bar transparent here. Though, this line is not necesarry
// in the reproduction of this bug.
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.transparent,
),
);
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Keyboard Stutter')),
body: Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Column(
children: [
Wrap(
spacing: 10,
children: [
// Here is the deal. Setting any SystemUIMode other than the default one induces
// this bug.
ElevatedButton(
onPressed: () {
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: SystemUiOverlay.values,
);
},
child: const Text('Default'),
),
ElevatedButton(
onPressed: () {
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
);
},
child: const Text('Edge to Edge'),
),
ElevatedButton(
onPressed: () {
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersive,
);
},
child: const Text('Immersive'),
),
ElevatedButton(
onPressed: () {
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersiveSticky,
);
},
child: const Text('Immersive Sticky'),
),
ElevatedButton(
onPressed: () {
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.leanBack,
);
},
child: const Text('Leanback'),
),
],
),
Expanded(
child: Align(
child: TextFormField(
decoration: const InputDecoration(
labelText:
'Focus on this TextField and observe the bottom.',
border: OutlineInputBorder(),
),
),
),
),
SizedBox.fromSize(
size: const Size.fromHeight(50),
child: const ColoredBox(
color: Colors.red,
child: Center(
child: Text('Observe the behavior of this bar.'),
),
),
)
],
),
),
),
);
}
}Reproduction of the bug
Here is a recording of the bug being reproduced.
x.mp4
Debug info
flutter doctor -v
[✓] Flutter (Channel beta, 3.3.0-0.3.pre, on Microsoft Windows [Version 10.0.22622.575], locale ro-RO)
• Flutter version 3.3.0-0.3.pre on channel beta at C:\Users\iamco\fvm\default
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 8c1149878b (6 days ago), 2022-08-10 12:15:36 -0500
• Engine revision f16e757d5d
• Dart version 2.18.0 (build 2.18.0-271.4.beta)
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at C:\Users\iamco\AppData\Local\Android\sdk
• Platform android-32, build-tools 32.1.0-rc1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.2.32630.192
• Windows 10 SDK version 10.0.19041.0
[✓] Android Studio (version 2021.2)
• Android Studio at C:\Program Files\Android\Android Studio
• 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
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
[✓] VS Code (version 1.70.1)
• VS Code at C:\Users\iamco\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.44.0
[✓] Connected device (4 available)
• SM A528B (mobile) • 12.21.11.122:45699 • android-arm64 • Android 12 (API 31)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22622.575]
• Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.81
• Edge (web) • edge • web-javascript • Microsoft Edge 104.0.1293.54
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Also, a small nit: when using SystemUiMode.edgeToEdge, and at the same time having gesture navigation enabled in my Android's settings, in the code sample provided, the entire app UI kind of just slides behind the navigation bar? (you can observe this on the provided recording when selecting Edge to Edge). An easy solution would be to put a SafeArea widget as a parent of the Column and child of Scaffold, but you would assume that Scaffold already rocks SafeArea under the hood. I don't know, it seems strange, though I did not want to make a separate issue because I thought it's not that big of a deal. Though, if you want me to report this as a separate issue, I will happily do so.
Thank you!