Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

all rituals screen

laurenspriem050c65a10305
diff --git a/mobile/apps/photos/lib/models/rituals/ritual_models.dart b/mobile/apps/photos/lib/models/rituals/ritual_models.dart
index 359bdae222..d794d74a90 100644
--- a/mobile/apps/photos/lib/models/rituals/ritual_models.dart
+++ b/mobile/apps/photos/lib/models/rituals/ritual_models.dart
@@ -95,6 +95,7 @@ class RitualProgress {
final String ritualId;
final Set<int> completedDayKeys;
final Map<int, EnteFile> recentFilesByDay;
+ final Map<int, int> recentFileCountsByDay;
final int currentStreak;
final int longestStreakOverall;
final int longestStreakThisMonth;
@@ -103,6 +104,7 @@ class RitualProgress {
required this.ritualId,
required this.completedDayKeys,
this.recentFilesByDay = const {},
+ this.recentFileCountsByDay = const {},
required this.currentStreak,
required this.longestStreakOverall,
required this.longestStreakThisMonth,
diff --git a/mobile/apps/photos/lib/services/rituals/rituals_service.dart b/mobile/apps/photos/lib/services/rituals/rituals_service.dart
index 6b44941eb5..f0e83467b5 100644
--- a/mobile/apps/photos/lib/services/rituals/rituals_service.dart
+++ b/mobile/apps/photos/lib/services/rituals/rituals_service.dart
@@ -143,6 +143,7 @@ class RitualsService {
final Map<int, Set<int>> collectionDayKeys = {};
final Map<int, Map<int, EnteFile>> collectionRecentFilesByDay = {};
+ final Map<int, Map<int, int>> collectionRecentFileCountsByDay = {};
if (ritualAlbumIds.isEmpty) {
return RitualsSummary(
@@ -154,11 +155,7 @@ class RitualsService {
final files = await FilesDB.instance.getAllFilesFromCollections(
ritualAlbumIds,
);
- final recentStart = DateTime(
- todayMidnight.year,
- todayMidnight.month,
- todayMidnight.day - 4,
- );
+ final recentStart = todayMidnight.subtract(const Duration(days: 42));
for (final EnteFile file in files) {
final bool ownerMatches =
file.ownerID == null ? true : file.ownerID == userId;
@@ -180,6 +177,11 @@ class RitualsService {
collectionDayKeys.putIfAbsent(collectionId, () => <int>{}).add(dayKey);
if (bucket.isBefore(recentStart)) continue;
+ final countsByDay = collectionRecentFileCountsByDay.putIfAbsent(
+ collectionId,
+ () => <int, int>{},
+ );
+ countsByDay.update(dayKey, (value) => value + 1, ifAbsent: () => 1);
final byDay =
collectionRecentFilesByDay.putIfAbsent(collectionId, () => {});
final existing = byDay[dayKey];
@@ -218,6 +220,8 @@ class RitualsService {
ritualId: ritual.id,
completedDayKeys: dates,
recentFilesByDay: collectionRecentFilesByDay[albumId] ?? const {},
+ recentFileCountsByDay:
+ collectionRecentFileCountsByDay[albumId] ?? const {},
currentStreak: ritualCurrent,
longestStreakOverall: ritualLongestOverall,
longestStreakThisMonth: ritualLongestThisMonth,
diff --git a/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart b/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
index 63df03d990..cb652ae92f 100644
--- a/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
+++ b/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
@@ -3,35 +3,17 @@ import "package:hugeicons/hugeicons.dart";
import "package:photos/l10n/l10n.dart";
import "package:photos/models/rituals/ritual_models.dart";
import "package:photos/service_locator.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/rituals/ritual_camera_page.dart";
+import "package:photos/ui/rituals/ritual_day_thumbnail.dart";
import "package:photos/ui/rituals/ritual_editor_dialog.dart";
-import "package:photos/ui/rituals/rituals_section.dart";
-class AllRitualsScreen extends StatefulWidget {
+class AllRitualsScreen extends StatelessWidget {
const AllRitualsScreen({super.key, this.ritual});
+ // Legacy param; retained for call sites that pass it.
final Ritual? ritual;
- @override
- State<AllRitualsScreen> createState() => _AllRitualsScreenState();
-}
-
-class _AllRitualsScreenState extends State<AllRitualsScreen> {
- Ritual? _selectedRitual;
-
- @override
- void initState() {
- super.initState();
- _selectedRitual = widget.ritual;
- }
-
- @override
- void didUpdateWidget(covariant AllRitualsScreen oldWidget) {
- super.didUpdateWidget(oldWidget);
- if (oldWidget.ritual != widget.ritual) {
- _selectedRitual = widget.ritual;
- }
- }
-
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
@@ -84,31 +66,28 @@ class _AllRitualsScreenState extends State<AllRitualsScreen> {
child: ValueListenableBuilder<RitualsState>(
valueListenable: ritualsService.stateNotifier,
builder: (context, state, _) {
- Ritual? selectedRitual = _selectedRitual;
- if (selectedRitual != null) {
- final match = state.rituals.where(
- (ritual) => ritual.id == selectedRitual!.id,
- );
- if (match.isNotEmpty) {
- selectedRitual = match.first;
- } else {
- selectedRitual = null;
- }
- }
+ final rituals = state.rituals;
+ final summary = state.summary;
return ListView(
physics: const BouncingScrollPhysics(),
- padding: const EdgeInsets.only(bottom: 48),
+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 48),
children: [
- RitualsSection(
- rituals: state.rituals,
- showHeader: false,
- selectedRitualId: selectedRitual?.id,
- onSelectionChanged: (ritual) {
- setState(() {
- _selectedRitual = ritual;
- });
- },
- ),
+ if (rituals.isEmpty)
+ _CreateRitualCard(
+ onTap: () async {
+ await showRitualEditor(context, ritual: null);
+ },
+ )
+ else
+ ...rituals.map(
+ (ritual) => Padding(
+ padding: const EdgeInsets.only(bottom: 12),
+ child: _RitualOverviewCard(
+ ritual: ritual,
+ progress: summary?.ritualProgress[ritual.id],
+ ),
+ ),
+ ),
],
);
},
@@ -117,3 +96,349 @@ class _AllRitualsScreenState extends State<AllRitualsScreen> {
);
}
}
+
+class _CreateRitualCard extends StatelessWidget {
+ const _CreateRitualCard({this.onTap});
+
+ final VoidCallback? onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final l10n = context.l10n;
+ return Container(
+ decoration: BoxDecoration(
+ color: Theme.of(context).brightness == Brightness.dark
+ ? colorScheme.backgroundElevated2
+ : const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(
+ color: Theme.of(context).brightness == Brightness.dark
+ ? colorScheme.strokeFaint
+ : Colors.black.withValues(alpha: 0.04),
+ ),
+ ),
+ child: Material(
+ color: Colors.transparent,
+ child: InkWell(
+ onTap: onTap,
+ borderRadius: BorderRadius.circular(20),
+ child: Padding(
+ padding: const EdgeInsets.all(16),
+ child: Row(
+ children: [
+ Container(
+ width: 30,
+ height: 30,
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Center(
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedPlusSign,
+ size: 18,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Text(
+ l10n.ritualCreateYourOwn,
+ style: textTheme.bodyBold,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _RitualOverviewCard extends StatelessWidget {
+ const _RitualOverviewCard({required this.ritual, required this.progress});
+
+ final Ritual ritual;
+ final RitualProgress? progress;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final now = DateTime.now();
+ final today = DateTime(now.year, now.month, now.day);
+ final days = _lastScheduledDaysInclusive(
+ ritual: ritual,
+ todayMidnight: today,
+ count: 5,
+ );
+ final completions = [
+ for (final day in days) progress?.hasCompleted(day) ?? false,
+ ];
+
+ return GestureDetector(
+ onLongPress: () async {
+ final action = await showModalBottomSheet<String>(
+ context: context,
+ backgroundColor: Colors.transparent,
+ builder: (context) => _RitualActionsSheet(ritual: ritual),
+ );
+ switch (action) {
+ case "edit":
+ if (!context.mounted) return;
+ await showRitualEditor(context, ritual: ritual);
+ break;
+ case "delete":
+ await ritualsService.deleteRitual(ritual.id);
+ break;
+ }
+ },
+ child: Container(
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ color: Theme.of(context).brightness == Brightness.dark
+ ? colorScheme.backgroundElevated2
+ : const Color(0xFFFAFAFA),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(
+ color: Theme.of(context).brightness == Brightness.dark
+ ? colorScheme.strokeFaint
+ : Colors.black.withValues(alpha: 0.04),
+ ),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Container(
+ width: 30,
+ height: 30,
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Center(
+ child: Text(
+ ritual.icon,
+ style: textTheme.bodyBold.copyWith(height: 1),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ ),
+ ),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Text(
+ ritual.title.isEmpty
+ ? context.l10n.ritualUntitled
+ : ritual.title,
+ style: textTheme.bodyBold,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ ),
+ const SizedBox(width: 8),
+ _StreakChip(streak: progress?.currentStreak ?? 0),
+ ],
+ ),
+ const SizedBox(height: 16),
+ if (days.isNotEmpty)
+ LayoutBuilder(
+ builder: (context, constraints) {
+ const spacing = 16.0;
+ final available =
+ constraints.maxWidth - (spacing * (days.length - 1));
+ final tileWidth = available / days.length;
+ return Row(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ for (final (index, day) in days.indexed) ...[
+ if (index != 0) const SizedBox(width: spacing),
+ Expanded(
+ child: Align(
+ alignment: Alignment.center,
+ child: _buildDayThumbnail(
+ context: context,
+ ritual: ritual,
+ day: day,
+ tileWidth: tileWidth,
+ completed: completions[index],
+ nextCompleted: index == days.length - 1
+ ? null
+ : completions[index + 1],
+ index: index,
+ ),
+ ),
+ ),
+ ],
+ ],
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _buildDayThumbnail({
+ required BuildContext context,
+ required Ritual ritual,
+ required DateTime day,
+ required double tileWidth,
+ required bool completed,
+ required bool? nextCompleted,
+ required int index,
+ }) {
+ final now = DateTime.now();
+ final today = DateTime(now.year, now.month, now.day);
+ final dayKey =
+ DateTime(day.year, day.month, day.day).millisecondsSinceEpoch;
+ final file = progress?.recentFilesByDay[dayKey];
+ final count =
+ progress?.recentFileCountsByDay[dayKey] ?? (completed ? 1 : 0);
+ final fadePhoto = completed && nextCompleted == false;
+ final isToday = _isSameDay(day, today);
+ final rotation = switch (index % 4) {
+ 0 => -0.05,
+ 1 => 0.10,
+ 2 => -0.08,
+ _ => 0.08,
+ };
+
+ final variant = completed
+ ? RitualDayThumbnailVariant.photo
+ : (isToday
+ ? RitualDayThumbnailVariant.camera
+ : RitualDayThumbnailVariant.empty);
+
+ return RitualDayThumbnail(
+ day: day,
+ variant: variant,
+ width: tileWidth,
+ photoFile: file,
+ photoCount: count,
+ fadePhoto: fadePhoto,
+ rotation: rotation,
+ onCameraTap: isToday && !completed
+ ? () => openRitualCamera(context, ritual)
+ : null,
+ );
+ }
+}
+
+class _StreakChip extends StatelessWidget {
+ const _StreakChip({required this.streak});
+
+ final int streak;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ return Container(
+ padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(14),
+ ),
+ child: Text(
+ "$streak ⚑",
+ style:
+ textTheme.small.copyWith(color: colorScheme.textMuted, height: 1),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ );
+ }
+}
+
+class _RitualActionsSheet extends StatelessWidget {
+ const _RitualActionsSheet({required this.ritual});
+
+ final Ritual ritual;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ return SafeArea(
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
+ child: Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: colorScheme.strokeFaint, width: 0.5),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ListTile(
+ title: Text(context.l10n.edit, style: textTheme.body),
+ leading: HugeIcon(
+ icon: HugeIcons.strokeRoundedPencilEdit01,
+ color: colorScheme.textBase,
+ size: 22,
+ ),
+ onTap: () => Navigator.of(context).pop("edit"),
+ ),
+ Divider(
+ height: 0.5,
+ thickness: 0.5,
+ color: colorScheme.strokeFaint,
+ ),
+ ListTile(
+ title: Text(
+ context.l10n.delete,
+ style: textTheme.body.copyWith(color: Colors.red),
+ ),
+ leading: const HugeIcon(
+ icon: HugeIcons.strokeRoundedDelete02,
+ color: Colors.red,
+ size: 22,
+ ),
+ onTap: () => Navigator.of(context).pop("delete"),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+List<DateTime> _lastScheduledDaysInclusive({
+ required Ritual ritual,
+ required DateTime todayMidnight,
+ required int count,
+}) {
+ final daysOfWeek = ritual.daysOfWeek;
+ if (daysOfWeek.length != 7 || !daysOfWeek.any((enabled) => enabled)) {
+ return const [];
+ }
+
+ final result = <DateTime>[];
+ for (int offset = 0; result.length < count && offset < 366; offset++) {
+ final day = todayMidnight.subtract(Duration(days: offset));
+ final weekdayIndex = day.weekday % 7; // Sunday-first
+ if (!daysOfWeek[weekdayIndex]) continue;
+ result.add(day);
+ }
+ return result.reversed.toList(growable: false);
+}
+
+bool _isSameDay(DateTime a, DateTime b) {
+ return a.year == b.year && a.month == b.month && a.day == b.day;
+}
+
+const _tightTextHeightBehavior = TextHeightBehavior(
+ applyHeightToFirstAscent: false,
+ applyHeightToLastDescent: false,
+);
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_day_thumbnail.dart b/mobile/apps/photos/lib/ui/rituals/ritual_day_thumbnail.dart
new file mode 100644
index 0000000000..b9c68ec5ad
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_day_thumbnail.dart
@@ -0,0 +1,347 @@
+import "package:flutter/material.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/viewer/file/thumbnail_widget.dart";
+
+enum RitualDayThumbnailVariant { photo, empty, camera }
+
+class RitualDayThumbnail extends StatelessWidget {
+ const RitualDayThumbnail({
+ required this.day,
+ required this.variant,
+ required this.width,
+ this.photoFile,
+ this.photoCount,
+ this.fadePhoto = false,
+ this.rotation = 0,
+ this.onCameraTap,
+ super.key,
+ });
+
+ final DateTime day;
+ final RitualDayThumbnailVariant variant;
+ final double width;
+
+ final EnteFile? photoFile;
+ final int? photoCount;
+
+ final bool fadePhoto;
+ final double rotation;
+ final VoidCallback? onCameraTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final textTheme = getEnteTextTheme(context);
+ final tileHeight = width * (72 / 48);
+
+ final label = "${_weekdayLabel(context, day)}\n${day.day}";
+ return SizedBox(
+ width: width,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ _Tile(
+ width: width,
+ height: tileHeight,
+ variant: variant,
+ photoFile: photoFile,
+ photoCount: photoCount,
+ fadePhoto: fadePhoto,
+ rotation: rotation,
+ onCameraTap: onCameraTap,
+ ),
+ const SizedBox(height: 8),
+ Text(
+ label,
+ textAlign: TextAlign.center,
+ textHeightBehavior: _tightTextHeightBehavior,
+ style: textTheme.miniBoldMuted.copyWith(height: 1.05),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _Tile extends StatelessWidget {
+ const _Tile({
+ required this.width,
+ required this.height,
+ required this.variant,
+ required this.photoFile,
+ required this.photoCount,
+ required this.fadePhoto,
+ required this.rotation,
+ required this.onCameraTap,
+ });
+
+ final double width;
+ final double height;
+ final RitualDayThumbnailVariant variant;
+ final EnteFile? photoFile;
+ final int? photoCount;
+ final bool fadePhoto;
+ final double rotation;
+ final VoidCallback? onCameraTap;
+
+ static const _blueBorder = Color(0xFF1DA9FF);
+ static const _blueFill = Color(0x231DA9FF);
+ static const _greenBorder = Color(0xFF1DB954);
+ static const _greenFill = Color(0x191DB954);
+
+ @override
+ Widget build(BuildContext context) {
+ return switch (variant) {
+ RitualDayThumbnailVariant.photo => _PhotoTile(
+ width: width,
+ height: height,
+ file: photoFile,
+ count: photoCount ?? 0,
+ fadePhoto: fadePhoto,
+ rotation: rotation,
+ ),
+ RitualDayThumbnailVariant.empty => _DottedTile(
+ width: width,
+ height: height,
+ borderColor: _blueBorder,
+ fillColor: _blueFill,
+ ),
+ RitualDayThumbnailVariant.camera => _DottedTile(
+ width: width,
+ height: height,
+ borderColor: _greenBorder,
+ fillColor: _greenFill,
+ child: IconButton(
+ padding: EdgeInsets.zero,
+ visualDensity: VisualDensity.compact,
+ icon: const Icon(
+ Icons.photo_camera_outlined,
+ size: 21,
+ color: _greenBorder,
+ ),
+ onPressed: onCameraTap,
+ ),
+ ),
+ };
+ }
+}
+
+class _DottedTile extends StatelessWidget {
+ const _DottedTile({
+ required this.width,
+ required this.height,
+ required this.borderColor,
+ required this.fillColor,
+ this.child,
+ });
+
+ final double width;
+ final double height;
+ final Color borderColor;
+ final Color fillColor;
+ final Widget? child;
+
+ @override
+ Widget build(BuildContext context) {
+ return SizedBox(
+ width: width,
+ height: height,
+ child: CustomPaint(
+ painter: _DashedRRectBorderPainter(
+ color: borderColor,
+ strokeWidth: 1,
+ dashLength: 4,
+ dashGap: 3,
+ radius: 8,
+ ),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(8),
+ child: ColoredBox(
+ color: fillColor,
+ child: Center(child: child),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _PhotoTile extends StatelessWidget {
+ const _PhotoTile({
+ required this.width,
+ required this.height,
+ required this.file,
+ required this.count,
+ required this.fadePhoto,
+ required this.rotation,
+ });
+
+ final double width;
+ final double height;
+ final EnteFile? file;
+ final int count;
+ final bool fadePhoto;
+ final double rotation;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return SizedBox(
+ width: width,
+ height: height,
+ child: Stack(
+ clipBehavior: Clip.none,
+ children: [
+ Positioned.fill(
+ child: Center(
+ child: Transform.rotate(
+ angle: rotation,
+ child: Opacity(
+ opacity: fadePhoto ? 0.45 : 1.0,
+ child: Container(
+ width: width,
+ height: height,
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(8),
+ border: Border.all(color: Colors.white, width: 2),
+ boxShadow: const [
+ BoxShadow(
+ color: Color(0x3F000000),
+ blurRadius: 5.3,
+ offset: Offset(2, 2),
+ ),
+ ],
+ ),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(6),
+ child: file == null
+ ? const SizedBox.shrink()
+ : ThumbnailWidget(
+ file!,
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ shouldShowSyncStatus: false,
+ shouldShowArchiveStatus: false,
+ shouldShowPinIcon: false,
+ shouldShowOwnerAvatar: false,
+ shouldShowFavoriteIcon: false,
+ shouldShowVideoDuration: false,
+ shouldShowVideoOverlayIcon: false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ if (count > 1)
+ Positioned(
+ top: 6,
+ right: 6,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(6),
+ ),
+ child: Text(
+ "$count",
+ style: textTheme.tinyBold.copyWith(
+ color: const Color(0xFF1DB954),
+ ),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+String _weekdayLabel(BuildContext context, DateTime day) {
+ switch (day.weekday) {
+ case DateTime.monday:
+ return "M";
+ case DateTime.tuesday:
+ return "Tu";
+ case DateTime.wednesday:
+ return "W";
+ case DateTime.thursday:
+ return "Th";
+ case DateTime.friday:
+ return "F";
+ case DateTime.saturday:
+ return "Sa";
+ case DateTime.sunday:
+ return "Su";
+ default:
+ final labels = MaterialLocalizations.of(context).narrowWeekdays;
+ return labels[day.weekday % 7];
+ }
+}
+
+const _tightTextHeightBehavior = TextHeightBehavior(
+ applyHeightToFirstAscent: false,
+ applyHeightToLastDescent: false,
+);
+
+class _DashedRRectBorderPainter extends CustomPainter {
+ const _DashedRRectBorderPainter({
+ required this.color,
+ required this.strokeWidth,
+ required this.dashLength,
+ required this.dashGap,
+ required this.radius,
+ });
+
+ final Color color;
+ final double strokeWidth;
+ final double dashLength;
+ final double dashGap;
+ final double radius;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final paint = Paint()
+ ..color = color
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = strokeWidth
+ ..strokeCap = StrokeCap.round;
+
+ final inset = strokeWidth / 2;
+ final rect = Rect.fromLTWH(
+ inset,
+ inset,
+ (size.width - strokeWidth).clamp(0.0, double.infinity),
+ (size.height - strokeWidth).clamp(0.0, double.infinity),
+ );
+ final rrect = RRect.fromRectAndRadius(
+ rect,
+ Radius.circular((radius - inset).clamp(0.0, radius)),
+ );
+ final path = Path()..addRRect(rrect);
+
+ for (final metric in path.computeMetrics()) {
+ double distance = 0;
+ while (distance < metric.length) {
+ final next = (distance + dashLength).clamp(0.0, metric.length);
+ canvas.drawPath(metric.extractPath(distance, next), paint);
+ distance = next + dashGap;
+ }
+ }
+ }
+
+ @override
+ bool shouldRepaint(covariant _DashedRRectBorderPainter oldDelegate) {
+ return oldDelegate.color != color ||
+ oldDelegate.strokeWidth != strokeWidth ||
+ oldDelegate.dashLength != dashLength ||
+ oldDelegate.dashGap != dashGap ||
+ oldDelegate.radius != radius;
+ }
+}