-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
r: invalidIssue is closed as not validIssue is closed as not valid
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Type a character on the text field.
- Watch the console for logs.
Expected results
The onKeyEvent should only be triggered once.
Actual results
The onKeyEvent is triggered twice.
Code sample
Code sample
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'application',
theme: ThemeData(useMaterial3: true),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
final Map<String, Widget Function()> tabMap = {
'Tab A': () => const TabAContent(),
'Tab B': () => const SizedBox.shrink(),
'Tab C': () => const SizedBox.shrink(),
};
final tabs = tabMap.keys.map((final title) => Tab(text: title));
final views = tabMap.values.map((final e) => e());
return Scaffold(
body: DefaultTabController(
length: tabs.length,
child: CustomScrollView(
scrollBehavior: ScrollConfiguration.of(context).copyWith(
scrollbars: false,
),
slivers: [
const SliverAppBar(title: Text('Application'), pinned: true),
SliverFillRemaining(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TabBar(tabs: tabs.toList(growable: false)),
Expanded(
child: TabBarView(
children: views.toList(growable: false),
),
),
],
),
),
),
],
),
),
);
}
}
class TabAContent extends StatelessWidget {
const TabAContent({super.key});
@override
Widget build(final BuildContext context) {
return ListView(
padding: EdgeInsets.zero,
children: const [Field()],
);
}
}
class Field extends StatefulWidget {
const Field({super.key});
@override
State<StatefulWidget> createState() => _FieldState();
}
class _FieldState extends State<Field> {
late final FocusNode _focusNode;
@override
void initState() {
super.initState();
_focusNode = FocusNode(onKeyEvent: (node, event) {
print('I am called');
return KeyEventResult.ignored;
});
}
@override
void dispose() {
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return TextField(focusNode: _focusNode);
}
}Screenshots or Video
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 3.12.0, on Microsoft Windows [Version 10.0.19045.3086], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.3)
[√] Android Studio (version 2022.2)
[√] VS Code (version 1.79.2)
[√] Connected device (3 available)
[√] Network resources
• No issues found!Metadata
Metadata
Assignees
Labels
r: invalidIssue is closed as not validIssue is closed as not valid