Android showModalBottomSheet已显示,但showBottomSheet未显示
安卓工作室3.6Android showModalBottomSheet已显示,但showBottomSheet未显示,android,flutter,Android,Flutter,安卓工作室3.6 class MainScreen extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: new Color(Constants.COLOR_PRIMARY_DARK))); return new S
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)),
因此,showModalBottomSheet成功展示。但是我需要显示showBottomSheet。我将showModalBottomSheet替换为showModalBottomSheet。因此,showBottomSheet不显示。您可以复制下面的粘贴运行完整代码
您可以使用
\u 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(),
);
}
}
导入“包装:颤振/材料.省道”;
导入“包:flifter/services.dart”;
类MainScreen扩展了无状态小部件{
最终GlobalKey _scaffoldKey=GlobalKey();
小部件_createProfileContainer(BuildContext上下文){
返回手势检测器(
onTap:(){
_显示发票(上下文);
},
子项:文本(“单击”);
}
void\u showBottomSheetInvoice(BuildContext上下文){
//_logger.d(“_显示发票:”);
_scaffoldKey.currentState.showBottomSheet((构建上下文){
返回容器(
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
填充物(
填充:常数边集全部(16.0),
子:文本(
'底部条形图的永久标头!',
textAlign:textAlign.left,
)),
正文(
“那么这里可能会有其他内容”
'将显示在底部栏中',
textAlign:textAlign.left,
),
],
));
});
}
@凌驾
小部件构建(构建上下文){
SystemChrome.SetSystemTimeOverlayStyle(
SystemUIOverlyStyle(statusBarColor:Colors.blue));
返回脚手架(
钥匙:_scaffoldKey,
正文:安全区(
子:SingleChildScrollView(
子:容器(
边距:仅限常量边集(左:4,右:4,下:4),
子项:列(子项:[
填充物(
填充:仅限边缘设置(顶部:4),
子项:_createProfileContainer(上下文)),
])))));
}
}
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
主屏幕:主屏幕(),
);
}
}
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(),
);
}
}