반응형

흠 텍스트폼필드에 onchange 이용해서 값을 저장하는 방법은 알아내었다. 

하지만 한개의 리스트만 사용하다보니 알럿창 안에 있는 값이 [index]값을 연결하지 못한 것 같다. 

 

즉 리스트가 한 개 더 필요로 하는 걸까..흠흠;; 

 

final Ingredient ingredient=Ingredient("",",",0,0);
  final nameC = TextEditingController();
  final weightC = TextEditingController();
  final priceC = TextEditingController();
  final brandC = TextEditingController();
  final inputC = TextEditingController();





  void save() {}



  void addIngredientList() {

    setState(() {
      ingredients.add(ingredient);

    });

    setState(() {});
  }

  void addIngredient() {



    showDialog(
        context: context,
        builder: (context) {


          return AlertDialog(
            title: Text(
              '재료입력',
            ),
            content: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                TextFormField(
                  onChanged: (value) {
                    ingredient.name=value;
                    setState(() {
                      
                    });
                  },

                  controller: nameC,
                  decoration: InputDecoration(hintText: 'ex) 고추장'),
                ),
                TextFormField(
                  onChanged: (value){
                    ingredient.weight=double.tryParse(value) ?? 0;
                    setState(() {
                      
                    });
                  },
                  controller: weightC,
                  decoration: InputDecoration(hintText: 'ex) 15000g'),
                ),
                TextFormField(
                  onChanged: (value){
                    ingredient.price=double.tryParse(value) ?? 0;
                    setState(() {

                    });
                  },
                  controller: priceC,
                  decoration: InputDecoration(hintText: 'ex) 30000원'),
                ),
                TextFormField(
                  onChanged: (value){
                    setState(() {
                       ingredient.brand=value;
                    });
                  },
                  controller: brandC,
                  decoration: InputDecoration(hintText: 'ex) 해찬들'),
                ),
              ],
            ),
            actions: [
              ElevatedButton(
                onPressed: () {},
                child: Text('저장'),
              )
            ],
          );
        });
  }

 

 

반응형

+ Recent posts