Skip to content

ListTile with tileColor behaves strange in sliver with animation #83124

Closed

Description

@TatsuUkraine

When ListTile with specified tileColor is used inside slivers, it behaves strange during an animation apply.

Steps to Reproduce

Use the following code example and tap on Toggle button to hide and then show the list tile.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatefulWidget {
  @override
  _MyWidgetState createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  bool _show = true;
  
  @override
  Widget build(BuildContext context) {
    
    return Scaffold(
      appBar: AppBar(title: Text('Tile example')),
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: AnimatedSwitcher(
              duration: Duration(milliseconds: 300),
              transitionBuilder: (Widget child, Animation<double> animation) =>
                SizeTransition(
                  sizeFactor: animation,
                  axisAlignment: 1,
                  child: child,
                ),
              child: _show ? ListTile(
                tileColor: Colors.yellow,
                title: Text('Titlte'),
              ) : SizedBox.shrink(),
            ),
          ),
          SliverToBoxAdapter(
            child: ElevatedButton(
              child: Text('toggle'),
              onPressed: () {
                setState(() {
                  _show = !_show;
                });
              },
            ),
          ),
        ],
      ),
      
    );
  }
}

Expected results: ListTile should remain color after it opened

Actual results: Color is missing

First noticed Flutter 2.2

Logs

[✓] Flutter (Channel stable, 2.2.0, on macOS 11.3 20E232 darwin-x64, locale ru-UA)
    • Flutter version 2.2.0 at /Users/tatsu/flutter
    • Framework revision b22742018b (7 days ago), 2021-05-14 19:12:57 -0700
    • Engine revision a9d88a4d18
    • Dart version 2.13.0

Activity

  1. AbhishekDoshi26 commented on May 23, 2021

    @AbhishekDoshi26

    Reproducible.

  2. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    on May 24, 2021
  3. xu-baolin commented on May 24, 2021

    @xu-baolin
    Member

    Relation issues, #73315 #59963

  4. xu-baolin commented on Jun 16, 2021

    @xu-baolin
    Member

    @TatsuUkraine Hi, here is a workaround:

    import 'package:flutter/material.dart';
    
    final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: Center(
              child: MyWidget(),
            ),
          ),
        );
      }
    }
    
    class MyWidget extends StatefulWidget {
      @override
      _MyWidgetState createState() => _MyWidgetState();
    }
    
    class _MyWidgetState extends State<MyWidget> {
      bool _show = true;
    
      @override
      Widget build(BuildContext context) {
    
        return Scaffold(
          appBar: AppBar(title: Text('Tile example')),
          body: CustomScrollView(
            slivers: [
              SliverToBoxAdapter(
                child: AnimatedSwitcher(
                  duration: Duration(milliseconds: 300),
                  transitionBuilder: (Widget child, Animation<double> animation) =>
                      SizeTransition(
                        sizeFactor: animation,
                        axisAlignment: 1,
                        child: child,
                      ),
                  child: _show ? Material(
                    child: ListTile(
                      tileColor: Colors.yellow,
                      title: Text('Titlte'),
                    ),
                  ) : SizedBox.shrink(),
                ),
              ),
              SliverToBoxAdapter(
                child: ElevatedButton(
                  child: Text('toggle'),
                  onPressed: () {
                    setState(() {
                      _show = !_show;
                    });
                  },
                ),
              ),
            ],
          ),
    
        );
      }
    }
  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 16, 2021
  6. TatsuUkraine commented on Jun 20, 2021

    @TatsuUkraine
    Author

    Thanks, it may solve the problem. Will let you know when I try it. Another workaround that I'm using now is a ColoredBox around the ListTile. Could you explain how Material widget solves the problem?

  7. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 20, 2021
  8. self-assigned this
    on Apr 20, 2022
  9. TahaTesser commented on Jul 13, 2022

    @TahaTesser
    Contributor

    This is fixed by #105760

  10. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jul 13, 2022
  11. moved this to Done (PR merged) in Nevercodeon Jul 18, 2022
  12. github-actions commented on Jul 27, 2022

    @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.

  13. locked as resolved and limited conversation to collaborators on Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions