Flutter程序PROFILE页面的上滑面板功能无法将参数类型'JsObject'分配给参数类型'BuildContext'
// Panel Body
SingleChildScrollView _panelBody(ScrollController controller) {
double hPadding = 40;
return SingleChildScrollView(
controller: controller,
physics: const ClampingScrollPhysics(),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: hPadding),
height: MediaQuery.of(context).size.height * 0.35,
^ context is the one that sending error signals which is The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'. I imported the dart.js that it recommended yet it did not fix the error
)
],
),
);
}
需要在_panelBody函数中传递buildContext。
SingleChildScrollView _panelBody(ScrollController controller, BuildContext context) {
double hPadding = 40;
return SingleChildScrollView(
controller: controller,
physics: const ClampingScrollPhysics(),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: hPadding),
height: MediaQuery.of(context).size.height * 0.35,
)
],
),
);
}
并将小部件称为
_panelBody(controller, context)
在 _panelBody 函数中添加上下文
SingleChildScrollView _panelBody(ScrollController controller, BuildContext context) { // <----HERE
然后无论你在哪里使用方法_panelBody,都使用如下代码
_panelBody(controller,context)