GDTyka
GDTyka

Reputation: 530

Flutter about Dismissible class

First of all, I have class CheckList, in it I have list checkLists and many other variablse like name,position and others, in this list i have CheckList objects.

So in Dismissible key i pass CheckList.checkLists[index] but i got this error

The argument type 'CheckList' can't be assigned to the parameter type 'Key'

Scaffold(
      body: Container(
        padding: EdgeInsets.all(14.0),
        child: ListView.separated(
          itemCount: CheckList.checkLists.length,
          itemBuilder: (BuildContext Context, int index){
            return Dismissible(
              key: CheckList.checkLists[index],
              child: InkWell(
                
              ),
            );
          },
          separatorBuilder: (BuildContext context, int index) {
            return Container(
              height: 14,
            );
          }),    
      ),
  );

what i need to pass into key?

Second question

Item in ListView must looks like this. This is item from other ListView in my app but i need same with other data in new ListView item

enter image description here

Will my Dismissble item dismiss normaly with this type of code?

Scaffold(           
                  body:
                  Container(
                   padding: EdgeInsets.all(14.0),
                  child: ListView.separated(
                    itemCount: CheckList.checkListtemplateXmlList.length,
                    itemBuilder: (BuildContext context, int index) {
                    return InkWell(
                      onTap: (){
                              CheckList checkList = CheckList();
                                CheckList.addCheckList(index,checkList);
                                showDialog(context: context, builder: (BuildContext  context){
                                  return AlertDialog(
                                    title: Text('Добавить описание'),
                                    content: TextField(
                                      onChanged: (String value) async{
                                        checkList.description = value;
                                      },
                                    ),
                                    actions: [
                                      ElevatedButton(onPressed: () async{
                                        await checkList.writeToFile();
                                        setState(() {
                                          CheckList.checkLists.add(checkList);
                                        });
                                        Navigator.pushNamedAndRemoveUntil(context, '/',(route) => false );
                                      },
                                          child: Text('Добавить'))
                                    ],
                                  );
                                });
                      },
                      child: Container(
                      decoration: BoxDecoration(
                        border: Border.all(
                        color: Color.fromARGB(255, 141, 166, 255), width: 1),
                        borderRadius: BorderRadius.circular(10)),
                      width: 50,
                      height: 80,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                          "${CheckList.checkListTempaltexmlNameList[index]}",
                          style: TextStyle(fontSize: 40),
                  )
                ],
              ),
            ),
                    );
          },
          separatorBuilder: (BuildContext context, int index) {
            return Container(
              height: 14,
            );
          }),
    ),
            );

Upvotes: 0

Views: 40

Answers (1)

Tanguy
Tanguy

Reputation: 994

The key parameter needs a Key object. You can either pass

  • UniqueKey() which will generate a unique key automatically for you
  • ValueKey(dynamic value) if you want to generate one from some variable. In you case that would be ValueKey(CheckList.checkLists[index]).

Upvotes: 0

Related Questions