chinese_calendar 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

chinese_calendar #

带有农历的日历

输入图片说明 输入图片说明 输入图片说明

Example #


class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Container(
          child: CalendarView(
            initDateTime: DateTime.now(),
          ),
        ),
      ),
    );
  }
}

[0.0.1] - TODO: 2020-2-29. #

  • TODO: 基础日历控件.

[0.0.2] - TODO: 2020-3-2. #

  • TODO: 添加日期范围选择功能.
  • TODO: 添加主题设置功能.

example/lib/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: Text("日历控件"),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                return BasePage();
              }));
            },
          ),
          ListTile(
            title: Text("选择日期范围"),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                return SelelctDatePage();
              }));
            },
          ),
          ListTile(
            title: Text("选择日期对话框"),
            onTap: () {
              showDateRangePicker(context: context, initDateTime: DateTime.now());
            },
          ),
        ],
      ),
    );
  }
}

class BasePage extends StatefulWidget {
  @override
  _BasePageState createState() => _BasePageState();
}

class _BasePageState extends State<BasePage> {
  CalendarInfo _clickInfo;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(24),
            child: CalendarView(
              initDateTime: DateTime.now(),
              builderItem: _builderItem,
            ),
          ),
          Text(""),
          Text("${_clickInfo?.solarDate?.toString()?.substring(0, 10)}"),
          Text("${_clickInfo?.lunarYearName}年${_clickInfo?.lunarMonthName}${_clickInfo?.lunarDayName}"),
          Text("${_clickInfo?.animal}"),
          Text("${_clickInfo?.astro}"),
          Text("${_clickInfo?.term}"),
          Text("${_clickInfo?.festival}"),
          Text("${_clickInfo?.lunarFestival}"),
        ],
      ),
    );
  }

  Widget _builderItem(CalendarInfo info, Widget child, int month) {
    if (null != _clickInfo && 0 == CalendarUtils.compareDate(_clickInfo.solarDate, info.solarDate)) {
      child = DecoratedBox(
        decoration: BoxDecoration(
          border: Border.all(color: Theme.of(context).accentColor),
        ),
        child: child,
      );
    }

    return InkWell(
      child: child,
      onTap: () {
        setState(() {
          _clickInfo = info;
        });
      },
    );
  }
}

class SelelctDatePage extends StatefulWidget {
  @override
  _SelelctDatePageState createState() => _SelelctDatePageState();
}

class _SelelctDatePageState extends State<SelelctDatePage> {
  DateTime _start;
  DateTime _end;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(24),
            child: CalenderSelect(
              initDateTime: DateTime.now(),
              showOtherDay: true,
              showLunary: false,
              onSelect: (start, end) {
                setState(() {
                  _start = start;
                  _end = end;
                });
              },
            ),
          ),
          Text(""),
          Text("开始 ${_start?.toString()?.substring(0, 10)}"),
          Text("结束 ${_end?.toString()?.substring(0, 10)}"),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  chinese_calendar: ^0.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:chinese_calendar/chinese_calendar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
38
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/src/calendar_utils.dart. (-0.50 points)

Analysis of lib/src/calendar_utils.dart reported 1 hint:

line 359 col 7: The declaration '_solarDays' isn't referenced.

Fix lib/src/calendar_view.dart. (-0.50 points)

Analysis of lib/src/calendar_view.dart reported 1 hint:

line 166 col 7: This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: _CalenderContent.calendarUtils

Fix lib/src/calender_theme.dart. (-0.50 points)

Analysis of lib/src/calender_theme.dart reported 1 hint:

line 3 col 1: Prefer using /// for doc comments.

Format lib/src/calender_select.dart.

Run flutter format to format lib/src/calender_select.dart.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test