Initial commit
This commit is contained in:
112
flutter_app/lib/widgets/calendar_widget.dart
Normal file
112
flutter_app/lib/widgets/calendar_widget.dart
Normal file
@@ -0,0 +1,112 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class CalendarWidget extends StatelessWidget {
|
||||
const CalendarWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final now = DateTime.now();
|
||||
final firstDayOfMonth = DateTime(now.year, now.month, 1);
|
||||
final lastDayOfMonth = DateTime(now.year, now.month + 1, 0);
|
||||
final daysInMonth = lastDayOfMonth.day;
|
||||
final startingWeekday = firstDayOfMonth.weekday; // Mon=1, Sun=7
|
||||
|
||||
// Simple calendar logic
|
||||
// We need to pad the beginning with empty slots
|
||||
// If week starts on Sunday, adjust accordingly. Let's assume Mon start for now or use locale.
|
||||
// Let's assume standard Sun-Sat or Mon-Sun. Let's go with Sun-Sat for standard calendar view often seen in KR/US.
|
||||
// DateTime.weekday: Mon=1, Sun=7.
|
||||
// If we want Sun start: Sun=0, Mon=1...
|
||||
// Let's adjust so Sunday is first.
|
||||
|
||||
int offset =
|
||||
startingWeekday %
|
||||
7; // If startingWeekday is 7 (Sun), offset is 0. If 1 (Mon), offset is 1.
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardTheme.color,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
DateFormat('MMMM yyyy').format(now),
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const Icon(Icons.calendar_today, color: Colors.white54),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Days Header
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: ['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((day) {
|
||||
return Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
day,
|
||||
style: const TextStyle(
|
||||
color: Colors.white54,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Days Grid
|
||||
Expanded(
|
||||
child: GridView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 7,
|
||||
childAspectRatio: 1.0,
|
||||
),
|
||||
itemCount: 42, // 6 rows max to be safe
|
||||
itemBuilder: (context, index) {
|
||||
final dayNumber = index - offset + 1;
|
||||
if (dayNumber < 1 || dayNumber > daysInMonth) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final isToday = dayNumber == now.day;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(4),
|
||||
decoration: isToday
|
||||
? BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
shape: BoxShape.circle,
|
||||
)
|
||||
: null,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'$dayNumber',
|
||||
style: TextStyle(
|
||||
color: isToday ? Colors.black : Colors.white,
|
||||
fontWeight: isToday
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user