import 'dart:math'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: CalendarPage(), ); } } class CalendarPage extends StatefulWidget { @override _CalendarPageState createState() => _CalendarPageState(); } class _CalendarPageState extends State { DateTime currentDate = DateTime.now(); late List dateList; @override void initState() { super.initState(); dateList = _generateDateList(currentDate); } List _generateDateList(DateTime date) { List list = []; DateTime firstOfMonth = DateTime(date.year, date.month, 1); int dayOfWeek = firstOfMonth.weekday; // Adjust to Monday start int startDay = dayOfWeek - 1; if (startDay < 0) startDay = 6; // Dates from previous month for (int i = startDay; i > 0; i--) { list.add(firstOfMonth.subtract(Duration(days: i))); } // Dates of current month int daysInMonth = DateUtils.getDaysInMonth(date.year, date.month); for (int i = 0; i < daysInMonth; i++) { list.add(DateTime(date.year, date.month, i + 1)); } return list; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Calendar"), ), body: GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 7, ), itemBuilder: (context, index) { double radius = (Random().nextInt(50).toDouble() + 20) / 2; // Reduced by 50% DateTime date = dateList[index]; return Center( child: Container( width: radius * 2, height: radius * 2, decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all(color: Colors.black, width: 2), ), child: Center( child: Container( width: radius, height: radius, decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.lightGreen, ), child: Center( child: Text( DateFormat("d").format(date), style: TextStyle(color: Colors.black), ), ), ), ), ), ); }, itemCount: dateList.length, ), ); } }