Skip to content

Web autofill throw exception when using html InputElement #114620

@dtruong27

Description

@dtruong27

Steps to Reproduce

For some reason, the browser did not store my text in the release web build, but the exception occurs when I debug the code:

  1. Run the app in debug mode with chrome as the device
  2. Enter first character of some stored text (for example in the attached video, I entered 7 because I had 700 stored by my browser)
  3. Tap on a text suggested by the browser (in my video, it is 700)

Expected results:

The suggested text should display without any exception

Actual results:

I got the exception:

errors.dart:266 Uncaught Error: Unexpected null value.
    at Object.throw_ [as throw] (errors.dart:266:49)
    at Object.nullCheck (operations.dart:528:63)
    at [_handleEvent] (keyboard_binding.dart:347:38)
    at _engine.KeyboardConverter.new.handleEvent (keyboard_binding.dart:542:7)
    at keyboard_binding.dart:141:25
    at Object._checkAndCall (operations.dart:334:14)
    at Object.dcall (operations.dart:339:39)
    at ret (js_patch.dart:413:11)
    at loggedHandler (keyboard_binding.dart:112:23)
    at Object._checkAndCall (operations.dart:334:14)
    at Object.dcall (operations.dart:339:39)
    at ret (js_patch.dart:413:11)
throw_ @ errors.dart:266
nullCheck @ operations.dart:528
[_handleEvent] @ keyboard_binding.dart:347
handleEvent @ keyboard_binding.dart:542
(anonymous) @ keyboard_binding.dart:141
_checkAndCall @ operations.dart:334
dcall @ operations.dart:339
ret @ js_patch.dart:413
loggedHandler @ keyboard_binding.dart:112
_checkAndCall @ operations.dart:334
dcall @ operations.dart:339
ret @ js_patch.dart:413
errors.dart:266 Uncaught Error: Unexpected null value.
    at Object.throw_ [as throw] (errors.dart:266:49)
    at Object.nullCheck (operations.dart:528:63)
    at [_handleEvent] (keyboard_binding.dart:347:38)
    at _engine.KeyboardConverter.new.handleEvent (keyboard_binding.dart:542:7)
    at keyboard_binding.dart:144:25
    at Object._checkAndCall (operations.dart:334:14)
    at Object.dcall (operations.dart:339:39)
    at ret (js_patch.dart:413:11)
    at loggedHandler (keyboard_binding.dart:112:23)
    at Object._checkAndCall (operations.dart:334:14)
    at Object.dcall (operations.dart:339:39)
    at ret (js_patch.dart:413:11)
Code sample

main.dart

import 'package:flutter/material.dart';

import 'text_input_native.dart' if (dart.library.html) 'text_input_web.dart'
    as text_input;

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      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(
        title: Text(widget.title),
      ),
      body: Center(
        child: AutofillGroup(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const [
            Text(
              'Please enter email',
            ),
            Padding(
              padding: EdgeInsets.all(12.0),
              child: text_input.MyTextInput(),
            ),
            Text(
              'Please enter again',
            ),
            Padding(
              padding: EdgeInsets.all(12.0),
              child: text_input.MyTextInput(),
            ),
          ],
        )),
      ),
    );
  }
}

text_input_web.dart

import 'package:flutter/material.dart';
import 'package:universal_html/html.dart' as html;
import 'dart:ui' as ui;

class MyTextInput extends StatelessWidget {
  const MyTextInput({super.key});

  html.HtmlElement _textInput(int id) {
    return html.InputElement()
      ..id = 'text'
      ..type = 'text'
      ..name = 'text'
      ..className = 'text-input'
      ..placeholder = 'Text'
      ..autocomplete = 'email'
      ..style.cssText = 'width: 100%; height: 100%;';
  }

  @override
  Widget build(BuildContext context) {
    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory(
      'my_text_input',
      (int id) => _textInput(id),
    );

    return const SizedBox(
      height: 60,
      child: HtmlElementView(
        viewType: 'my_text_input',
      ),
    );
  }
}

text_input_native.dart

import 'package:flutter/material.dart';

class MyTextInput extends StatelessWidget {
  const MyTextInput({super.key});

  @override
  Widget build(BuildContext context) {
    return const TextField();
  }
}
Logs
[+2473 ms] Error: Unexpected null value.
                    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49      throw_
                    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63  nullCheck
                    lib/_engine/engine/keyboard_binding.dart 347:38                                   [_handleEvent]
                    lib/_engine/engine/keyboard_binding.dart 542:7                                    handleEvent
                    lib/_engine/engine/keyboard_binding.dart 141:25                                   <fn>
                    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14  _checkAndCall
                    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39  dcall
                    lib/_engine/engine/keyboard_binding.dart 112:23                                   loggedHandler
                    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14  _checkAndCall
                    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39  dcall
[   +8 ms] Error: Unexpected null value.
           dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49      throw_
           dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63  nullCheck
           lib/_engine/engine/keyboard_binding.dart 347:38                                   [_handleEvent]
           lib/_engine/engine/keyboard_binding.dart 542:7                                    handleEvent
           lib/_engine/engine/keyboard_binding.dart 144:25                                   <fn>
           dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14  _checkAndCall
           dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39  dcall
           lib/_engine/engine/keyboard_binding.dart 112:23                                   loggedHandler
           dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14  _checkAndCall
           dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39  dcall
Analyzing test_keyboard_event...                                        
No issues found! (ran in 2.1s)
[✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-x64, locale en-GB)
    • Flutter version 3.3.7 on channel stable at /Users/duy/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e99c9c7cd9 (2 days ago), 2022-11-01 16:59:00 -0700
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc5)
    • Android SDK at /Users/duy/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0-rc5
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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+0-b1504.28-7817840)

[✓] VS Code (version 1.73.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.53.20221101

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 13.0 22A380 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.87

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

• No issues found!
Screen.Recording.2022-11-03.at.16.51.50.mov

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.found in release: 3.3Found to occur in 3.3found in release: 3.5Found to occur in 3.5has 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 teamtriaged-webTriaged by Web platform team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions