showModalBottomSheet adaptive size Flutter

397 views Asked by At

I have the next problem, having a little number of children allows users to scroll even though there is an empty space

Future<void> buildScrollableSheet([Widget? header]) {
    return showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) => makeDismissible(
        child: DraggableScrollableSheet(
          initialChildSize: 0.3,
          maxChildSize: 0.9, // this one should be adaptive
          builder: (_, controller) => Container(
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.vertical(
                top: Radius.circular(25),
              ),
            ),
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Column(
              // crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                const Padding(
                  padding: EdgeInsets.all(24),
                  child: Center(
                    child: Text(
                      'My header',
                      style: TextStyle(
                        color: Color(0xff757575),
                        fontSize: 14,
                      ),
                    ),
                  ),
                ),
                Flexible(
                  child: Material(
                    color: Colors.white,
                    child: ListView(
                      shrinkWrap: true,
                      controller: controller,
                      children: [
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

Here you can see maxChildSize is being set as 0.9 which is fine with a lot of children inside ListView, but in this case, there are only 3 elements and I want to prevent scrolling to full size, also it would be great to set initialChildSize to childs size, so if I have a huge list of items it would always open full. Thank you!

showModalBottomSheet openedModalSheet

0

There are 0 answers