Flutter错误,渲染库捕获异常
Flutter error, Exception caught by rendering library
我的代码之前运行良好,然后当我 运行 flutter 升级并下载最新版本时,每次我尝试按下按钮移动到下一页。我收到“渲染库错误捕获的异常。
这是我得到的错误
════════ Exception caught by rendering library ═════════════════════════════════
Null check operator used on a null value
The relevant error-causing widget was
PageView
lib\menu_frame.dart:59
════════════════════════════════════════════════════════════════════════════════
E/flutter ( 5787): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Null check
operator used on a null value.
这是我为那个特定页面准备的代码
class MenuFrame extends StatelessWidget {
PageController pageController = PageController();
@override
Widget build(BuildContext context) {
return Material(
child: Container(
child: Column(
children: <Widget>[
SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 28.0, vertical: 40.0),
child: Column(
children: <Widget>[
Icon(
FontAwesomeIcons.heartBroken,
color: Color.fromRGBO(245, 48, 111, 1.0),
size: 60.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'VORTEX',
style: TextStyle(
fontSize: 38.0,
fontWeight: FontWeight.bold,
color: Color.fromRGBO(245, 48, 111, 1.0),
),
),
Text(
'FITNESS',
style: TextStyle(
fontSize: 38.0,
fontWeight: FontWeight.bold,
),
),
],
),
Text(
'Find your passion for fitness!',
style: TextStyle(color: Colors.white, fontSize: 18.0),
textAlign: TextAlign.center,
),
// SizedBox(
// height: 85.0,
// ),
],
),
),
),
Expanded(
child: PageView(
controller: pageController,
//physics: NeverScrollableScrollPhysics(),
children: <Widget>[
HomeSignInWidget(
goToSignIn: () {
pageController.animateTo(1,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn);
},
goToSignUp: () {
pageController.animateTo(2,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn);
},
),
SignIn(),
CreateLogin(
cancelBackToHome: () {
pageController.animateTo(0,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn);
},
),
],
),
),
],
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(255, 123, 67, 1.0),
Color.fromRGBO(245, 50, 111, 1.0),
])),
),
);
}
}
虽然我刚刚升级到最新版本,但我似乎无法弄清楚哪里出了问题??
那是因为 null safety
来自 Flutter 2.0
的更新
有2个方案可以解决这个问题
第一
您将迁移 null safety
的所有代码
第二
在 pubspec.yaml
中降级您的 sdk 环境版本。
示例:sdk: ">=2.10.0 <3.0.0"
你可以选择使用哪一个,如果你想使用空安全选择第一个,如果你不想使用空安全选择第二个
希望这对您有所帮助。
我的代码之前运行良好,然后当我 运行 flutter 升级并下载最新版本时,每次我尝试按下按钮移动到下一页。我收到“渲染库错误捕获的异常。
这是我得到的错误
════════ Exception caught by rendering library ═════════════════════════════════
Null check operator used on a null value
The relevant error-causing widget was
PageView
lib\menu_frame.dart:59
════════════════════════════════════════════════════════════════════════════════
E/flutter ( 5787): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Null check
operator used on a null value.
这是我为那个特定页面准备的代码
class MenuFrame extends StatelessWidget {
PageController pageController = PageController();
@override
Widget build(BuildContext context) {
return Material(
child: Container(
child: Column(
children: <Widget>[
SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 28.0, vertical: 40.0),
child: Column(
children: <Widget>[
Icon(
FontAwesomeIcons.heartBroken,
color: Color.fromRGBO(245, 48, 111, 1.0),
size: 60.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'VORTEX',
style: TextStyle(
fontSize: 38.0,
fontWeight: FontWeight.bold,
color: Color.fromRGBO(245, 48, 111, 1.0),
),
),
Text(
'FITNESS',
style: TextStyle(
fontSize: 38.0,
fontWeight: FontWeight.bold,
),
),
],
),
Text(
'Find your passion for fitness!',
style: TextStyle(color: Colors.white, fontSize: 18.0),
textAlign: TextAlign.center,
),
// SizedBox(
// height: 85.0,
// ),
],
),
),
),
Expanded(
child: PageView(
controller: pageController,
//physics: NeverScrollableScrollPhysics(),
children: <Widget>[
HomeSignInWidget(
goToSignIn: () {
pageController.animateTo(1,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn);
},
goToSignUp: () {
pageController.animateTo(2,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn);
},
),
SignIn(),
CreateLogin(
cancelBackToHome: () {
pageController.animateTo(0,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn);
},
),
],
),
),
],
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(255, 123, 67, 1.0),
Color.fromRGBO(245, 50, 111, 1.0),
])),
),
);
}
}
虽然我刚刚升级到最新版本,但我似乎无法弄清楚哪里出了问题??
那是因为 null safety
来自 Flutter 2.0
有2个方案可以解决这个问题
第一
您将迁移 null safety
第二
在 pubspec.yaml
中降级您的 sdk 环境版本。
示例:sdk: ">=2.10.0 <3.0.0"
你可以选择使用哪一个,如果你想使用空安全选择第一个,如果你不想使用空安全选择第二个
希望这对您有所帮助。