flutter_custom_calendar 1.0.4+0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • new59

flutter_custom_calendar #

本插件是基于flutter_custom_calendar做了稍微的修改进行上传的。

具体使用方法见flutter_custom_calendar

新增一个选择mode

支持选择开始和结束,选择范围内的日期,使用方法

controller = new CalendarController(
    minYear: 2019,
    minYearMonth: 1,
    maxYear: 2021,
    maxYearMonth: 12,
    showMode: CalendarConstants.MODE_SHOW_MONTH_AND_WEEK,
    selectedDateTimeList: _selectedDate,
    selectMode: CalendarSelectedMode.mutltiStartToEndSelect)
  ..addOnCalendarSelectListener((dateModel) {
    _selectedModels.add(dateModel);
  })
  ..addOnCalendarUnSelectListener((dateModel) {
    if (_selectedModels.contains(dateModel)) {
      _selectedModels.remove(dateModel);
    }
  });

CalendarSelectedMode.mutltiStartToEndSelect这个选择模式会选择开始和结束中间的 默认选择的。

安装和使用 #

Use this package as a library

  1. Depend on it Add this to your package's pubspec.yaml file:
dependencies:
  flutter_custom_calendar: ^1.0.3
  1. 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.

  1. Import it Now in your Dart code, you can use:
import 'package:flutter_custom_calendar/flutter_custom_calendar.dart';

动画演示 #

查看API #

查看一个例子 如何使用 #

[1.0.4+0.4] #

  • 新增三个模式相互且含数据不影响

[1.0.1] #

  • 新增多选范围功能

example/lib/main.dart

