最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Flutter Typeahead focus order using "tab" not working - Stack Overflow

programmeradmin6浏览0评论

I ran into an issue with TypeAheadField widget where pressing "tab" doesn't go to the next text field and instead goes to completely random place. In web, it actually even goes on the browser URL.

I managed to get a repro. If you go from one text field (first or last 2) to the other with "tab" or "Uppercase tab" it works perfectly. But there are 2 bugs:

  • If you go from the second text field and press "tab", you need to press it twice before it actually goes to the TypeAheadField field. Note that if you go the second last and press "uppercase tab" this goes directly to the TypeAheadField field.
  • Once the focus is on the TypeAheadField field, if you press "tab" it doesn't go anywhere useful.

This is especially problematic on web and I guess apps as well.

Any idea how to fix this?

Code:

import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  TextEditingController textController = TextEditingController();

  MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Typeahead bug',
      home: Scaffold(
        appBar: AppBar(title: const Text('Login')),
        body: Column(children: [
          TextFormField(),
          TextFormField(),
          TypeAheadField<String>(
            controller: textController,
            hideOnEmpty: true,
            debounceDuration: const Duration(),
            builder: (context, controller, focusNode) {
              return TextFormField(
                  controller: controller,
                  focusNode: focusNode,
                  autofocus: true,
                  decoration: InputDecoration(
                    labelText: 'Typeahead',
                  ));
            },
            suggestionsCallback: (v) => v == "" ? [] : ["a", "b"],
            itemBuilder: (context, v) => ListTile(title: Text(v)),
            onSelected: (String v) {
              textController.text = v;
            },
          ),
          TextFormField(),
          TextFormField(),
        ]),
      ),
    );
  }
}
发布评论

评论列表(0)

  1. 暂无评论