Выпадающий список в flutter не работает странные ошибки

#flutter #dart

Вопрос:

Добрый день, ребята, у меня интересная проблема. поэтому я пытаюсь сделать кнопку выпадающего списка (строка 46), я пытаюсь загрузить элементы (строка 51), и это просто не работает.
вот мой код.

 import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:inc_tools/support/ToolsApi.dart';


class NewToolPage extends StatefulWidget {
  static String id = "NewToolPage";

  final typesTools;
  NewToolPage({this.typesTools});

  @override
  _NewToolPageState createState() => _NewToolPageState();
}

class _NewToolPageState extends State<NewToolPage> {
  var _toolNumber = TextEditingController();
  var _toolType = TextEditingController();
  var _toolTags = TextEditingController();
  var _toolQuantity = TextEditingController();
  bool isChecked = true;
  String _chosenValue = "";

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('New Tool'),centerTitle: true,),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  SizedBox(
                    width: 200,height: 50,
                      child: TextField(controller: _toolNumber,decoration:InputDecoration(labelText: "Barcode Number",))),
                  Text('Or'),
                  ElevatedButton(onPressed: (){}, child: Text('Scan Barcode')),
                ],),
              Row(
                children: [

                  DropdownButton<String>(
                    focusColor:Colors.white,
                    value: _chosenValue,
                    style: TextStyle(color: Colors.white),
                    iconEnabledColor:Colors.black,
                    items: optionsTypes() ,  // <---here is where the items will be return to.
                    onChanged: (String? value) {
                      setState(() {
                        _chosenValue = value!;
                      });
                    },
                  ),
                ],
              ),
              simpleInput(_toolType, "Tool Type"),
              simpleInput(_toolTags, "Tags"),
              simpleInput(_toolQuantity, "Quantity" ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                Text('Active', style: TextStyle(fontSize: 17),),
                Checkbox(value: isChecked, onChanged:(bool? value){
                  setState(() {
                    isChecked = value!;
                  });
                }),
              ],),
              ElevatedButton(onPressed: () async {
                bool isWasCreated = await ToolsAPI().newToolApi(
                    code: _toolNumber.text,
                    type: _toolType.text,
                    tags: _toolTags.text,
                    quantity: _toolQuantity.text,
                );
                if(isWasCreated){
                  Navigator.pop(context);
                }
              },
                child: Text('Summit', style: TextStyle(fontSize: 20),),
              )
            ],
          ),
        ),
      ),
    );
  }
 

поэтому я использую эту функцию для создания списка товаров, чтобы загрузить его в раздел «товары»(строка 51).

   List<DropdownMenuItem<String>> optionsTypes (){

    List<DropdownMenuItem<String>> items = [];
    List<String> types = widget.typesTools;


    // loops the values.
    for(String _value in types){

      // this check what values is giving to the function
      print("--------->>  $_value");

      // add to the list so can be return.
      items.add(
          DropdownMenuItem<String>(value: _value, child: Text(_value)));
    }

      // return list of items the widget
      return items;
  }
 

инструкция по печати в строке 104 показывает эти результаты

 I/flutter (11378): --------->>  hammer Drill
I/flutter (11378): --------->>  Skill Saw
I/flutter (11378): --------->>  Demolition Saw
 

но ошибка, которую я получил, заключается в следующем

 The following assertion was thrown building NewToolPage(dirty, state: _NewToolPageState#7dfe6):
There should be exactly one item with [DropdownButton]'s value: . 
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 850 pos 15: 'items == null || items.isEmpty || value == null ||
              items.where((DropdownMenuItem<T> item) {
                return item.value == value;
              }).length == 1'
 

Any ideas will be highly appreciated.