Skip to content
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

[keyboard_actions] Mystery padding/widget above keyboard when TimeDilation > 1.0 #182

Open
md84419 opened this issue Feb 10, 2022 · 0 comments

Comments

@md84419
Copy link

md84419 commented Feb 10, 2022

I have a mystery padding above the keyboard when TimeDilation > 1.0 and I come to the screen with my keyboard on, from another screen.

The padding seems to be proportional to the time dilation when timeDilation >1.0 and < 3.0. It seems to be constant at the same height for timeDilation values >= 3.0.

If I change the routing so that FirstScreen never gets generated, the bug is avoided. Similarly, the bug can be worked around by forcing a screen redraw.

What is the cause and how do I need to change my code, to fix this bug?

Steps to Reproduce

  1. Execute flutter run on the code sample

Expected results:

15 (blue) logical pixels between the bottom of the green Container and the top of the grey CueKeyboard widget.

Actual results:

Approximately 150 (blue) logical pixels between the bottom of the green Container and the top of the grey CueKeyboard widget.

The extra space doesn't appear to be accounted for in the Widget inspector. There isn't a widget listed in the inspector that can account for the extra space and it isn't padding or margin on the CueKeyboard or the Container or any of their ancestors.

Code sample
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:keyboard_actions/keyboard_actions.dart';

void main() async {
  // set the system top-level property [timeDilation] to control the animation speed
  timeDilation = 3.0;

  WidgetsFlutterBinding.ensureInitialized();

  runApp(
    MyApp(),
  );
}

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

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: '/',
      onGenerateRoute: (RouteSettings settings) {
        final routes = <String, WidgetBuilder?>{
          '/': (_) => FirstScreen(),
          '/screen2': (_) => SecondScreen(),
        };
        final builder = routes[settings.name]!;
        return MaterialPageRoute(
          builder: builder,
          settings: settings,
        );
      },
    );
  }
}

// ----------------------------------------------------------

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

  @override
  _FirstScreenState createState() => _FirstScreenState();
}

