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

[Flutter] wave form data is not displaying in the graph

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

  1. Stack

    Stack Membro Participativo

    am working on a habit tracker app using flutter with sqflite howerevr i am trying to display the data of the task done that has been saved into database as per date and want to display that data in the graph in a wave form like if someday i did not have entry for that habit or can say task then for that day the entry was also not being stored in the database and i'll try to implement for that not stored id for that day the wave data will display in a declining form however i have tried fetching the data from the database but i am not able to display the wave form data in the database.

    /*databasehelper*/
    Future<bool> isTaskTrackedForDate(int taskId, String trackedDate) async {
    final db = await database;
    final result = await db.query(
    tableTaskTrack,
    where: '$columnTaskId = ? AND $columnTrackedDate = ?',
    whereArgs: [taskId, trackedDate],

    );
    return result.isNotEmpty;
    }


    /*taskcontroller*/
    Future<List<double>> fetchProgressDataForDateRange(DateTime today, int taskId) async {
    try {
    List<double> weeklyProgress = [];

    DateTime startOfPreviousWeek = today.subtract(Duration(days: today.weekday + 6));
    //DateTime endOfPreviousWeek = today.subtract(Duration(days: today.weekday));

    for (int i = 0; i < 6; i++) {
    DateTime previousDate = startOfPreviousWeek.add(Duration(days: i));
    double progressForPreviousDate = await fetchProgressForDate(previousDate, taskId);
    weeklyProgress.add(progressForPreviousDate);
    }

    for (int i = 0; i <= 6; i++) {
    DateTime currentDate = today.add(Duration(days: i));
    double progressForCurrentDate = await fetchProgressForDate(currentDate, taskId);
    weeklyProgress.add(progressForCurrentDate);
    }

    return weeklyProgress;
    } catch (e) {
    print("Error fetching progress data: $e");
    return List<double>.filled(14, 0.0);
    }
    }

    Future<double> fetchProgressForDate(DateTime date, int taskId) async {
    String trackedDate = DateFormat('dd-MM-yyyy').format(date); // Format the date for tracking
    print("task $taskId is tracked for date: $trackedDate");
    bool isTracked = await _databaseHelper.isTaskTrackedForDate(taskId, trackedDate);
    print("Task $taskId tracked on $trackedDate: $isTracked");

    return isTracked ? 1.0 : 0.0;
    }


    /*taskScreen*/
    Future<List<double>> fetchProgressData(TaskController taskController, int taskId) async {
    try {
    DateTime today = DateTime.now();
    final progressData = await taskController.fetchProgressDataForDateRange(today, taskId); // Pass today and taskId
    return progressData;
    } catch (e) {
    print('Error fetching progress data: $e');
    return List<double>.filled(14, 0.0); // Return default 0 progress for all days in case of error
    }
    }
    final Rx<DateTime> currentStartDate = DateTime.now().subtract(Duration(days: DateTime.now().weekday - 1)).obs;

    void moveToPreviousWeek() {
    currentStartDate.value = currentStartDate.value.subtract(Duration(days: 7));

    }

    void moveToNextWeek() {
    currentStartDate.value = currentStartDate.value.add(Duration(days: 7));

    }


    .I have tried implementing the fetchProgressDataForDateRange which basically fetch the data in the form of wave for both previous and current week however it seems to display the same graph on every week ,i want to display only the previous week data into previous week graph while if i move into current week the position of the data in the graph for current week should be different from previous weeks,however it seems to look it is fetching for previous ,current and future weeks same graph bar data ,which is not acceptable i also dont want to calulcate for fyuture weeks graph data it seems to show there also the same graph enter image description here

    Continue reading...

Compartilhe esta Página