import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: BottomSheetDemo(),
);
}
}
class BottomSheetDemo extends StatefulWidget {
@override
_BottomSheetDemoState createState() => new _BottomSheetDemoState();
}
class _BottomSheetDemoState extends State<BottomSheetDemo> {
final _scaffoldKey = new GlobalKey<ScaffoldState>();
VoidCallback _showPersistantBottomSheetCallBack;
@override
void initState() {
super.initState();
_showPersistantBottomSheetCallBack = _showBottomSheet;
}
void _showBottomSheet() {
setState(() {
_showPersistantBottomSheetCallBack = null;
});
_scaffoldKey.currentState
.showBottomSheet((context) {
return new Container(
height: 200.0,
color: Colors.teal[100],
child: Center(
child: Text("Drag Downwards Or Back To Dismiss Sheet",
style: TextStyle(fontSize: 18, color: Colors.black),
textAlign: TextAlign.center,),
),
);
})
.closed
.whenComplete(() {
if (mounted) {
setState(() {
_showPersistantBottomSheetCallBack = _showBottomSheet;
});
}
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.grey[200],
key: _scaffoldKey,
appBar: AppBar(
backgroundColor: Colors.cyan[200],
title: Text("Flutter Persistent BottomSheet"),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: RaisedButton(
color: Colors.teal[100],
onPressed: _showPersistantBottomSheetCallBack,
child: Text("Show Persistent BottomSheet",
style: TextStyle(color: Colors.black),
),
)),
),
);
}
}
No comments:
Post a Comment