mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-10 20:27:01 +01:00
Wires the shared gate (~/utils/scripts/check_file_length.sh) into a new .pre-commit-config.yaml as a local hook, checking only the files in the commit and failing rather than warning. No baseline, no allowlist. The repo had a hand-written .git/hooks/pre-commit running two checks; both are ported verbatim into the config rather than dropped, with the version bump ordered last so it cannot rewrite pubspec.yaml for a commit a gate is still about to reject. scripts/install_hooks.sh now installs pre-commit (and removes the legacy hook) instead of writing its own. .github/workflows/file-length.yml runs the same check on push, kept separate from release-apk.yml so an over-long file fails lint rather than blocking an APK release. Splits the four cleanest violations, all behaviour-preserving: note_template.dart 370 -> 203 + parser (186) firebase_backend.dart 308 -> barrel (24) + project/store/client port_guard.dart 315 -> 232 + linux_system_probe (100) notes_list_screen.dart 698 -> 225 + 5 widget/nav files Where a file had external callers, the original path stays as a barrel that re-exports the split parts, so no call site changed. Verified: 313 tests pass, coverage identical at 99.9% / 1922 lines (per-file too -- notes_list's 281 covered lines are now 81+75+51+41+22+11), flutter analyze clean, and a staged 260-line file makes git commit fail. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
110 lines
3.3 KiB
Dart
110 lines
3.3 KiB
Dart
/// The Created / Last-updated date-range control used by the filter sheet.
|
|
///
|
|
/// Split out of `notes_list_screen.dart` for file size. Public only because
|
|
/// Dart privacy is library-scoped and the filter sheet now lives in a
|
|
/// different file.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// A labelled date range shown as presets plus a custom-range picker.
|
|
class DateRangeField extends StatelessWidget {
|
|
/// Creates a labelled date-range control.
|
|
const DateRangeField({
|
|
required this.label,
|
|
required this.from,
|
|
required this.to,
|
|
required this.onChanged,
|
|
super.key,
|
|
});
|
|
|
|
/// Heading shown above the control (e.g. 'Created').
|
|
final String label;
|
|
|
|
/// Start of the selected range, or null when unbounded.
|
|
final DateTime? from;
|
|
|
|
/// End of the selected range, or null when unbounded.
|
|
final DateTime? to;
|
|
|
|
/// Called with the new (from, to); either may be null to clear.
|
|
final void Function(DateTime? from, DateTime? to) onChanged;
|
|
|
|
bool get _hasRange => from != null || to != null;
|
|
|
|
/// Sets a preset range of the last [days] days ending today.
|
|
void _applyDays(int days) {
|
|
final now = DateTime.now();
|
|
final today = DateTime(now.year, now.month, now.day);
|
|
onChanged(today.subtract(Duration(days: days - 1)), today);
|
|
}
|
|
|
|
Future<void> _pickCustom(BuildContext context) async {
|
|
final now = DateTime.now();
|
|
final picked = await showDateRangePicker(
|
|
context: context,
|
|
firstDate: DateTime(2020),
|
|
lastDate: DateTime(now.year + 1, 12, 31),
|
|
initialDateRange: (from != null && to != null)
|
|
? DateTimeRange(start: from!, end: to!)
|
|
: null,
|
|
);
|
|
if (picked != null) onChanged(picked.start, picked.end);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text(label, style: theme.textTheme.labelLarge),
|
|
const Spacer(),
|
|
if (_hasRange)
|
|
Text(_rangeLabel(), style: theme.textTheme.bodySmall),
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
Wrap(
|
|
spacing: 8,
|
|
children: [
|
|
ActionChip(
|
|
label: const Text('Today'),
|
|
onPressed: () => _applyDays(1),
|
|
),
|
|
ActionChip(
|
|
label: const Text('7 days'),
|
|
onPressed: () => _applyDays(7),
|
|
),
|
|
ActionChip(
|
|
label: const Text('30 days'),
|
|
onPressed: () => _applyDays(30),
|
|
),
|
|
ActionChip(
|
|
label: const Text('Custom…'),
|
|
onPressed: () => _pickCustom(context),
|
|
),
|
|
if (_hasRange)
|
|
ActionChip(
|
|
avatar: const Icon(Icons.clear, size: 16),
|
|
label: const Text('Any'),
|
|
onPressed: () => onChanged(null, null),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// Compact "YYYY-MM-DD → YYYY-MM-DD" (or one-sided) summary of the range.
|
|
String _rangeLabel() {
|
|
String d(DateTime? t) =>
|
|
t == null ? '…' : '${t.year}-${_two(t.month)}-${_two(t.day)}';
|
|
return '${d(from)} → ${d(to)}';
|
|
}
|
|
|
|
String _two(int n) => n.toString().padLeft(2, '0');
|
|
}
|