4

I have a ListView inside a ListView and the inner ListView doesn't know how height it should be so I have to give it a specific height with for example a SizedBox. However the problem is that I actually want the inner ListView to shrink wrap so that it wont scroll/take unnecessary space within the parent ListView.

Thanks in advance

2
  • 1
    I am a bit confused about your question, have you tried to set the shrinkWrap property to true ? Commented Aug 19, 2017 at 17:27
  • 1
    Maybe use a Column instead of the nested ListView? Commented Aug 19, 2017 at 17:31

1 Answer 1

16

This sounds like a good use case for CustomScrollView.

video

import 'dart:async';
import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
    home: new Scaffold(
      body: new CustomScrollView(
        slivers: [
          new SliverToBoxAdapter(
            child: new Container(height: 100.0, color: Colors.blueAccent),
          ),
          new SliverList(
            delegate: new SliverChildListDelegate(
              new List<Widget>.generate(10, (int index) {
                return new Text(
                  'Item $index',
                  style: new TextStyle(fontSize: 42.0),
                );
              }),
            ),
          ),
          new SliverToBoxAdapter(
            child: new Container(height: 100.0, color: Colors.tealAccent),
          ),
        ],
      ),
    ),
  ));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.