LateInitializationError:field' _recognition@25356196'尚未初始化

发布于 2025-02-13 14:01:45 字数 2182 浏览 0 评论 0原文

每当我运行颤音代码时,我都会不断出现错误。下面的代码是我从中得到问题的飞镖文件。我尝试调试,但无法得到答案,并且该项目延迟了我,因为我仍然有一些未完成的项目。我希望我能得到这个错误的答案。

错误是另一个例外: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑕疵 2025-02-20 14:01:46

您尚未初始化晚列表&lt; dynamic&gt; _recognitions;和最简单的解决方案是删除late并用空列表初始化它。

List<dynamic> _recognitions = [];

如果您不删除late,请确保已在build上使用它之前已将其初始化。您可以在initstate上初始化它。

You have not initialized late List<dynamic> _recognitions; and the simplest solution is remove late and initialize it with empty list.

List<dynamic> _recognitions = [];

If you wan't to remove late, make sure it has been initialized before You use it on build. You can initialize it on initState.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文