Skip to content

Inactive (onTap: null) ListTile keeps hover state until mouse out #117733

@gialdeyn

Description

@gialdeyn
inactive-listtile-keeps-hover.mov

Steps to Reproduce

(I tried in web)

  1. Execute flutter run on the code sample
  2. Click on unselected item (and keep mouse cursor on it)

Expected results:
The ListTile immediately becomes inactive. Without any hover state and with its default background.

Actual results:
The ListTile keeps some kind of hover state (with different background color) until mouse cursor leaves it.

By the way, mouse cursor type depends on active/inactive state of the ListTile and switches correctly.

Code sample
import 'package:flutter/material.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: ListView(
          children: ['Title 1', 'Title 2']
              .asMap()
              .entries
              .map((entry) => ListTile(
                    title: Text(entry.value),
                    subtitle: Text(
                        entry.key == selectedIndex ? 'is selected' : 'sub'),
                    onTap: entry.key == selectedIndex
                        ? null
                        : () {
                            setState(() {
                              selectedIndex = entry.key;
                            });
                          },
                  ))
              .toList(),
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopa: mouseIssues related to using a mouse or mouse supportf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions