Skip to content

Commit bcde6f8

Browse files
committed
feat: add YaruCalendar
1 parent ec543b0 commit bcde6f8

10 files changed

Lines changed: 857 additions & 255 deletions

example/lib/example_page_items.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'code_snippet_button.dart';
66
import 'pages/autocomplete_page.dart';
77
import 'pages/banner_page.dart';
88
import 'pages/border_container_page.dart';
9+
import 'pages/calendar_page.dart';
910
import 'pages/carousel_page.dart';
1011
import 'pages/checkbox_page.dart';
1112
import 'pages/choice_chip_bar_page.dart';
@@ -143,6 +144,14 @@ final examplePageItems = <PageItem>[
143144
? const Icon(YaruIcons.calendar_month_filled)
144145
: const Icon(YaruIcons.calendar_month),
145146
),
147+
PageItem(
148+
title: 'YaruCalendar',
149+
floatingActionButtonBuilder: null,
150+
pageBuilder: (context) => const CalendarPage(),
151+
iconBuilder: (context, selected) => selected
152+
? const Icon(YaruIcons.calendar_month_filled)
153+
: const Icon(YaruIcons.calendar_month),
154+
),
146155
PageItem(
147156
title: 'YaruDraggable',
148157
floatingActionButtonBuilder: (_) => const CodeSnippedButton(
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:yaru/yaru.dart';
3+
4+
class CalendarPage extends StatefulWidget {
5+
const CalendarPage({super.key});
6+
7+
@override
8+
State<CalendarPage> createState() => _CalendarPageState();
9+
}
10+
11+
class _CalendarPageState extends State<CalendarPage> {
12+
DateTime selectedDateTime = DateTime.now();
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return Center(
17+
child: Column(
18+
mainAxisSize: MainAxisSize.min,
19+
children: [
20+
YaruDayPicker(
21+
firstDate: DateTime(1900),
22+
lastDate: DateTime(2100),
23+
initialDate: DateTime.now(),
24+
onDaySelected: (day) => setState(() => selectedDateTime = day),
25+
),
26+
Text('Selected day: ${selectedDateTime.toString()}'),
27+
].withSpacing(25),
28+
),
29+
);
30+
}
31+
}
32+
33+
extension _ListSpacing on List<Widget> {
34+
List<Widget> withSpacing(double spacing) {
35+
return expand((item) sync* {
36+
yield SizedBox(height: spacing);
37+
yield item;
38+
}).skip(1).toList();
39+
}
40+
}

lib/src/foundation/yaru_entry_segment.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ enum YaruSegmentEventReturnAction {
77
ignored,
88
}
99

10-
abstract interface class YaruEntrySegment implements Listenable {
10+
abstract interface class YaruEntrySegment implements ChangeNotifier {
1111
String? get input;
1212
String get text;
1313
int get length;
@@ -396,7 +396,8 @@ class YaruSegmentedEntryController extends ChangeNotifier {
396396
/// Returns true if successful.
397397
bool maybeSelectPreviousSegment() {
398398
if (_index - 1 >= 0) {
399-
index--;
399+
_index--;
400+
notifyListeners();
400401
return true;
401402
}
402403
return false;
@@ -406,20 +407,23 @@ class YaruSegmentedEntryController extends ChangeNotifier {
406407
/// Returns true if successful.
407408
bool maybeSelectNextSegment() {
408409
if (_index + 1 < length) {
409-
index++;
410+
_index++;
411+
notifyListeners();
410412
return true;
411413
}
412414
return false;
413415
}
414416

415417
/// Selects the first segment.
416418
void selectFirstSegment() {
417-
index = 0;
419+
_index = 0;
420+
notifyListeners();
418421
}
419422

420423
/// Selects the last segment.
421424
void selectLastSegment() {
422-
index = length - 1;
425+
_index = length - 1;
426+
notifyListeners();
423427
}
424428
}
425429

0 commit comments

Comments
 (0)