LateInitializationError:field' _recognition@25356196'尚未初始化
每当我运行颤音代码时,我都会不断出现错误。下面的代码是我从中得到问题的飞镖文件。我尝试调试,但无法得到答案,并且该项目延迟了我,因为我仍然有一些未完成的项目。我希望我能得到这个错误的答案。
错误是另一个例外:lateinitializationError:field'_recognition@25356196'没有 被初始化。谢谢。
import 'package:flutter/material.dart';
import 'bounding_box.dart';
import 'camera.dart';
import 'dart:math' as math;
import 'package:tflite/tflite.dart';
// ignore: must_be_immutable
class LiveFeed extends StatefulWidget {
List<CameraDescription> cameras;
// ignore: use_key_in_widget_constructors
LiveFeed(this.cameras);
@override
// ignore: library_private_types_in_public_api
_LiveFeedState createState() => _LiveFeedState();
}
class _LiveFeedState extends State<LiveFeed> {
late List<dynamic> _recognitions;
int _imageHeight = 0;
int _imageWidth = 0;
initCameras() async {
}
loadTfModel() async {
await Tflite.loadModel(
model: "assets/models/ssd_mobilenet.tflite",
labels: "assets/models/labels.txt",
);
}
/*
The set recognitions function assigns the values of recognitions, imageHeight and width to the variables defined here as callback
*/
setRecognitions(recognitions, imageHeight, imageWidth) {
setState(() {
_recognitions = recognitions;
_imageHeight = imageHeight;
_imageWidth = imageWidth;
});
}
@override
void initState() {
super.initState();
loadTfModel();
}
@override
Widget build(BuildContext context) {
Size screen = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: const Text("Orange AI"),
),
body: Stack(
children: <Widget>[
CameraFeed(widget.cameras, setRecognitions),
BoundingBox(
// ignore: unnecessary_null_comparison
_recognitions,
math.max(_imageHeight, _imageWidth),
math.min(_imageHeight, _imageWidth),
screen.height,
screen.width,
),
],
),
);
}
}
我的航站楼
Another exception was thrown: LateInitializationError: Field '_recognitions@25356196' has not
been initialized.```
I keep getting the error above whenever I run my Flutter code. The code below is my dart file which I get the problem from. I tried debugging but couldn't get an answer and the project is delaying me because I still have some unfinished ones. Pls I hope I can get an answer for this error.
The error is Another exception was thrown: LateInitializationError: Field '_recognitions@25356196' has not
been initialized. Thank you.
import 'package:flutter/material.dart';
import 'bounding_box.dart';
import 'camera.dart';
import 'dart:math' as math;
import 'package:tflite/tflite.dart';
// ignore: must_be_immutable
class LiveFeed extends StatefulWidget {
List<CameraDescription> cameras;
// ignore: use_key_in_widget_constructors
LiveFeed(this.cameras);
@override
// ignore: library_private_types_in_public_api
_LiveFeedState createState() => _LiveFeedState();
}
class _LiveFeedState extends State<LiveFeed> {
late List<dynamic> _recognitions;
int _imageHeight = 0;
int _imageWidth = 0;
initCameras() async {
}
loadTfModel() async {
await Tflite.loadModel(
model: "assets/models/ssd_mobilenet.tflite",
labels: "assets/models/labels.txt",
);
}
/*
The set recognitions function assigns the values of recognitions, imageHeight and width to the variables defined here as callback
*/
setRecognitions(recognitions, imageHeight, imageWidth) {
setState(() {
_recognitions = recognitions;
_imageHeight = imageHeight;
_imageWidth = imageWidth;
});
}
@override
void initState() {
super.initState();
loadTfModel();
}
@override
Widget build(BuildContext context) {
Size screen = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: const Text("Orange AI"),
),
body: Stack(
children: <Widget>[
CameraFeed(widget.cameras, setRecognitions),
BoundingBox(
// ignore: unnecessary_null_comparison
_recognitions,
math.max(_imageHeight, _imageWidth),
math.min(_imageHeight, _imageWidth),
screen.height,
screen.width,
),
],
),
);
}
}
My Terminal
Another exception was thrown: LateInitializationError: Field '_recognitions@25356196' has not
been initialized.```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尚未初始化
晚列表&lt; dynamic&gt; _recognitions;
和最简单的解决方案是删除late
并用空列表初始化它。如果您不删除
late
,请确保已在build
上使用它之前已将其初始化。您可以在initstate
上初始化它。You have not initialized
late List<dynamic> _recognitions;
and the simplest solution is removelate
and initialize it with empty list.If you wan't to remove
late
, make sure it has been initialized before You use it onbuild
. You can initialize it oninitState
.