💻
Flutter documentation
  • Flutter documentation
    • Starting an App
    • Import
  • Visual Studio Code
  • Widgets
    • Stateless Widget
    • Stateful Widget
    • Scaffold
    • Text
      • OverFlow
      • Rounded background text
    • Padding
    • Align
    • DraggableScrollableSheet
    • Container
    • Decorated box
    • Expanded
    • IntrinsicHeight
    • IntrinsicWidth
    • ListView.builder(...)
    • Buttons
    • Gauge
    • Navigator
      • WillPopScope
    • Web View
    • Divider
    • Future builder
    • Image
      • Cached_network_image
      • Fade In Image
    • ClipOval
    • InkWell
    • Wrap
    • SingleChildScrollView
    • Stack
    • FittedBox
    • DropdownButton
    • ValueListenableBuilder
    • Maps
    • fl_chart
    • Set SystemNavigation Bar Color
    • Onesignal
    • Builder
    • Set orientation
    • SSE
    • Chat
    • Flutter_animate
    • Supabase
      • Android
    • Changing name and package name
    • Sign apk/abb
  • Dart
    • If / Else in one line
    • Functions
  • Others
  • Airtable
Powered by GitBook
On this page
  1. Widgets

DraggableScrollableSheet

It is declared like this:

DraggableScrollableSheet(
//...
)

WARNING:

It is recommended to put the widget inside a stack so that it is on top of the other widgets.

It would look like this:

Stack(children: <Widget>[
   //DraggableScrollableSheet(...
 ]
)

A DraggableScrollableSheet needs a builder

DraggableScrollableSheet(

builder: (context, scrollController){
return // Widgets example Container()
}

)

Inside the builder it is necessary to have a scroll type widget such as a SingleChildScrollView. And to make it move, it is necessary to connect it with the scrollController with: controller: scrollController

DraggableScrollableSheet(
//  initialChildSize: 0.1,
//  minChildSize: 0.1,
//  maxChildSize: 1,
                
  builder: (context, scrollController) {
    return Container(
       
         child: SingleChildScrollView(
         controller: scrollController,
        // other widgets          
      )
    );
  }
)

Options

The DraggableScrollableSheet have different options:

DraggableScrollableSheet(

// Initial size
initialChildSize: 0.1, // from 0.0 to 1.0

// Min size
minChildSize: 0.1, // from 0.0 to 1.0

// Max size
maxChildSize: 1, // from 0.0 to 1.0

  builder: (context, scrollController) {
    return Container(
       
         child: SingleChildScrollView(
         controller: scrollController,
        // other widgets          
      )
    );
  }
)

And finally, you can add decoration to the container to enhance the visual appearance.

DraggableScrollableSheet(

// Initial size
initialChildSize: 0.1, // from 0.0 to 1.0

// Min size
minChildSize: 0.1, // from 0.0 to 1.0

// Max size
maxChildSize: 1, // from 0.0 to 1.0

  builder: (context, scrollController) {
    return Container(
       
         child: SingleChildScrollView(
         controller: scrollController,
        // other widgets          
      ),
      
      // decoration here
  decoration: BoxDecoration(
        color: Colors.red,
        borderRadius: BorderRadius.only(
        topLeft: Radius.circular(50),
        topRight: Radius.circular(50),
      )
    ),
      
    );
  }
)

If you are running this on the web, it would not work, to get this to work you need to put the following code:

// This in 👇
//class MyApp extends StatelessWidget {
//  @override
//  Widget build(BuildContext context) {
//    return MaterialApp(


        scrollBehavior: MaterialScrollBehavior().copyWith(
          dragDevices: {
            PointerDeviceKind.mouse,
            PointerDeviceKind.touch,
            PointerDeviceKind.stylus,
            PointerDeviceKind.unknown
          },
        ),

Also, you will need to import import 'package:flutter/gestures.dart';

Widget example:


class ImageRoundedWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(30),
        image: const DecorationImage(
            image: NetworkImage(
              "https://www.onadesants.cat/wp-content/uploads/2021/05/radio-targeta.jpg",
            ),
            fit: BoxFit.cover),
        boxShadow: const [
          BoxShadow(
            color: Colors.black,
            blurRadius: 50.0, // soften the shadow
            spreadRadius: 2.0, //extend the shadow
            offset: Offset(
              15.0, // Move to right 10  horizontally
              8.0, // Move to bottom 10 Vertically
            ),
          )
        ],
      ),
    );
  }
}
PreviousAlignNextContainer

Last updated 2 years ago