0

I wrote a list of card, and limit its max height. I want the card bottom fade when its height is over the limit, fade is not displayed when the limit is not exceeded.

The following is the effect I want

enter image description here

my code

Widget _buildBody(BuildContext context) {
return CustomScrollView(
  slivers: [
    SliverList(
        delegate: SliverChildBuilderDelegate(
      (context, index) {
        return ConstrainedBox(
          constraints: const BoxConstraints(maxHeight: 200),
          child: Wrap(
            children: [
              const Card(
                child: ListTile(
                  title: Text('test title'),
                  subtitle: Text(
                      'test \n test \n test test test test test test test test test testtest test test test test test test test '),
                ),
              ),
            ],
          ),
        );
      },
      childCount: 10,
    ))
  ],
);

enter image description here

Ken White
  • 123,280
  • 14
  • 225
  • 444
Jeremy
  • 21
  • 2

1 Answers1

0

I think you were meaning to constrain the height of the individual cards:

Using a ShaderMask you can achieve this effect: the effect

CustomScrollView(
        slivers: [
          SliverList(
              delegate: SliverChildBuilderDelegate(
            (context, index) {
              return Wrap(
                children: [
                  ConstrainedBox(
                    constraints:
                        const BoxConstraints(maxHeight: 200),
                    child: Card(
                      color: Colors.white,
                      child: ListTile(
                        title: Text('test title',),
                        subtitle: ShaderMask(
                          shaderCallback: (bounds) => LinearGradient(
                            begin: Alignment.center,
                            end: Alignment.bottomCenter,
                            colors: [Colors.white, Colors.transparent],
                          ).createShader(bounds),
                          child: Text('test \n test \n test test test test test test test test test testtest test test test test test test test test test test test test test test test test test testtest test test test test test test test ',),
                        ),
                      ),
                    ),
                  ),
                ],
              );
            },
            childCount: 10,
          ))
        ],
      ),
Dominic
  • 322
  • 1
  • 8
  • great !But I don't know which card exceeds the height limit。Is there any way to do it? – Jeremy Jan 09 '23 at 15:42