1

I have a ListView.builder where I want to show containers with shadows. And I want a shadow of one container to cover another container. Example of how it should looks. It easily to do with Stack widget, but I have no idea how to do it inside ListView.builder.

Solution that works fine for me

Instead of using ListView I've decided to use CustomScrollView that takes slivers as parameters. Inside slivers I'm maping through a list of items and return my container wrapped with SliverToBoxAdapter. I don't know exactly how it works, but it works fine for me.

CustomScrollView(
  slivers: [
    ...names.map(
      (e) => SliverToBoxAdapter(
        child: Center(
          child: CustomContainer(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('Container #${e['name']}'),
                  Text('Age is ${e['age']} y.o.')
                ],
              ),
            ),
          ),
        ),
      ),
    ),
  ],
),
2
  • You simply can't make items overlap inside the ListView, that is the purpose of the Stack as you mentioned. May I ask the use case behind it ? Commented Jun 15, 2021 at 9:02
  • I just have a design where I have a list of items that should be shown in this way. @Wapazz Commented Jun 15, 2021 at 9:11

2 Answers 2

0

// if scroll view overflow on other widget then use ClipRRect With Expanded.

ClipRRect(
child: Expanded(
child: CustomScrollView(
clipBehavior: Clip.none, //add this line inside CustomScrollView
  slivers: [
    ...names.map(
      (e) => SliverToBoxAdapter(
        child: Center(
          child: CustomContainer(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('Container #${e['name']}'),
                  Text('Age is ${e['age']} y.o.')
                ],
              ),
            ),
          ),
        ),
      ),
    ),
  ],
),),),

I face the same problem and i use this tricks and it's solved.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Amir, that's what I need. Btw do you have any thoughts, how can I do something similar but in this time I need use shadow inside a grid view?
0

You can use index of listview and give different elevation of card according to index.

 ListView.builder(
          itemCount:10,
          shrinkWrap: true,
          itemBuilder: (ctx, i) {
            return Card(
              elevation: (i%2 == 1)?10 :0,
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Row(
                  crossAxisAlignment:CrossAxisAlignment.center,
                  mainAxisAlignment:MainAxisAlignment.center,
                  children: [
                    Text("Container $i"),
                  ],
                ),
              ),
            );
          }),

1 Comment

Thanks for the answer but it's not what I actually need. What l need is a shadow from one container to cover another container.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.