You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.0 KiB
Dart
91 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/dashboard_latest/dashboard_provider.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
import 'package:test_sa/new_views/app_style/app_text_style.dart';
|
|
import 'package:test_sa/views/app_style/sizing.dart';
|
|
|
|
class WeeklyCalendarFragment extends StatelessWidget {
|
|
const WeeklyCalendarFragment({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Generate the list of dates for the current week (3 days before and 3 days after today)
|
|
List<DateTime> weekDates = getWeekDates();
|
|
|
|
return Consumer<DashBoardProvider>(
|
|
builder: (context, snapshot, _) => GridView.builder(
|
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 7,
|
|
childAspectRatio: 70 / 60,
|
|
crossAxisSpacing: 2,
|
|
mainAxisSpacing: 12,
|
|
),
|
|
itemCount: weekDates.length, // Now we have 7 items
|
|
itemBuilder: (context, index) {
|
|
DateTime date = weekDates[index];
|
|
String formattedDate = DateFormat('EEE\ndd').format(date); // EEE: Day name, dd: Day number
|
|
|
|
return listItem(
|
|
formattedDate, // Pass the formatted date
|
|
snapshot.dashboardCount?.data?.countOpen ?? 0, // Adjust as needed
|
|
context,
|
|
snapshot.isAllCountLoading,
|
|
index,
|
|
AppColor.primary10,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
// Function to generate a list of dates for 3 days before and 3 days after the current date
|
|
List<DateTime> getWeekDates() {
|
|
DateTime today = DateTime.now();
|
|
List<DateTime> weekDates = [];
|
|
|
|
for (int i = -3; i <= 3; i++) {
|
|
weekDates.add(today.add(Duration(days: i)));
|
|
}
|
|
|
|
return weekDates;
|
|
}
|
|
|
|
Widget listItem(String formattedDate, int value, BuildContext context, bool isLoading, int index, Color iconColor) {
|
|
return GestureDetector(
|
|
onTap: isLoading
|
|
? null
|
|
: () {
|
|
// Action on tapping the date (if required)
|
|
},
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
8.height,
|
|
Column(
|
|
children: [
|
|
Container(
|
|
color: Colors.red,
|
|
child: Text(
|
|
formattedDate,
|
|
style: AppTextStyles.tinyFont2,
|
|
),
|
|
),
|
|
// Any other widgets you want to display (e.g. counts, icons)
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|