summaryrefslogtreecommitdiff
path: root/lib/screens/events_screen.dart
blob: 0b78fbe632c87eb0860a2de836af5772826153de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'package:flutter/material.dart';
import 'package:table_calendar/table_calendar.dart';

import '../widgets/event_list.dart';

enum Vista { calendario, lista }

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

  @override
  State<EventsScreen> createState() => _EventsScreenState();
}

class _EventsScreenState extends State<EventsScreen> {
  Vista vista = Vista.calendario;
  DateTime _selectedDay = DateTime.now();
  DateTime _focusedDay = DateTime.now();
  CalendarFormat _calendarFormat = CalendarFormat.month;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Eventos'),
        actions: [
          SegmentedButton<Vista>(
            showSelectedIcon: false,
            segments: const [
              ButtonSegment<Vista>(
                value: Vista.calendario,
                icon: Icon(Icons.calendar_month),
              ),
              ButtonSegment<Vista>(
                value: Vista.lista,
                icon: Icon(Icons.list),
              ),
            ],
            selected: <Vista>{vista},
            onSelectionChanged: (p0) {
              setState(() {
                vista = p0.first;
              });
            },
          )
        ],
      ),
      body: Container(
          child: vista == Vista.calendario
              ? TableCalendar(
                  firstDay: DateTime.fromMicrosecondsSinceEpoch(0),
                  lastDay: DateTime.utc(9000, 12, 31),
                  focusedDay: _focusedDay,
                  selectedDayPredicate: (day) {
                    return isSameDay(_selectedDay, day);
                  },
                  onDaySelected: (selectedDay, focusedDay) {
                    setState(() {
                      _selectedDay = selectedDay;
                      _focusedDay = focusedDay;
                    });
                  },
                  calendarFormat: _calendarFormat,
                  onFormatChanged: (format) {
                    setState(() {
                      _calendarFormat = format;
                    });
                  },
                )
              : const EventList()),
      floatingActionButton: FloatingActionButton.extended(
        label: const Text('Nuevo'),
        icon: const Icon(Icons.add),
        onPressed: () {
          Navigator.of(context).pushNamed('/newevent');
        },
      ),
    );
  }
}