ethio_greg_dual_calendar 0.1.1
ethio_greg_dual_calendar: ^0.1.1 copied to clipboard
Dual-calendar dates and calendar UIs for Flutter in both the Gregorian and Ethiopian (Amete Mihret) calendars, localized in English, Amharic, and Afaan Oromoo.
import 'package:ethio_greg_dual_calendar/ethio_greg_dual_calendar.dart';
import 'package:flutter/material.dart';
void main() => runApp(const ExampleApp());
/// Demonstrates live calendar/language switching: every rendered date follows
/// the settings row at the top, with no per-widget plumbing.
class ExampleApp extends StatefulWidget {
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
String _language = 'en';
var _calendar = CalendarSystem.gregorian;
var _geez = false;
DateTime _selected = DateTime.now();
DateTime _focused = DateTime.now();
void _apply(void Function() change) {
setState(() {
change();
// One global assignment; the setState rebuild re-resolves every date.
AppDate.config = EthioCalendarConfig(
calendar: _calendar,
l10n: CalendarL10n.forLocale(_language),
geezDayNumbers: _geez,
);
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ethio_greg_dual_calendar example',
theme: ThemeData(colorSchemeSeed: Colors.green),
home: Scaffold(
appBar: AppBar(title: const Text('ethio_greg_dual_calendar')),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
// Settings: language, calendar system, Ge'ez day numbers.
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Language'),
DropdownButton<String>(
value: _language,
items: const [
DropdownMenuItem(value: 'en', child: Text('English')),
DropdownMenuItem(value: 'am', child: Text('አማርኛ')),
DropdownMenuItem(value: 'om', child: Text('Afaan Oromoo')),
DropdownMenuItem(value: 'ti', child: Text('ትግርኛ')),
],
onChanged: (v) => _apply(() => _language = v!),
),
],
),
CalendarSelector(
value: _calendar,
onChanged: (v) => _apply(() => _calendar = v),
),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Ge\'ez day numbers (፩ ፲ ፴)'),
value: _geez,
onChanged: (v) => _apply(() => _geez = v),
),
const Divider(),
// Formatted dates re-resolve on every settings change.
Text(
AppDate.mediumDate(_selected),
style: Theme.of(context).textTheme.headlineSmall,
),
Text(AppDate.relativeOrWeekdayMonthDay(_selected)),
const SizedBox(height: 16),
MonthSelector(
date: _focused,
onDateChanged: (d) => setState(() => _focused = d),
),
MonthCalendar(
focusedDate: _focused,
selectedDate: _selected,
firstDate: DateTime(2020),
lastDate: DateTime(2030),
onDaySelected: (day) => setState(() => _selected = day),
onFocusedDateChanged: (month) =>
setState(() => _focused = month),
eventCountForDay: (day) => day.day % 7 == 0 ? 2 : 0,
),
const Divider(),
const Text('Day strip (auto-scrolls to the selected day):'),
WeekLongCalendar(
selectedDate: _selected,
onDaySelected: (day) => setState(() {
_selected = day;
_focused = day;
}),
),
const Divider(),
// EthioCalendarScope: both systems side by side in one tree,
// independent of the global settings above.
const Text('Both calendars at once via EthioCalendarScope:'),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: EthioCalendarScope(
config: const EthioCalendarConfig(),
child: Builder(
builder: (context) => Text(
EthioCalendarScope.of(context).mediumDate(_selected),
textAlign: TextAlign.center,
),
),
),
),
Expanded(
child: EthioCalendarScope(
config: const EthioCalendarConfig(
calendar: CalendarSystem.ethiopian,
l10n: CalendarL10n.am,
),
child: Builder(
builder: (context) => Text(
EthioCalendarScope.of(context).mediumDate(_selected),
textAlign: TextAlign.center,
),
),
),
),
],
),
],
),
),
);
}
}