简体   繁体   English

不显示底部表

[英]Not show bottomSheet

Android Studio 3.6 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)),
          );
        });
  }

When I tap the message " _showBottomSheetNotification_start " is show in logcat but bottomSheet not show.当我点击消息“ _showBottomSheetNotification_start ”时,logcat 中显示但bottomSheet不显示。

error:错误:

════════ 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"

Try wrapping your MainScreen widget inside MaterialApp as it's home property.尝试将MainScreen小部件包装在MaterialApp中,因为它是 home 属性。 Example:例子:

void main() => runApp(new MaterialApp(home: new MainScreen()));

class MainScreen extends StatelessWidget {

  // some cool codes ;-) 

}

Solution Reference: See this issue解决方案参考: 见this issue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM