Pressing an IconButton that was added to a TextField through InputDecoration, fires both an onPressed callback from the IconButton as well as the onTap callback from the TextField. Only the onPressed callback from the IconButton should be fired.
Code sample:
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for Material Design 3 [TextField]s.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const TextFieldExamplesApp());
}
class TextFieldExamplesApp extends StatelessWidget {
const TextFieldExamplesApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('TextField Examples')),
body: Column(
children: <Widget>[
Spacer(),
SizedBox(
width: 500,
child: TextField(
onTap: () {
print(StackTrace.current);
print('onTap is called');
},
decoration: InputDecoration(
enabled: true,
label: Text('label'),
hintText: '',
suffixIcon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: IconButton(
icon: const Icon(Icons.arrow_drop_down),
selectedIcon: const Icon(Icons.arrow_drop_up),
onPressed: () {
print('onPressed is called');
// _textFocusNode.requestFocus();
// handlePressed(controller);
},
),
),
)
),
),
Spacer(),
],
),
),
);
}
}
Steps to reproduce:
- Tap drop down arrow at the end of the text field.
- Check logs for debug print statements.
Expected: Only onPressed is fired.
Actual: onTap and onPressed is fired.
Pressing an
IconButtonthat was added to aTextFieldthroughInputDecoration, fires both anonPressedcallback from theIconButtonas well as theonTapcallback from theTextField. Only theonPressedcallback from theIconButtonshould be fired.Code sample:
Steps to reproduce:
Expected: Only
onPressedis fired.Actual:
onTapandonPressedis fired.