calendar_view2 0.0.1 copy "calendar_view2: ^0.0.1" to clipboard
calendar_view2: ^0.0.1 copied to clipboard

Calender View Two

example/lib/main.dart

import 'package:calendar_view2/calendar_view.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:google_fonts/google_fonts.dart';

void main() {
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  final EventController<Object?> _eventController = EventController<Object?>();
  PageController? _pageController;
  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  @override
  void dispose() {
    _eventController.dispose();
    super.dispose();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    // setState(() {
    //   _platformVersion = platformVersion;
    // });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // showPerformanceOverlay: t,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 8),
              child: _buildCalendar(context),
            ),
            Expanded(
                child: Container(
              color: Colors.red,
            )),
          ],
        ),
      ),
    );
  }

  Widget _buildCalendar(BuildContext context) {
    return CalendarControllerProvider(
      controller: _eventController,
      child: SizedBox(
        child: MonthView(
          borderSize: 0.5,
          cellAspectRatio: 1.3,
          width: 615,
          backgroundHeaderColor: const Color(0xFF5182E3),
          weekDayBuilder: (day) => ColoredBox(
            color: const Color(0xFF5182E3),
            child: Text(
              "$day",
              style: GoogleFonts.montserrat(
                color: Colors.white,
                fontSize: 16,
                fontWeight: FontWeight.w600,
              ),
              textAlign: TextAlign.center,
            ),
          ),
          cellBuilder: (date, event, isToday, isInMonth, hideDaysNotInMonth) {
            final day = date.day;
            return Container(
              color: isToday ? const Color(0xFFFFFBD2) : null,
              padding: const EdgeInsets.all(8),
              child: Stack(
                fit: StackFit.expand,
                children: [
                  if (!hideDaysNotInMonth || isInMonth)
                    Text(
                      "$day",
                      style: GoogleFonts.montserrat(
                        color: isInMonth ? Colors.black : Colors.grey,
                        fontSize: 12,
                        fontWeight: FontWeight.w400,
                      ),
                      textAlign: TextAlign.right,
                    ),
                  if (isInMonth)
                    Padding(
                      padding: const EdgeInsets.only(top: 0),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            isToday ? "Ro" : "M2",
                            style: GoogleFonts.montserrat(
                              color: isInMonth ? Colors.black : Colors.grey,
                              fontSize: 14,
                              fontWeight: FontWeight.w600,
                            ),
                            textAlign: TextAlign.right,
                          ),
                          const SizedBox(height: 4),
                          if (!isToday)
                            Text(
                              "10:15 - 18:09",
                              style: GoogleFonts.montserrat(
                                color: const Color(0xFF808080),
                                fontSize: 8,
                                fontWeight: FontWeight.w400,
                              ),
                              textAlign: TextAlign.center,
                            ),
                          if (!isToday)
                            Text(
                              "+0:05",
                              style: GoogleFonts.montserrat(
                                color: const Color(0xFF6297FF),
                                fontSize: 8,
                                fontWeight: FontWeight.w400,
                              ),
                              textAlign: TextAlign.center,
                            ),
                        ],
                      ),
                    )
                ],
              ),
            );
          },
          pageController: (pageController) {
            _pageController = pageController;
          },
          borderColor: const Color(0xFFE8EBED),
          hideDaysNotInMonth: true,
          // useAvailableVerticalSpace: true,
          headerBuilder: (date) {
            final dateNow = DateTime.now();
            final isNext =
                date.year < dateNow.year ? true : date.month < dateNow.month;
            return Row(
              children: [
                IconButton(
                  onPressed: () {
                    _pageController?.previousPage(
                      duration: const Duration(milliseconds: 300),
                      curve: Curves.ease,
                    );
                  },
                  icon: const Icon(
                    Icons.chevron_left,
                    color: Color(0xFF5182E3),
                  ),
                ),
                SizedBox(
                  width: 80,
                  child: Text(
                    "${date.month}/${date.year}",
                    style: GoogleFonts.montserrat(
                      color: Colors.black,
                      fontSize: 16,
                      fontWeight: FontWeight.w600,
                    ),
                    textAlign: TextAlign.center,
                  ),
                ),
                IconButton(
                  onPressed: () {
                    if (!isNext) return;
                    _pageController?.nextPage(
                      duration: const Duration(milliseconds: 300),
                      curve: Curves.ease,
                    );
                  },
                  icon: Icon(
                    Icons.chevron_right,
                    color: isNext
                        ? const Color(0xFF5182E3)
                        : const Color(0xFFD9D9D9),
                  ),
                ),
              ],
            );
          },
        ),
      ),
    );
  }
}
1
likes
140
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

Calender View Two

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on calendar_view2