class _FirstScreenState extends State<FirstScreen> {
  @override
  void initState() {
    WidgetsBinding.instance?.addPostFrameCallback((_) {
      Navigator.of(context).pushNamed('/screen2');
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold();
  }
}

// ----------------------------------------------------------

class SecondScreen extends StatefulWidget {
  @override
  _SecondScreenState createState() => _SecondScreenState();
}

class _SecondScreenState extends State<SecondScreen>
    with RouteAware, WidgetsBindingObserver {
  FocusNode? focusNode;

  ValueNotifier<String>? _stringValueNotifier;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance!.addObserver(this);
    this._stringValueNotifier = ValueNotifier<String>('');
    this._stringValueNotifier!.addListener(() {});
  }

  @override
  void dispose() {
    _stringValueNotifier?.dispose();

    WidgetsBinding.instance!.removeObserver(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    this.focusNode = FocusNode();

    return Scaffold(
      body: KeyboardContent(
        focusNode: this.focusNode!,
        stringValueNotifier: this._stringValueNotifier!,
      ),
    );
  }
}

// ----------------------------------------------------------

class KeyboardContent extends StatelessWidget {
  final FocusNode focusNode;
  final ValueNotifier<String> stringValueNotifier;

  /// A container for an on-screen keyboard
  /// The widget automatically gets rebuilt on value change, triggered
  /// when a keyboard button is pressed.
  KeyboardContent({
    required this.focusNode,
    required this.stringValueNotifier,
  });

  KeyboardActionsConfig _buildConfig(BuildContext context) {
    List<Widget Function(FocusNode)> toolbarButtons = [];

    return KeyboardActionsConfig(
        keyboardActionsPlatform: KeyboardActionsPlatform.ALL,
        keyboardBarColor: Colors.grey[200]!,
        //nextFocus: false,
        actions: [
          KeyboardActionsItem(
            focusNode: focusNode,
            displayActionBar: false,
            displayDoneButton: false,
            toolbarButtons: toolbarButtons,
            footerBuilder: (_) => CueKeyboard(),
          )
        ]);
  }

  @override
  Widget build(BuildContext context) {
    if (!focusNode.hasPrimaryFocus) focusNode.requestFocus();
    return Container(
      decoration: BoxDecoration(color: Colors.blue),
      child: KeyboardActions(
        config: _buildConfig(context),
        child: Container(
          padding: EdgeInsets.only(left: 15, right: 15),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              KeyboardCustomInput<String>(
                focusNode: focusNode,
                notifier: stringValueNotifier,
                builder: (context, keyboardTapVal, hasFocus) {
                  return Container(
                      margin: EdgeInsets.only(top: 100),
                      height: 800,
                      width: 100,
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(32.0),
                          color: Colors.green));
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class CueKeyboard extends StatefulWidget implements PreferredSizeWidget {
  static final double _keyboardHeight = 184.0;

  CueKeyboard({
    Key? key,
  }) : super(key: key);

  @override
  _CueKeyboardState createState() => _CueKeyboardState();

  @override
  Size get preferredSize => Size.fromHeight(CueKeyboard._keyboardHeight);
}

class _CueKeyboardState extends State<CueKeyboard> {
  dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Wrap(
      children: [
        Column(
          children: [Text("Keyboard")],
        ),
      ],
    );
  }
}
Logs
$ flutter run --verbose
[  +53 ms] executing: [C:\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +84 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] 77d935af4db863f6abd0b9c31c7e6df2a13de57b
[        ] executing: [C:\flutter/] git tag --points-at 77d935af4db863f6abd0b9c31c7e6df2a13de57b
[  +24 ms] Exit code 0 from: git tag --points-at 77d935af4db863f6abd0b9c31c7e6df2a13de57b
[        ] 2.8.1
[   +6 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +15 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [C:\flutter/] git ls-remote --get-url origin
[  +11 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +70 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref HEAD
[  +14 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[  +47 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +7 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +48 ms] executing: C:\Users\md844\Android\SDK\platform-tools\adb.exe devices -l
[  +40 ms] List of devices attached
           emulator-5554          device product:sdk_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:11
[   +6 ms] C:\Users\md844\Android\SDK\platform-tools\adb.exe -s emulator-5554 shell getprop
[  +33 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +66 ms] Skipping pub get: version match.
[  +40 ms] Found plugin integration_test at C:\flutter\packages\integration_test\
[  +82 ms] Found plugin integration_test at C:\flutter\packages\integration_test\
[   +6 ms] Generating C:\Users\md844\source\repos\ucue_keyboard_bug\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[  +41 ms] ro.hardware = ranchu
[  +13 ms] Using hardware rendering with device Android SDK built for x86. If you notice graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
[  +24 ms] Initializing file store
[   +9 ms] Skipping target: gen_localizations
[   +4 ms] gen_dart_plugin_registrant: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents:
C:\Users\md844\source\repos\ucue_keyboard_bug\.dart_tool\package_config_subset}
[  +23 ms] Found plugin integration_test at C:\flutter\packages\integration_test\
[   +2 ms] gen_dart_plugin_registrant: Complete
[   +1 ms] Skipping target: _composite
[   +2 ms] complete
[   +4 ms] Launching lib\main.dart on Android SDK built for x86 in debug mode...
[   +3 ms] C:\flutter\bin\cache\dart-sdk\bin\dart.exe --disable-dart-dev C:\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot --sdk-root
C:\flutter\bin\cache\artifacts\engine\common\flutter_patched_sdk/ --incremental --target=flutter --debugger-module-names --experimental-emit-debug-metadata
-DFLUTTER_WEB_AUTO_DETECT=true --output-dill C:\Users\md844\AppData\Local\Temp\flutter_tools.f728f2b7\flutter_tool.9d976d\app.dill --packages
C:\Users\md844\source\repos\ucue_keyboard_bug\.dart_tool\package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation
--filesystem-scheme org-dartlang-root --initialize-from-dill build\c075001b96339384a97db4862b8ab8db.cache.dill.track.dill --enable-experiment=alternative-invalidation-strategy    
[   +7 ms] executing: C:\Users\md844\Android\SDK\build-tools\32.0.0\aapt dump xmltree C:\Users\md844\source\repos\ucue_keyboard_bug\build\app\outputs\flutter-apk\app.apk
AndroidManifest.xml
[   +8 ms] Exit code 0 from: C:\Users\md844\Android\SDK\build-tools\32.0.0\aapt dump xmltree C:\Users\md844\source\repos\ucue_keyboard_bug\build\app\outputs\flutter-apk\app.apk   
AndroidManifest.xml
[        ] N: android=http://schemas.android.com/apk/res/android
             E: manifest (line=2)
               A: android:versionCode(0x0101021b)=(type 0x10)0x1
               A: android:versionName(0x0101021c)="0.0.1" (Raw: "0.0.1")
               A: android:compileSdkVersion(0x01010572)=(type 0x10)0x1d
               A: android:compileSdkVersionCodename(0x01010573)="10" (Raw: "10")
               A: package="uk.co.cuedspeech.ucue.debug" (Raw: "uk.co.cuedspeech.ucue.debug")
               A: platformBuildVersionCode=(type 0x10)0x1d
               A: platformBuildVersionName=(type 0x10)0xa
               E: uses-sdk (line=7)
                 A: android:minSdkVersion(0x0101020c)=(type 0x10)0x17
                 A: android:targetSdkVersion(0x01010270)=(type 0x10)0x1e
               E: uses-permission (line=14)
                 A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
               E: application (line=22)
                 A: android:label(0x01010001)="uCUE" (Raw: "uCUE")
                 A: android:icon(0x01010002)=@0x7f080000
                 A: android:name(0x01010003)="io.flutter.app.FlutterApplication" (Raw: "io.flutter.app.FlutterApplication")
                 A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff
                 A: android:extractNativeLibs(0x010104ea)=(type 0x12)0x0
                 A: android:appComponentFactory(0x0101057a)="androidx.core.app.CoreComponentFactory" (Raw: "androidx.core.app.CoreComponentFactory")
                 E: activity (line=29)
                   A: android:theme(0x01010000)=@0x7f0a0000
                   A: android:name(0x01010003)="uk.co.cuedspeech.ucue.MainActivity" (Raw: "uk.co.cuedspeech.ucue.MainActivity")
                   A: android:launchMode(0x0101001d)=(type 0x10)0x1
                   A: android:configChanges(0x0101001f)=(type 0x11)0x40003fb4
                   A: android:windowSoftInputMode(0x0101022b)=(type 0x11)0x10
                   A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
                   E: meta-data (line=43)
                     A: android:name(0x01010003)="io.flutter.embedding.android.NormalTheme" (Raw: "io.flutter.embedding.android.NormalTheme")
                     A: android:resource(0x01010025)=@0x7f0a0001
                   E: meta-data (line=53)
                     A: android:name(0x01010003)="io.flutter.embedding.android.SplashScreenDrawable" (Raw: "io.flutter.embedding.android.SplashScreenDrawable")
                     A: android:resource(0x01010025)=@0x7f040002
                   E: intent-filter (line=57)
                     E: action (line=58)
                       A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
                     E: category (line=60)
                       A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
                 E: meta-data (line=67)
                   A: android:name(0x01010003)="flutterEmbedding" (Raw: "flutterEmbedding")
                   A: android:value(0x01010024)=(type 0x10)0x2
[   +8 ms] executing: C:\Users\md844\Android\SDK\platform-tools\adb.exe -s emulator-5554 shell -x logcat -v time -t 1
[  +13 ms] <- compile package:ucue_keyboard_bug/main.dart
[  +55 ms] --------- beginning of main
    
[...]

[  +49 ms] --------- beginning of main
           01-30 13:39:27.586 I/cmd     (25596): oneway function results will be dropped but finished with status OK and parcel size 4
[   +6 ms] executing: C:\Users\md844\Android\SDK\platform-tools\adb.exe -s emulator-5554 shell am start -a android.intent.action.RUN -f 0x20000000 --ez
enable-background-compilation true --ez enable-dart-profiling true --ez enable-checked-mode true --ez verify-entry-points true
uk.co.cuedspeech.ucue.debug/uk.co.cuedspeech.ucue.MainActivity
[  +34 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=uk.co.cuedspeech.ucue.debug/uk.co.cuedspeech.ucue.MainActivity (has extras) }
[   +1 ms] Waiting for observatory port to be available...
[ +360 ms] W/FlutterActivityAndFragmentDelegate(25618): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration
steps.
[  +21 ms] Observatory URL on device: http://127.0.0.1:39329/Bg_xE12sSvQ=/
[        ] executing: C:\Users\md844\Android\SDK\platform-tools\adb.exe -s emulator-5554 forward tcp:0 tcp:39329
[  +16 ms] 60159
[        ] Forwarded host port 60159 to device port 39329 for Observatory
[   +4 ms] Caching compiled dill
[  +24 ms] Connecting to service protocol: http://127.0.0.1:60159/Bg_xE12sSvQ=/
[ +252 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:60159/Bg_xE12sSvQ=/.
[ +116 ms] DDS is listening at http://127.0.0.1:60162/57G22rjDLdI=/.
[  +43 ms] Successfully connected to service protocol: http://127.0.0.1:60159/Bg_xE12sSvQ=/
[  +56 ms] DevFS: Creating new filesystem on the device (null)
[  +32 ms] DevFS: Created new filesystem on the device (file:///data/user/0/uk.co.cuedspeech.ucue.debug/code_cache/ucue_keyboard_bugULKJZB/ucue_keyboard_bug/)
[   +2 ms] Updating assets
[  +67 ms] Syncing files to device Android SDK built for x86...
[   +1 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[   +2 ms] <- recompile package:ucue_keyboard_bug/main.dart 027f4494-050d-4ec8-becc-6f960203b371
[        ] <- 027f4494-050d-4ec8-becc-6f960203b371
[ +114 ms] Updating files.
[        ] DevFS: Sync finished
[        ] Syncing files to device Android SDK built for x86... (completed in 120ms)
[        ] Synced 0.0MB.
[   +1 ms] <- accept
[   +3 ms] Connected to _flutterView/0xe290b860.
[   +2 ms] Flutter run key commands.
[   +1 ms] r Hot reload. 
[        ] R Hot restart.
[        ] h List all available interactive commands.
[        ] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[        ] q Quit (terminate the application on the device).
[        ]  Running with sound null safety 
[        ] An Observatory debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:60162/57G22rjDLdI=/
[ +491 ms] I/eech.ucue.debu(25618): Waiting for a blocking GC ProfileSaver
[ +242 ms] The Flutter DevTools debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:60162/57G22rjDLdI=/
pubspec.yaml

name: ucue_keyboard_bug
description: Demo app showing the keyboard bug when time dialation=3

publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.0.1+1

environment:
  sdk: '>=2.12.0-0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  keyboard_actions: ^3.4.0
  pedantic:
  uuid: ^3.0.1

# Temporary dependencies
dependency_overrides:
 
dev_dependencies:
  flutter_test:
    sdk: flutter
  integration_test:
    sdk: flutter

analyzer:
  strong-mode: true
  language:
    enableSuperMixins: true

# The following section is specific to Flutter.
flutter:
  uses-material-design: true
$ flutter analyze
Analyzing ucue_keyboard_bug...                                          
No issues found! (ran in 1.4s)
$ flutter analyze
Analyzing ucue_keyboard_bug...                                          
No issues found! (ran in 1.4s)

md844@LAPTOP-FSG05SD7 MINGW64 ~/source/repos/ucue_keyboard_bug
$ flutter doctor -v
[√] Flutter (Channel stable, 2.10.0, on Microsoft Windows [Version 10.0.19044.1466], locale en-GB)
    • Flutter version 2.10.0 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (8 days ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at C:\Users\md844\Android\SDK
    • Platform android-32, build-tools 32.0.0
    • ANDROID_HOME = C:\Users\md844\Android\SDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2020.3)
    • 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.10+0-b96-7249189)

[√] VS Code (version 1.64.0)
    • VS Code at C:\Users\md844\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.34.0

[√] Connected device (5 available)
    • Pixel 4a (mobile)                  • 17131JEC201655 • android-arm64  • Android 12 (API 31)
    • Android SDK built for x86 (mobile) • emulator-5554  • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)                  • windows        • windows-x64    • Microsoft Windows [Version 10.0.19044.1466]
    • Chrome (web)                       • chrome         • web-javascript • Google Chrome 97.0.4692.99
    • Edge (web)                         • edge           • web-javascript • Microsoft Edge 97.0.1072.69

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Screenshot of the app output, with mystery padding encircled:
https://i.stack.imgur.com/ClPJo.png

Screenshot of widget inspector:
https://paste.pics/8c925245d4b1734af6c580fabb153da9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant