Skip to content

Pressing a suffix icon button on a TextField fires both the TextField-onTap and IconButton-onPressed callbacks #118340

Description

@Renzo-Olivares

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:

  1. Tap drop down arrow at the end of the text field.
  2. Check logs for debug print statements.

Expected: Only onPressed is fired.
Actual: onTap and onPressed is fired.

Activity

  1. added
    a: text inputEntering text in a text field or keyboard related problems
    c: regressionIt was better in the past than it is now
    on Jan 11, 2023
  2. github-actions commented on Mar 4, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  3. locked as resolved and limited conversation to collaborators on Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

a: text inputEntering text in a text field or keyboard related problemsc: regressionIt was better in the past than it is now

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions