很好奇为什么我的onPressed函数不能在调试模式下工作



我正试图在onPressed方法中实现颤振中的简单底板

这是我的代码

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class LoginScreen extends StatelessWidget {
void _onButtonPressed(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (context) => new Column(
children: [
new Container(
child: Text('Hello'),
)
],
));
}
@override
Widget build(BuildContext context) => new Scaffold(
body: new RaisedButton(
onPressed: () => _onButtonPressed(context),
child: Text('Hello'),
),
);
}

因此,每当我将flatterMode设置为启动文件调试模式时,当我点击按钮时,它会显示异常

'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3524 pos 12: '!_debugLocked': is not true.

但是,当我在配置文件或发布模式下构建应用程序时,底部表单就像一个魅力。这有什么具体的原因吗?

因为我有另一个页面,它也实现了底部工作表,但它适用于任何模式。

刚刚在安卓工作室上构建了这个应用程序

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3524 pos 12: '!_debugLocked': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
When the exception was thrown, this was the stack: 
#2      NavigatorState.push (package:flutter/src/widgets/navigator.dart:3524:12)
#3      showModalBottomSheet (package:flutter/src/material/bottom_sheet.dart:667:65)
#4      _LoginScreen._onButtonPressed (package:mahayoga_admin/loginScreen.dart:10:5)
#5      _LoginScreen.build.<anonymous closure> (package:mahayoga_admin/loginScreen.dart:29:53)
#6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#095ab
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(18.8, 44.1)
finalLocalPosition: Offset(44.0, 18.0)
button: 1
sent tap down
════════════════════════════════════════════════════════════════════════════════════════════════════

所以我把代码改成了这个

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mahayoga_admin/bottomSheetDrawer.dart';
class LoginScreen extends StatefulWidget {
State<StatefulWidget> createState() => _LoginScreen();
}
class _LoginScreen extends State<LoginScreen> {
void _onButtonPressed(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (context) => SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: new Container(
child: Text("Hello world"),
),
),
));
}
@override
Widget build(BuildContext context) => new Scaffold(
body: new Container(
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
child: new Container(
child: Column(
children: [
new RaisedButton(onPressed: () => _onButtonPressed(context))
],
),
),
)));
}

要解决这个问题,只需将其包装在Container中,并将高度设置为屏幕最大高度,如下所示:

@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
child: ... //You can then have a column warped within a container(height specified)....after that under column use the raised button
),
),
}

很抱歉打扰了大家,但就我手动调试而言,这是我在屏幕上导航应用程序的方式。实际发生的事情是,我跳到问题陈述中提到的屏幕上,检查用户是否通过了身份验证,是否处于以前状态的onUnit函数中。正如我提到的,在之前的状态中,我实现了底部表单。S实现失败了,突然我跳到了另一个屏幕上,这就是为什么在上面的屏幕上我无法获得我的底页。所以我所要做的就是正确地改变我的导航。

最新更新