flutter_khmer_chankitec 0.0.8 copy "flutter_khmer_chankitec: ^0.0.8" to clipboard
flutter_khmer_chankitec: ^0.0.8 copied to clipboard

A Flutter plugin for Khmer lunar calendar (Chhankitek/ចន្ទគតិ) calculations. Convert Gregorian dates to Khmer lunar dates with full support for Buddhist calendar features including Sila days detection.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_khmer_chankitec/flutter_khmer_chankitec.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Khmer Chankitec Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Khmer Lunar Calendar Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late KhmerLunarDate _lunarDate;

  @override
  void initState() {
    super.initState();
    // Get current date in Khmer lunar calendar
    _lunarDate = Chhankitek.now();
  }

  void _refreshDate() {
    setState(() {
      _lunarDate = Chhankitek.now();
    });
  }

  @override
  Widget build(BuildContext context) {
    final now = DateTime.now();

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: SingleChildScrollView(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'Today\'s Date',
                style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 30),

              // Gregorian Date
              Card(
                elevation: 4,
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Column(
                    children: [
                      const Text(
                        'Gregorian Calendar',
                        style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      const SizedBox(height: 10),
                      Text(
                        '${now.day}/${now.month}/${now.year}',
                        style: const TextStyle(fontSize: 24),
                      ),
                    ],
                  ),
                ),
              ),

              const SizedBox(height: 20),

              // Khmer Lunar Date
              Card(
                elevation: 4,
                color: Colors.deepPurple.shade50,
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Column(
                    children: [
                      Text(
                        'Khmer Lunar Calendar',
                        style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.w600,
                          color: Colors.deepPurple.shade700,
                        ),
                      ),
                      const SizedBox(height: 15),
                      Column(
                        children: [
                          Text(
                            _lunarDate.toString(),
                            style: const TextStyle(fontSize: 16),
                            textAlign: TextAlign.center,
                          ),

                          const SizedBox(height: 10),

                          /// display shortLunarDay with space
                          Text(
                            'With space: ${Chhankitek.fromDate(DateTime(now.year, now.month, now.day)).shortLunarDay}',
                            style: const TextStyle(
                              fontSize: 18,
                              fontWeight: FontWeight.bold,
                            ),
                            textAlign: TextAlign.center,
                          ),

                          /// display shortLunarDay compact (no space)
                          Text(
                            'Compact: ${Chhankitek.fromDate(DateTime(now.year, now.month, now.day)).shortLunarDayCompact}',
                            style: const TextStyle(
                              fontSize: 18,
                              fontWeight: FontWeight.bold,
                            ),
                            textAlign: TextAlign.center,
                          ),
                        ],
                      ),
                      const SizedBox(height: 15),
                      if (_lunarDate.isSilaDay)
                        Container(
                          padding: const EdgeInsets.symmetric(
                            horizontal: 12,
                            vertical: 6,
                          ),
                          decoration: BoxDecoration(
                            color: Colors.orange.shade100,
                            borderRadius: BorderRadius.circular(20),
                            border: Border.all(color: Colors.orange.shade700),
                          ),
                          child: Text(
                            'ថ្ងៃសីល (Sila Day)',
                            style: TextStyle(
                              color: Colors.orange.shade900,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                    ],
                  ),
                ),
              ),

              const SizedBox(height: 20),

              // Lunar Date Details
              Card(
                elevation: 4,
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      const Text(
                        'Lunar Date Details',
                        style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      const Divider(height: 20),
                      _buildDetailRow('Day of Week:', _lunarDate.dayOfWeek),
                      _buildDetailRow('Lunar Day:', '${_lunarDate.lunarDay}'),
                      _buildDetailRow('Lunar Month:', _lunarDate.lunarMonth),
                      _buildDetailRow('Lunar Zodiac:', _lunarDate.lunarZodiac),
                      _buildDetailRow('Lunar Era:', _lunarDate.lunarEra),
                      _buildDetailRow('Lunar Year:', _lunarDate.lunarYear),
                      const Divider(height: 20),
                      _buildDetailRow('Solar Day:', _lunarDate.solarDay),
                      _buildDetailRow('Solar Month:', _lunarDate.solarMonth),
                      _buildDetailRow('Solar Year:', _lunarDate.solarYear),
                    ],
                  ),
                ),
              ),

              const SizedBox(height: 20),

              // Special Days Info
              Card(
                elevation: 4,
                color: Colors.amber.shade50,
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Column(
                    children: [
                      const Text(
                        'Special Day Checks',
                        style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      const Divider(height: 20),
                      _buildSpecialDayRow(
                        'Sila Day (ថ្ងៃសីល)',
                        _lunarDate.isSilaDay,
                      ),
                      _buildSpecialDayRow(
                        'Full Moon (ថ្ងៃពេញបូណ៌មី)',
                        _lunarDate.isFullMoon,
                      ),
                      _buildSpecialDayRow(
                        'New Moon (ថ្ងៃបាតមាស)',
                        _lunarDate.isNewMoon,
                      ),
                    ],
                  ),
                ),
              ),

              const SizedBox(height: 20),

              // Number Conversion Example
              Card(
                elevation: 4,
                color: Colors.green.shade50,
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Column(
                    children: [
                      const Text(
                        'Number Conversion',
                        style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      const Divider(height: 20),
                      _buildDetailRow(
                        'Number 2024:',
                        KhmerNumberUtils.toKhmerNumber(2024),
                      ),
                      _buildDetailRow(
                        'Number 12345:',
                        KhmerNumberUtils.toKhmerNumber(12345),
                      ),
                      _buildDetailRow(
                        'Current Year:',
                        KhmerNumberUtils.toKhmerNumber(now.year),
                      ),
                      _buildDetailRow(
                        'Current Day:',
                        KhmerNumberUtils.toKhmerNumber(now.day),
                      ),
                    ],
                  ),
                ),
              ),

              const SizedBox(height: 30),

              ElevatedButton.icon(
                onPressed: _refreshDate,
                icon: const Icon(Icons.refresh),
                label: const Text('Refresh'),
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 30,
                    vertical: 15,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildDetailRow(String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4.0),
      child: Row(
        children: [
          Expanded(
            flex: 2,
            child: Text(
              label,
              style: const TextStyle(fontWeight: FontWeight.w500),
            ),
          ),
          Expanded(
            flex: 3,
            child: Text(value, style: const TextStyle(color: Colors.blue)),
          ),
        ],
      ),
    );
  }

  Widget _buildSpecialDayRow(String label, bool isSpecial) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 6.0),
      child: Row(
        children: [
          Expanded(
            child: Text(
              label,
              style: const TextStyle(fontWeight: FontWeight.w500),
            ),
          ),
          Icon(
            isSpecial ? Icons.check_circle : Icons.cancel,
            color: isSpecial ? Colors.green : Colors.grey,
            size: 24,
          ),
        ],
      ),
    );
  }
}
1
likes
145
points
168
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for Khmer lunar calendar (Chhankitek/ចន្ទគតិ) calculations. Convert Gregorian dates to Khmer lunar dates with full support for Buddhist calendar features including Sila days detection.

Repository (GitHub)
View/report issues

Topics

#khmer #calendar #lunar-calendar #buddhist-calendar #cambodia

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_khmer_chankitec