1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] how to pin a task at top while allowing only two task can be pinned

Discussão em 'Mobile' iniciado por Stack, Outubro 9, 2024 às 07:52.

  1. Stack

    Stack Membro Participativo

    I am trying to pin the task at first index whenver i clcik on pin however it seems to be not pinned at the index with the icon displayed on the top left side

    void pinTask(int index) {
    if (pinnedTasks.contains(index)) {
    pinnedTasks.remove(index);
    } else {
    pinnedTasks.add(0);
    var task = taskList[index];

    taskList.removeAt(index);
    taskList.insert(0, task);

    pinnedTasks = {0};
    }
    update();
    }
    List<String> getPinnedTasks() {
    return taskList.where((task) => isTaskSelected[taskList.indexOf(task)]).toList();
    }
    List<String> get sortedTasks {
    List<String> sortedList = taskList.toList();
    sortedList.sort((a, b) {
    int indexA = taskList.indexOf(a);
    int indexB = taskList.indexOf(b);
    return pinnedTasks.contains(indexA) && !pinnedTasks.contains(indexB) ? -1 : 1;
    });
    return sortedList;
    }


    void _showOptionsDialog(BuildContext context, TaskController taskController, int index) {
    showDialog(
    context: context,
    builder: (BuildContext context) {
    return Dialog(
    shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.only(
    topLeft: Radius.circular(10),
    topRight: Radius.circular(0),
    bottomLeft: Radius.circular(0),
    bottomRight: Radius.circular(0),
    ),
    ),
    child: SizedBox(
    width: double.infinity,
    height: 130,
    child: Padding(
    padding: EdgeInsets.all(8.0),
    child: Center(
    child: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    mainAxisSize: MainAxisSize.min,
    children: [
    ListTile(
    leading: Icon(Icons.push_pin),
    title: Text('Pin', style: TextStyle(fontSize: 14)),
    //this from where i am pinning the task
    onTap: () {
    taskController.pinTask(index); // Pin or unpin the task
    Navigator.of(context).pop(); // Close dialog
    },
    ),

    ],
    ),
    ),
    ),
    ),
    );
    },
    );
    }


    i have tried implemented how to pin a task while only two tasks can be pinned at the top only with the icon displayed however i am unable to display the pin icon over the task list enter image description here.The pin icon should display like also i want to implement the functionality how can i unpin the task using same methods

    Continue reading...

Compartilhe esta Página