【发布时间】:2020-04-06 13:03:54
【问题描述】:
Android Studio 3.6
@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: _createScanCheckContainer(context)),
])))));
}
Widget _createScanCheckContainer(BuildContext context) {
return new GestureDetector(
onTap: () {
_logger
.d("_createScanCheckContainer: onTap -> forward_to_scan_screen");
// only for test
_showBottomSheetNotification(context);
},
child: new Container(
height: 56.0,
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(Constants.ROUNDED_CORNER_RADIUS)),
color: Color(Constants.COLOR_PRIMARY),
boxShadow: [_createBoxShadow()]),
child: Stack(children: [
new Positioned(
left: Constants.DEFAULT_MARGIN,
top: Constants.DEFAULT_MARGIN,
bottom: Constants.DEFAULT_MARGIN,
child: new Image.asset('assets/images/ic_scan_ticket.png'),
),
new Expanded(
child: Align(
alignment: Alignment.center,
child: Text("Scan receipt",
style: TextStyle(fontSize: 19.0, color: Colors.white)),
))
])));
}
void _showBottomSheetNotification(BuildContext context) {
_logger.d("_showBottomSheetNotification_start");
showBottomSheet(
context: context,
builder: (context) {
return new Container(
height: 135.0,
color: Colors.orange,
child: new Text("Test message",
style: TextStyle(color: Colors.white)),
);
});
}
当我点击消息“_showBottomSheetNotification_start”时,logcat 中显示但 bottomSheet 不显示。
错误:
════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
No Scaffold widget found.
MainScreen widgets require a Scaffold widget ancestor.
The specific widget that could not find a Scaffold ancestor was: MainScreen
The ancestors of this widget were:
: MaterialApp
state: _MaterialAppState#2c9e7
: MyApp
...
Typically, the Scaffold widget is introduced by the MaterialApp or WidgetsApp widget at the top of your application widget tree.
When the exception was thrown, this was the stack:
#0 debugCheckHasScaffold.<anonymous closure> (package:flutter/src/material/debug.dart:112:7)
#1 debugCheckHasScaffold (package:flutter/src/material/debug.dart:123:4)
#2 showBottomSheet (package:flutter/src/material/bottom_sheet.dart:721:10)
#3 MainScreen._showBottomSheetNotification (package:flutter_sample/screens/main_screen.dart:375:5)
#4 MainScreen._createScanCheckContainer.<anonymous closure> (package:flutter_sample/screens/main_screen.dart:183:11)
...
Handler: "onTap"
【问题讨论】: