Android 类型';字符串';不是类型为';int';属于';指数';使用tflite时-颤振

Android 类型';字符串';不是类型为';int';属于';指数';使用tflite时-颤振,android,flutter,tensorflow,dart,machine-learning,Android,Flutter,Tensorflow,Dart,Machine Learning,我在我的应用程序中使用了tflite包,在程序的一部分中,我得到了一个错误,类型“String”不是“index”类型“int”的子类型。。我将单独提及该行,并将在代码中提供行numeber 现在,在那一行,当我写\u输出[0]['label']时,显示了这个错误。但如果我编写了\u输出[0][0],错误会消失,但会显示一个随机文本。现在,我如何纠正它 首先是守则- import 'dart:io'; import 'package:flutter/material.dart'; import

我在我的应用程序中使用了
tflite
包,在程序的一部分中,我得到了一个错误,
类型“String”不是“index”类型“int”的子类型。
。我将单独提及该行,并将在代码中提供行numeber

现在,在那一行,当我写
\u输出[0]['label']
时,显示了这个错误。但如果我编写了
\u输出[0][0]
,错误会消失,但会显示一个随机文本。现在,我如何纠正它

首先是守则-

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:tflite/tflite.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {

  bool _isLoading=true;
  File _image = File("");
  List _output = [];
  final picker = ImagePicker();

  @override
  void initState() {
    super.initState();
    loadModel().then((value) {
      setState(() {

      });
    });
  }

  detectImage(File image) async {
    var output = await Tflite.runModelOnImage(
      path: image.path,
      numResults: 2,
      threshold: 0.6,
      imageMean: 127.5,
      imageStd: 127.5,
    );
    setState(() {
      _output.add(output);
      _isLoading = false;
    });
    output!=null ? output.clear() : null;
  }

  loadModel() async {
    await Tflite.loadModel(
      model: 'assets/model_unquant.tflite',
      labels: 'assets/labels.txt',
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();

  }

  pickImage() async {
    var image = await picker.getImage(source: ImageSource.camera);
    if(image == null)
      return null;

    setState(() {
      _image = File(image.path);
    });

    detectImage(_image);
  }

  pickGalleryImage() async {
    var image = await picker.getImage(source: ImageSource.gallery);
    if(image == null)
      return null;

    setState(() {
      _image = File(image.path);
    });

    detectImage(_image);
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        backgroundColor: Colors.grey[400],
        body: Center(
          child: Container(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(height: 20.0,),
                Center(
                  child: Text(
                    'Cats and Dogs Detector app',
                    style: TextStyle(
                      fontSize: 25.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.white70,
                    ),
                  ),
                ),
                SizedBox(height: 200.0),
                Center(
                  child: _isLoading ? Container(
                    width: MediaQuery.of(context).size.width*0.9,
                    child: Column(
                      children: [
                        Image.asset("assets/cats n dogs 2.jpg", fit: BoxFit.cover,)
                      ],
                    ),
                  ) : Container(
                    child: Column(
                      children: [
                        Container(
                          height: 250,
                          child: Image.file(_image),
                        ),
                        SizedBox(height: 20.0,),
                        _output!=null ? Text('${_output[0]['label']}', style: TextStyle(color: Colors.white, fontSize: 15.0),) : Container(),
                        SizedBox(height: 10.0,),
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  height: 20.0,
                ),
                Center(
                  child: Container(
                    width: MediaQuery.of(context).size.width*0.6,
                    alignment: Alignment.center,
                    child: Column(
                      children: [
                        ElevatedButton(
                          onPressed: () {
                            pickImage();
                          },
                          style: ButtonStyle(
                            backgroundColor: MaterialStateProperty.all(Colors.grey),
                          ),
                          child: Padding(
                            padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 15.0),
                            child: Text(
                              'Capture a pic',
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 17.5,
                              ),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: MediaQuery.of(context).size.height*0.01,
                        ),
                        ElevatedButton(
                          onPressed: () {
                            pickGalleryImage();
                          },
                          style: ButtonStyle(
                            backgroundColor: MaterialStateProperty.all(Colors.grey),
                          ),
                          child: Padding(
                            padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 15.0),
                            child: Text(
                              'Select from gallery',
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 17.50,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

行号120-
\u输出=无效的Text('${u output[0]['label']}',style:TextStyle(color:Colors.white,fontSize:15.0),):Container(),

请帮助我了解您在此处为{u output分配了一个值,但您试图访问第122行中的'label',但没有为列表分配label属性

这是正确的还是我误解了什么

  detectImage(File image) async {
    var output = await Tflite.runModelOnImage(
      path: image.path,
      numResults: 2,
      threshold: 0.6,
      imageMean: 127.5,
      imageStd: 127.5,
    );
    setState(() {
      _output.add(output);
      _isLoading = false;
    });
    output!=null ? output.clear() : null;
  }
  detectImage(File image) async {
    var output = await Tflite.runModelOnImage(
      path: image.path,
      numResults: 2,
      threshold: 0.6,
      imageMean: 127.5,
      imageStd: 127.5,
    );
    setState(() {
      _output.add(output);
      _isLoading = false;
    });
    output!=null ? output.clear() : null;
  }