import 'dart:collection';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/constants/constants.dart';
import 'package:flutter_custom_calendar/controller.dart';
import 'package:flutter_custom_calendar/flutter_custom_calendar.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,
          visualDensity: VisualDensity.adaptivePlatformDensity,
          focusColor: Colors.teal),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  CalendarController controller;
  CalendarViewWidget calendar;
  HashSet<DateTime> _selectedDate = new HashSet();
  HashSet<DateModel> _selectedModels = new HashSet();
  @override
  void initState() {
    _selectedDate.add(DateTime.now());
    controller = new CalendarController(
        minYear: 2019,
        minYearMonth: 1,
        maxYear: 2021,
        maxYearMonth: 12,
        showMode: CalendarConstants.MODE_SHOW_MONTH_AND_WEEK,
        selectedDateTimeList: _selectedDate,
        selectMode: CalendarSelectedMode.singleSelect)
      ..addOnCalendarSelectListener((dateModel) {
        _selectedModels.add(dateModel);
        setState(() {
          _selectDate = _selectedModels.toString();
        });
      })
      ..addOnCalendarUnSelectListener((dateModel) {
        if (_selectedModels.contains(dateModel)) {
          _selectedModels.remove(dateModel);
        }
        setState(() {
          _selectDate = '';
        });
      });
    calendar = new CalendarViewWidget(
      calendarController: controller,
      dayWidgetBuilder: (DateModel model) {
        double wd = (MediaQuery.of(context).size.width - 20) / 7;
        bool _isSelected = model.isSelected;
        if (_isSelected &&
            CalendarSelectedMode.singleSelect ==
                controller.calendarConfiguration.selectMode) {
          _selectDate = model.toString();
        }
        return ClipRRect(
          borderRadius: BorderRadius.all(Radius.circular(wd / 2)),
          child: Container(
            color: _isSelected ? Theme.of(context).focusColor : Colors.white,
            alignment: Alignment.center,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  model.day.toString(),
                  style: TextStyle(
                      color: model.isCurrentMonth
                          ? (_isSelected == false
                              ? (model.isWeekend
                                  ? Colors.black38
                                  : Colors.black87)
                              : Colors.white)
                          : Colors.black38),
                ),
//              Text(model.lunarDay.toString()),
              ],
            ),
          ),
        );
      },
    );
    super.initState();
  }

  String _selectDate = '';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: CupertinoScrollbar(
        child: CustomScrollView(
          slivers: <Widget>[
            _topButtons(),
            SliverToBoxAdapter(
              child: calendar,
            ),
            SliverToBoxAdapter(
              child: Container(
                child: Text(
                  ' $_selectDate ',
                  style: TextStyle(color: Theme.of(context).focusColor),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _topButtons() {
    return SliverToBoxAdapter(
      child: Wrap(
        direction: Axis.vertical,
        crossAxisAlignment: WrapCrossAlignment.start,
        children: <Widget>[
          Text('请选择mode'),
          FlatButton(
            child: Text(
              'singleSelect',
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              setState(() {
                controller.calendarConfiguration.selectMode =
                    CalendarSelectedMode.singleSelect;
              });
            },
            color: controller.calendarConfiguration.selectMode ==
                    CalendarSelectedMode.singleSelect
                ? Colors.teal
                : Colors.black38,
          ),
          FlatButton(
            child: Text(
              'multiSelect',
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              setState(() {
                controller.calendarConfiguration.selectMode =
                    CalendarSelectedMode.multiSelect;
              });
            },
            color: controller.calendarConfiguration.selectMode ==
                    CalendarSelectedMode.multiSelect
                ? Colors.teal
                : Colors.black38,
          ),
          FlatButton(
            child: Text(
              'mutltiStartToEndSelect',
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              setState(() {
                controller.calendarConfiguration.selectMode =
                    CalendarSelectedMode.mutltiStartToEndSelect;
              });
            },
            color: controller.calendarConfiguration.selectMode ==
                    CalendarSelectedMode.mutltiStartToEndSelect
                ? Colors.teal
                : Colors.black38,
          )
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_custom_calendar: ^1.0.4+0.4

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:flutter_custom_calendar/flutter_custom_calendar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
75
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_custom_calendar that is a package requiring null.

Health suggestions

Fix lib/utils/solar_term_util.dart. (-25 points)

Analysis of lib/utils/solar_term_util.dart reported 65 hints, including:

line 8 col 23: Name non-constant identifiers using lowerCamelCase.

line 36 col 23: Name non-constant identifiers using lowerCamelCase.

line 39 col 23: Name non-constant identifiers using lowerCamelCase.

line 43 col 23: Name non-constant identifiers using lowerCamelCase.

line 46 col 29: Name non-constant identifiers using lowerCamelCase.

Fix lib/utils/lunar_util.dart. (-14.39 points)

Analysis of lib/utils/lunar_util.dart reported 31 hints, including:

line 8 col 20: Name non-constant identifiers using lowerCamelCase.

line 236 col 20: Name non-constant identifiers using lowerCamelCase.

line 467 col 39: Name non-constant identifiers using lowerCamelCase.

line 472 col 23: Name non-constant identifiers using lowerCamelCase.

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

Fix lib/controller.dart. (-8.63 points)

Analysis of lib/controller.dart reported 18 hints, including:

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

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

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

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

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

Fix additional 16 files with analysis or formatting issues. (-23.65 points)

Additional issues in the following files:

  • lib/utils/date_util.dart (15 hints)
  • lib/calendar_provider.dart (6 hints)
  • lib/configuration.dart (4 hints)
  • lib/constants/constants.dart (3 hints)
  • lib/utils/LogUtil.dart (3 hints)
  • lib/widget/default_custom_day_view.dart (3 hints)
  • lib/widget/month_view.dart (3 hints)
  • lib/widget/base_day_view.dart (2 hints)
  • lib/widget/calendar_view.dart (2 hints)
  • lib/widget/week_view.dart (2 hints)
  • lib/cache_data.dart (1 hint)
  • lib/model/date_model.dart (1 hint)
  • lib/widget/base_week_bar.dart (1 hint)
  • lib/widget/default_combine_day_view.dart (1 hint)
  • lib/widget/only_one_pointer_widget.dart (1 hint)
  • lib/utils/math_util.dart (Run flutter format to format lib/utils/math_util.dart.)

Maintenance suggestions

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
provider ^4.1.3 4.3.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
nested 0.0.4
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test