Skip to content

InkWell overlay colors aren't applied on MaterialState.selected state #159063

@bleroux

Description

@bleroux

Steps to reproduce

  1. Run the code sample.
  2. Hover the InkWell square at the center of the screen.

Expected results

The overlay color is green (the one for selected + hovered states):

Enregistrement.de.l.ecran.2024-11-18.a.09.32.52.mov

Actual results

The overlay color is yellow (selected state is ignored):

Enregistrement.de.l.ecran.2024-11-18.a.09.31.41.mov

Code sample

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> {
  late WidgetStatesController _controller;

  @override
  void initState() {
    super.initState();
    _controller =
        WidgetStatesController(<WidgetState>{WidgetState.selected});
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final WidgetStateProperty<Color> overlayColor =
        WidgetStateProperty.resolveWith((Set<WidgetState> states) {
      if (states.contains(WidgetState.selected)) {
        if (states.contains(WidgetState.hovered)) {
          return Colors.green;
        }
      }
      if (states.contains(WidgetState.hovered)) {
        return Colors.red;
      }
      return Colors.transparent;
    });

    return MaterialApp(
      home: Directionality(
        textDirection: TextDirection.ltr,
        child: Material(
          child: Center(
            child: InkWell(
              statesController: _controller,
              overlayColor: overlayColor,
              onTap: () {},
              child: Container(
                decoration: BoxDecoration(border: Border.all()),
                width: 100,
                height: 100,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
Flutter (Channel [user-branch], 3.27.0-1.0.pre.538, on macOS 14.2.1 23C71
    darwin-arm64, locale fr-FR)

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.found in release: 3.24Found to occur in 3.24found in release: 3.27Found to occur in 3.27frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions