使用Flutter执行HotRestart时,引发了另一个异常。 NoSuchMethodError:无效的空成员:'findRenderObject'继续引发。
在“ flutter run”后立即出现此错误,但是如果重写文本中的字符,将输出以下错误。
我尝试重新启动Google Chrome,重新运行Flutter,更新FlutterSDK,重新启动VisualStudioCode,并在Android模拟器而非网络上进行构建,但是此错误从未消失。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'todo_list_for_web',
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: RootPage(),
);
}
}
class RootPage extends StatefulWidget {
@override
_RootPageState createState() => _RootPageState();
}
class _RootPageState extends State<RootPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Todo list"),
backgroundColor: Colors.black87,
),
body: Row(
children: <Widget>[
Expanded(
flex: 5,
child: Container(
height: double.infinity,
width: double.infinity,
color: Colors.white,
child: TaskListArea(),
),
),
Expanded(
flex: 3,
child: Container(
child: InfoWindows(),
),
)
],
));
}
}
class TaskListArea extends StatefulWidget {
@override
_TaskListAreaState createState() => _TaskListAreaState();
}
class _TaskListAreaState extends State<TaskListArea> {
List<String> tasks = [
"try making coffee",
"work on homework",
"do my paper",
];
@override
Widget build(BuildContext context) {
return Container(
color: Colors.green,
child: Stack(children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: Padding(
//Title Text
padding: EdgeInsets.only(top: 18.0, left: 10.0, bottom: 30.0),
child: Text(
"Today's tasks.",
style: TextStyle(
fontSize: 30.0,
),
textAlign: TextAlign.start,
)),
),
Align(
alignment: Alignment.center,
child: Container(
height: 300.0,
child: ListView.separated(
separatorBuilder: (context, index) =>
Divider(color: Colors.black),
padding: EdgeInsets.all(16.0),
itemCount: tasks.length,
itemBuilder: (context, i) => Padding(
padding: EdgeInsets.all(8.0),
child: Center(child: Text(tasks[i]),)
)
)
)
),
Padding(
padding: EdgeInsets.all(50.0),
child: Align(
alignment: Alignment.bottomCenter,
child: Row(children: <Widget>[
Expanded(
flex: 20,
child: TextField(
decoration: InputDecoration(
hintText: "make coffee.",
border: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.black),
)),
)),
Expanded(
child: SizedBox(
width: 10.0,
),
),
Expanded(
flex: 5,
child: FlatButton(
color: Colors.grey,
onPressed: () {},
child: Text("Add"),
))
])))
]));
}
}
class InfoWindows extends StatefulWidget {
@override
_InfoWindowsState createState() => _InfoWindowsState();
}
class _InfoWindowsState extends State<InfoWindows> {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
color: Colors.red,
)),
Expanded(
flex: 1,
child: Container(
color: Colors.blueGrey,
))
],
);
}
}
执行热重启...
Another exception was thrown: NoSuchMethodError:invalid member on null: 'findRenderObject'
Performing hot restart...
Restarted application in 509ms.
Performing hot restart...
511ms
══╡ EXCEPTION CAUGHT BY ANIMATION LIBRARY
╞═════════════════════════════════════════════════════════
The following JSNoSuchMethodError was thrown
while notifying listeners for
AnimationController:
NoSuchMethodError: invalid member on null:
'findRenderObject'
When the exception was thrown, this was the
stack:
package:flutter/src/widgets/editable_text.dart
1726:68 get renderEditable
package:flutter/src/widgets/editable_text.dart
1590:20 [_onCursorColorTick]
package:flutter/src/animation/listener_helpers.dart 124:21 notifyListeners
package:flutter/src/animation/animation_controller.dart 362:5 set value
package:flutter/src/widgets/editable_text.dart
1625:37 [_cursorTick]
package:build_web_compilers/src/dev_compiler/dart_sdk.js 28721:9 <fn>
The AnimationController notifying listeners was:AnimationController#2e5b8(⏭ 1.000; paused)
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: NoSuchMethodError:invalid member on null: 'findRenderObject'