Reputation: 15646
android studio 3.6
class MainScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: new Color(Constants.COLOR_PRIMARY_DARK)));
return new Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: new Container(
margin: const EdgeInsets.only(
left: Constants.DEFAULT_MARGIN,
right: Constants.DEFAULT_MARGIN,
bottom: Constants.DEFAULT_MARGIN),
child: new Column(children: [
new Padding(
padding:
EdgeInsets.only(top: Constants.DEFAULT_MARGIN),
child: _createProfileContainer(context)),
...
Widget _createProfileContainer(BuildContext context) {
return new GestureDetector(
onTap: () {
_showBottomSheetInvoice(context);
},
child:
...
void _showBottomSheetInvoice(BuildContext context) {
_logger.d("_showBottomSheetInvoice: ");
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return new Container(
color: new Color(Constants.BOTTOM_SHEET_BG),
child:
As result the showModalBottomSheet success show. But I need to show showBottomSheet. I replace showModalBottomSheet by showBottomSheet. And as result the showBottomSheet not show.
Upvotes: 1
Views: 1097
Reputation: 54365
You can copy paste run full code below
You can use _scaffoldKey.currentState.showBottomSheet
code snippet
void _showBottomSheetInvoice(BuildContext context) {
_scaffoldKey.currentState.showBottomSheet((BuildContext context) {
return Container(
child: Column(
working demo
full code
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(),
);
}
}
Upvotes: 1