0

I am new to flutter/dart. So I couldn't fully understand how to add events in my Calendar. I am using a package called table_calendar, I read the documents about it but still couldn't manage to do it. This is my current code;

import 'package:flutter/material.dart';
import 'package:table_calendar/table_calendar.dart';

void main() {
  runApp(MaterialApp(
    debugShowCheckedModeBanner: false,
    home: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  DateTime today = DateTime.now();
  void _onDaySelected(DateTime day, DateTime focusedDay) {
    setState(() {
      today = day;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("    TAKVIM-OMER FARUK AYTEPE")),
      body: content(),
    );
  }

  Widget content() {
    return Column(
      children: [
        Text("Secilen Gun : " + today.toString().split(" ")[0]),
        Container(
            child: TableCalendar(
              onDaySelected: _onDaySelected,
              selectedDayPredicate: (day) => isSameDay(day, today),
              rowHeight: 45,
              headerStyle: HeaderStyle(
                formatButtonVisible: false, titleCentered: true),
              availableGestures: AvailableGestures.all,
              focusedDay: today,
              firstDay: DateTime.utc(2010, 10, 16),
              lastDay: DateTime.utc(2030, 10, 16))),
      ],
    );
  }
}

For example;

I want to add an event on a specified day, for example I want my program to show me "X person died" below my calendar when I press that specified day.

I tried using if statements, but looks like using only if statements won't gonna work. So I need to use the event system but as I mentioned I couldn't understand it properly.

Ömer
  • 5
  • 2

0 Answers0