您可以在下面复制粘贴运行完整代码
您可以使用
_scaffoldKey.currentState.showBottomSheet
代码片段
void _showBottomSheetInvoice(BuildContext context) {
_scaffoldKey.currentState.showBottomSheet((BuildContext context) {
return Container(
child: Column(
工作演示
完整代码
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class MainScreen extends StatelessWidget {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
Widget _createProfileContainer(BuildContext context) {
return GestureDetector(
onTap: () {
_showBottomSheetInvoice(context);
},
child: Text("click"));
}
void _showBottomSheetInvoice(BuildContext context) {
//_logger.d("_showBottomSheetInvoice: ");
_scaffoldKey.currentState.showBottomSheet((BuildContext context) {
return Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'Persistent header for bottom bar!',
textAlign: TextAlign.left,
)),
Text(
'Then here there will likely be some other content '
'which will be displayed within the bottom bar',
textAlign: TextAlign.left,
),
],
));
});
}
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.blue));
return Scaffold(
key: _scaffoldKey,
body: SafeArea(
child: SingleChildScrollView(
child: Container(
margin: const EdgeInsets.only(left: 4, right: 4, bottom: 4),
child: Column(children: [
Padding(
padding: EdgeInsets.only(top: 4),
child: _createProfileContainer(context)),
])))));
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MainScreen(),
);
}
}