Skip to content

Instantly share code, notes, and snippets.

@rishi-singh26
Created March 2, 2024 06:10
Show Gist options
  • Save rishi-singh26/b3dd20265c54353c6440a5475ceee266 to your computer and use it in GitHub Desktop.
Save rishi-singh26/b3dd20265c54353c6440a5475ceee266 to your computer and use it in GitHub Desktop.
Implement a draggable and scrollable bottom sheet In flutter.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final Completer<GoogleMapController> _controller = Completer<GoogleMapController>();
static const CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(37.42796133580664, -122.085749655962),
zoom: 14.4746,
);
final DraggableScrollableController sheetController = DraggableScrollableController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Stack(
children: [
GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),
DraggableScrollableSheet(
controller: sheetController,
builder: (BuildContext context, scrollController) {
return Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: Theme.of(context).canvasColor,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25),
),
),
child: CustomScrollView(
controller: scrollController,
slivers: [
SliverToBoxAdapter(
child: Center(
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).hintColor,
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
height: 4,
width: 40,
margin: const EdgeInsets.symmetric(vertical: 10),
),
),
),
const SliverAppBar(
title: Text('My App'),
primary: false,
pinned: true,
centerTitle: false,
),
SliverList.list(children: [
FilledButton.tonal(
onPressed: () {
sheetController.animateTo(
0.8,
duration: const Duration(milliseconds: 200),
curve: Curves.bounceIn,
);
},
child: const Text('Scrool to 0.8'),
),
const ListTile(title: Text('Jane Doe')),
const ListTile(title: Text('Jack Reacher')),
])
],
),
);
},
),
],
),
);
}
}
@Naimishimaker
Copy link

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment