Last active
February 27, 2019 07:39
-
-
Save IhorKlimov/908be06e2229ac9f4c0e4e0edc23e59b to your computer and use it in GitHub Desktop.
Flutter Bottom Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: '', | |
theme: ThemeData(primarySwatch: Colors.blue), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
PersistentBottomSheetController _bottomSheet; | |
BuildContext _context; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('')), | |
body: Builder(builder: (c) { | |
_context = c; | |
return Container(); | |
}), | |
floatingActionButton: FloatingActionButton(onPressed: _showBottomSheet), | |
); | |
} | |
_showBottomSheet() { | |
_bottomSheet = showBottomSheet( | |
context: _context, | |
isScrollControlled: true, | |
builder: (context) { | |
return ListView.builder( | |
itemBuilder: (context, index) { | |
return Container(height: 48, color: Colors.teal); | |
}, | |
itemCount: 30, | |
); | |
}); | |
Timer(Duration(seconds: 3), () { | |
print('Closing'); | |
_bottomSheet.close(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment