Skip to content

ListTile.selectedTileColor not visible when parent Container has explicit background color #174366

@cnayan

Description

@cnayan

Steps to reproduce

ListTile's selection highlighting (selectedTileColor) becomes invisible or non-functional when the ListTile is nested inside a Container with an explicit color property set.

Steps to Reproduce:

  1. Create a ListView with ListTile items inside a Container
  2. Set an explicit background color on the parent Container (e.g., Color.fromARGB(255, 27, 27, 27))
  3. Set selectedTileColor: Colors.blue on the ListTile
  4. Set selected: true on a ListTile item
  5. Observe that the selection highlighting is not visible

Expected Behavior:

  • ListTile should display the specified selectedTileColor (blue background) when selected: true, regardless of parent Container background color.

Actual Behavior:

  • ListTile selection highlighting is not visible when parent Container has an explicit color property. The blue selection background does not appear.

Workaround:

  • Remove the color property from the parent Container. The selection highlighting works correctly when no explicit color is set on parent containers.

Environment:

Flutter version: 3.35.1
Dart version: 3.9.0 (stable) (Mon Aug 11 07:58:10 2025 -0700) on "windows_x64"
Test Platform: Desktop


Code Description

// This DOESN'T work - selection not visible
Container(
  color: Color.fromARGB(255, 27, 27, 27),
  child: ListView.builder(
    itemBuilder: (context, index) => ListTile(
      title: Text('Item $index'),
      selected: selectedIndex == index,
      selectedTileColor: Colors.blue,
    ),
  ),
)

// This WORKS - selection visible
Container(
  // color: Color.fromARGB(255, 27, 27, 27), // Commented out
  child: ListView.builder(
    itemBuilder: (context, index) => ListTile(
      title: Text('Item $index'),
      selected: selectedIndex == index,
      selectedTileColor: Colors.blue,
    ),
  ),
)

Expected results

  • ListTile should display the specified selectedTileColor (blue background) when selected: true, regardless of parent Container background color.

Actual results

  • ListTile selection highlighting is not visible when parent Container has an explicit color property. The blue selection background does not appear.

Code sample

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

class Model {
  final String name;
  Model({required this.name});
}

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      darkTheme: ThemeData.dark(useMaterial3: true),
      home: Scaffold(body: const ListWidgetWrapper(
        // color: Colors.purple  // <<<========== Uncomment this to see the selection background color disappear.
      )),
    );
  }
}

class ListWidgetWrapper extends StatefulWidget {
  final Color? color;

  const ListWidgetWrapper({super.key, this.color});

  @override
  State<ListWidgetWrapper> createState() => _ListWidgetWrapperState();
}

class _ListWidgetWrapperState extends State<ListWidgetWrapper> {
  int? _selectedIndex;
  final ScrollController _scrollController = ScrollController();
  final List<Model> _list = ["AAAA", "BBBB", "CCCC"].map((x) => Model(name: x)).toList();

  @override
  Widget build(BuildContext context) {
    return Container(
      color: widget.color ?? Colors.transparent,
      child: Padding(
        padding: const EdgeInsets.all(4.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Expanded(
              child: RawScrollbar(
                controller: _scrollController,
                thumbVisibility: true,
                trackVisibility: true,
                thumbColor: Colors.blue.withAlpha(127),
                child: ListView.builder(
                  itemCount: _list.length,
                  controller: _scrollController,
                  hitTestBehavior: HitTestBehavior.opaque,
                  itemBuilder: (context, index) => _buildListItem(index),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildListItem(int index) {
    return ListTile(
      dense: true,
      minTileHeight: 24,
      iconColor: Colors.white,
      titleTextStyle: TextStyle(color: Colors.white, fontSize: 14, decoration: TextDecoration.none),
      leading: const Icon(Icons.storage, size: 12),
      minLeadingWidth: 12,
      horizontalTitleGap: 12,
      title: Text(_list[index].name, maxLines: 1, overflow: TextOverflow.ellipsis, softWrap: false),
      onTap: () => _onTap(index),
      selected: _selectedIndex == index,
      selectedTileColor: Colors.blueAccent, // <<===== I want this color as background color
    );
  }

  void _onTap(int index) {
    if (_selectedIndex != index) {
      setState(() {
        _selectedIndex = index;
      });
    }
  }
}

Screenshots or Video

Screenshots / Video demonstration
Without container color With container color
Image Image

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.35.1, on Microsoft Windows [Version 10.0.26100.4946], locale en-IN) [503ms]
    • Flutter version 3.35.1 on channel stable at D:\Dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 20f8274939 (11 days ago), 2025-08-14 10:53:09 -0700
    • Engine revision 1e9a811bf8
    • Dart version 3.9.0
    • DevTools version 2.48.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-lldb-debugging

[✓] Windows Version (11 Pro 64-bit, 24H2, 2009) [5.3s]

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [3.8s]
    • Android SDK at C:\Users\nayan\AppData\Local\Android\Sdk
    • Emulator version 36.1.9.0 (build_id 13823996) (CL:N/A)
    • Platform android-36, build-tools 36.0.0
    • ANDROID_HOME = C:\Users\nayan\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [130ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.14.12) [128ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.14.36408.4
    • Windows 10 SDK version 10.0.26100.0

[✓] Android Studio (version 2025.1.2) [21ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)

[✓] VS Code (version 1.103.2) [19ms]
    • VS Code at C:\Users\nayan\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.116.0

[✓] Connected device (3 available) [384ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.4946]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 139.0.7258.128
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 139.0.3405.102

[✓] Network resources [598ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterd: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.good first issueRelatively approachable for first-time contributorsr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions