123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- import 'package:flutter/material.dart';
- import 'package:fast_med_flutter/ui/pages/add_event.dart';
- import 'package:fast_med_flutter/ui/pages/view_event.dart';
- import 'package:table_calendar/table_calendar.dart';
- import 'package:firebase_core/firebase_core.dart';
-
- import 'model/event.dart';
-
- void main() async{
- WidgetsFlutterBinding.ensureInitialized();
- await Firebase.initializeApp();
- runApp(Calendario());
- }
-
- class Calendario extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Citas Disponibles',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: MyHomePage(),
- routes: {
- "add_event": (_) => AddEventPage(),
- },
- );
- }
- }
-
-
-
- class MyHomePage extends StatefulWidget {
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
-
- class _MyHomePageState extends State<MyHomePage> {
- CalendarController _controller;
- Map<DateTime, List<dynamic>> _events;
- List<dynamic> _selectedEvents;
-
- @override
- void initState() {
- super.initState();
- _controller = CalendarController();
- _events = {};
- _selectedEvents = [];
- }
-
- Map<DateTime, List<dynamic>> _groupEvents(List<EventModel> events) {
- Map<DateTime,List<dynamic>> data = {};
- events.forEach((event) {
- DateTime date = DateTime(event.eventDate.year, event.eventDate.month,
- event.eventDate.day, 12);
- if(data[date] == null) data[date] = [];
- data[date].add(event);
- });
- return data;
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('Citas Disponibles'),
- ),
- body: StreamBuilder<List<EventModel>>(
- // stream: eventDBS.streamList(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- List<EventModel> allEvents = snapshot.data;
- if (allEvents.isNotEmpty) {
- _events = _groupEvents(allEvents);
- }
- }
-
- return SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- TableCalendar(
- events: _events,
- initialCalendarFormat: CalendarFormat.week,
- calendarStyle: CalendarStyle(
- canEventMarkersOverflow: true,
- todayColor: Colors.orange,
- selectedColor: Theme
- .of(context)
- .primaryColor,
- todayStyle: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 18.0,
- color: Colors.white)),
- headerStyle: HeaderStyle(
- centerHeaderTitle: true,
- formatButtonDecoration: BoxDecoration(
- color: Colors.orange,
- borderRadius: BorderRadius.circular(20.0),
- ),
- formatButtonTextStyle: TextStyle(color: Colors.white),
- formatButtonShowsNext: false,
- ),
- startingDayOfWeek: StartingDayOfWeek.monday,
-
- builders: CalendarBuilders(
- selectedDayBuilder: (context, date, events) =>
- Container(
- margin: const EdgeInsets.all(4.0),
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: Theme
- .of(context)
- .primaryColor,
- borderRadius: BorderRadius.circular(10.0)),
- child: Text(
- date.day.toString(),
- style: TextStyle(color: Colors.white),
- )),
- todayDayBuilder: (context, date, events) =>
- Container(
- margin: const EdgeInsets.all(4.0),
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: Colors.orange,
- borderRadius: BorderRadius.circular(10.0)),
- child: Text(
- date.day.toString(),
- style: TextStyle(color: Colors.white),
- )),
- ),
- calendarController: _controller,
- ),
- ..._selectedEvents.map((event) =>
- ListTile(
- title: Text(event.title),
- onTap: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (_) =>
- EventDetailsPage(
- event: event,
- )));
- },
- )),
- ],
- ),
- );
- }
- ),
- floatingActionButton: FloatingActionButton(
- child: Icon(Icons.add),
- onPressed: () => Navigator.pushNamed(context, 'add_event'),
- ),
- );
- }
- }
|