【问题标题】:Not show bottomSheet不显示底部表
【发布时间】: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"

【问题讨论】:

    标签: android flutter


    【解决方案1】:

    尝试将您的 MainScreen 小部件包装在 MaterialApp 中,因为它是 home 属性。示例:

    void main() => runApp(new MaterialApp(home: new MainScreen()));
    
    class MainScreen extends StatelessWidget {
    
      // some cool codes ;-) 
    
    }
    

    解决方案参考:See this issue

    【讨论】:

    • 没有帮助。不显示底页。但是如果我尝试 showModalBottomSheet 那么它会成功显示
    猜你喜欢
    • 2020-12-11
    • 2013-02-06
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 2020-05-24
    • 2019-08-03
    • 2022-09-22
    相关资源
    最近更新 更多