Hey! I need some help with a code in flutter. How can I do this differently? Please dont…
- User
Hey! I need some help with a code in flutter. How can I do this differently? Please dont alter anything inside the container. Expanded( child: Stack( children: taskList.map((task) { int index = taskList.indexOf(task); return AnimatedPositioned( key: ValueKey(task.title), duration: const Duration(seconds: 1), top: 55.0 * index, left: 0, right: 0, child: TweenAnimationBuilder( key: ValueKey(task.isCompleted), tween: Tween(begin: task.isCompleted ? 0.1 : 0.0, end: 0.0 ), duration: const Duration(milliseconds: 1000), curve: Curves.easeInOut, builder: (context, tilt, child) { return Transform( alignment: Alignment.center, transform: Matrix4.rotationZ(tilt), child: Container( margin: const EdgeInsets.only(top: 10,left: 10,right: 10,bottom: 0), color: (deletar && taskIndexToRemove == index) ? Colors.red :cores[index % 2], child: Dismissible( key: UniqueKey(), // Chave única para cada item onDismissed: (direction) { if (direction == DismissDirection.endToStart){
// Remove o item da lista setState(() { taskList.removeAt(index); }); } if (direction == DismissDirection.startToEnd) { _toggleCompletion(index); } }, confirmDismiss: (DismissDirection dismissDirection) { apagar = true; apertouBotao = Completer(); if (dismissDirection == DismissDirection.endToStart){ return Future.any([ Future.delayed(const Duration(seconds: 3), () => apagar), apertouBotao.future, ]); } else{ return Future.any([ Future.delayed(const Duration(seconds: 0), () => apagar), apertouBotao.future, ]); } }, // Widget de background que aparece durante o swipe para direita background: Container( color: Colors.green, alignment: Alignment.centerLeft, padding: const EdgeInsets.symmetric(horizontal: 20), child: taskList[index].isCompleted ? const Icon(Icons.check_box_outline_blank, color: Colors.black) : const Icon(Icons.check_box, color: Colors.black) ), // Widget de background que aparece durante o swipe para esquerda secondaryBackground: Container( color: Colors.red, alignment: Alignment.centerRight, padding: const EdgeInsets.symmetric(horizontal: 20), child: IconButton( onPressed: () { apagar = false; apertouBotao.complete( false ); }, icon: const Icon(Icons.undo, color: Colors.black), ), ), // Conteúdo principal: o item da lista child: ListTile( title: Text(taskList[index].title), leading: Checkbox( value: taskList[index].isCompleted, onChanged: (value) { _toggleCompletion(index); } ), trailing: IconButton( icon: Icon(deletar && taskIndexToRemove == index ? Icons.undo : Icons.delete), tooltip: 'Apagar Tarefa', onPressed: () { if (deletar && taskIndexToRemove == index) { _undoDelete('completed'); } else { if (deletar == false){ _deleteTask(index); } } } ), ), ), ) ); } ) ); } ).toList(), ) ) - Assistant