作用

Flutter仿钉钉考勤日历

原型

Flutter仿钉钉考勤日历

开发

  1. 运用
          // 考勤日历
DatePickerDialog(
initialDate: DateTime.now(),
firstDate: DateTime(2020),
lastDa数组的界说te数组的界说: DateTime(2030),
onDateChanged: onDateChanged,
// 0:无情况,1:正常考勤  2:失Flutter常考情,迟到,早退,
// 若不满一个月,日历会自动用0补满一个月
checking: [
0,数组词
0,
1,
2,
],
),

DatePickerDialog是在存在与F数组公式lutter的material包中,flutter结构优缺点F数组去重lutter自带的日历是以dialog方法存在的,本文将dialo数组ggithub永久回家地址改成StatefulWidget直接数组函数的使用方法在页面中,将剩余东西去掉,直接在material/caleFlutterndar_date_picker.dart中_DayPicker上进行修改。
2. 修改日历中日期样式:

 Widget dayWgithubidget = Container(
margin: EdgeInsets.all(4.0),
decoration: decoration,
alignment: Alignment.center,
child: C数组和链表的差异olumn(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(localizations.formatDecimal(daygithub中文官网网页),
style: TextStyle(
fontSize: 14.0,
color: dayColor,
fontWeight: FontWeight.b数组去重old))数组指针,
Visibility(
visible: checking[day - 1] == 1 || checking[day - 1] == 2,
child: Container(数组函数的使用方法
height: 6.0,
width: 6.0,
decoration: Bogithub中文官网网页xDecorationgiti轮胎是什么品牌(
shape: BoxShape.cirflutter结构优缺点cle,
color: isSelectedDay ? Colors.wflutteredhi数组指针te :
(checkiflutter结构ng[day - 1] == 1 ?  Color(0xFF1376EE): Color(0xFFFF8Agiti21)),
),
),
),
],
),
);

Visi数组词bility本来没有,git指令是修改加上去的,主要是闪现当天数组去重打卡情况,若打卡正常则在日期闪现下方闪现蓝色小点,若有异常则闪现橙色的点,若没有情况就不闪现,checking则是运用DatePickerDialog传入的,由于日历从1开始,数组是从索引0开始的,所以运用checking[day – 1]才华精确获取某一日数组词的打卡情况,day 则是日历中某一月中悉数日期。

2.设置数组和链表的差异星期标题
修改后数组c言语

  Liflutter菜鸟教程st<Widget&gtgitlab; _dayHeaders() {
fingiti轮胎是什么品牌al List<Widget> result = <Widget>数组c言语[];
final List<String> weekdays = ["日", "一", "flutter怎样读音发音二", "三", "四", "五", "六"];
for (int i = 1; true; i = (i + 1) % 7) {
fgitlabinal String weekday = weeflutter结构优缺点kdays[i];
result.add(ExcludeSemantics(
child: Center(
child: Te数组的界说xt(weekday,
style: TextStyle(fontSize: 14.0, cgitiolor: Color(0xFgiti轮胎是什么品牌Fgit指令999999)))),
)flutter值得学吗);
if (i == (1 - 1) % 7) break;
}
return result;
}

Git文:

  List<Widget> _dayHeaders(TextStyle? headerStylgithub中文官网网页e, MaterialLocalizations localizations) {
final List数组的界说<Widget> result = <Widget>[];
for (int i = localizations.firstDayOfWeekIndex; true; i = (i + 1) % 7) {
final String weekday = localizations.narrowWeekdays[i];
result.add(ExcludeSemantics(
child: Center(child:github Text(weekday, stylgit教程e: headerStyle)),
)flutter结构优缺点);
if (i == (localizations.firstDayOfWeekIGitndexgithub中文官网网页 - 1) % 7)
break;
}
retugithub永久回家地址rn result;
}

localizations.firstDayOfgitiWeekIndex回来值为0或许1,若回来0,则周日为每周的第一天;若回来1,则星期一为每周的第一天。本文中没有从localizations.firstDayOfWeekIndex获取,直接赋值为1,则每周从星期一开始。

3.补全每个月空白日期:

  • 获取指定月份有多少fluttered
  static int getDaysInMonth(int year, int month) {
if(month < 1){
yegitlabar = year - 1;
month = month + 12;
}
if(month > 12){
year = year + 1;
month = month - 12;
}
if (month =gitlab= DateTime.february) {
final bool isLeapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
r数组c言语eturn isLeapYear ? 29 : 28;
}
const Lgit教程ist<int> daysInMonth = <int>[31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3giti轮胎1];
return daysInMonth[month - 1];
}flutter菜鸟教程
  • 获取指定月份1日的偏移量,即每个月第一天是星期几,若1号是星期3,由于日历每周是从第一天开始的,所以第一周的星期的星期一,星期二为空白,需求补全上个月的倒数后两天,所以还需求获取上个月的毕竟数组两天是哪两天。
// 获取日期偏移
static int firstDayOffsets(int year,github永久回家地址 int month) {
final int weekdayFromMonday = DateTime(year,gitlab month).weekday - 1;
int firstDayOfWeekIndex = 1;
firstDayOfWeekIndex = (firstDayOfWeekIndex - 1) % 7;
return (weekdayFromMonday - firstDayO数组词fWeekIndex) % 7;
}
...
// 补全开始日期
int day = -dayOffse数组t;
while (day < days数组和链表的差异InMonth) {
day++;
if (day < 1) {
da数组排序yItems.adflutter怎样读音发音d(Container(
margin: EdgeInsets.all(4.0),
alignment: Alignment.cenGitter,
chilfluttershyd: Coflutter值得学吗lumn(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// daysInPreMonth上个月的天数-本月日期偏移则可把本月开始缺失的日期补全
Text(数组初始化localizations.fo数组指针rmatDecimal(daysInPreMonth - day.abs()),
style: TextStyle(
fontSize: 14.0,
color: Color(0xFF88888giti轮胎8),
fontWei数组公式ght: FontWeight.bold)),
Visibility(
visible: false,
chil数组去重d: Container(
height: 6.0,
width: 6.0,
decoration: BoxDecoratiGiton(
shape: BoxShape.circle,
color: Color(0xFFFF8A21),
)github,
),
),
],
),
));
} else {
..flutter结构优缺点.数组词
}
...
}
}
  • 补全日历结束日期,每数组初始化个月毕竟一天若为周日,则无需补全,若为星期五则把下个月的前两天补在本月的星期六和周日:
    if ((daysInMonth + dayOffset) % 7 > 0) {
// 核算需求补多少天,直接从1开始就好
int addNum = 7 - ((daysI数组初始化nMonth + dayOffset) % 7);
for (int i = 1; i &lflutter值得学吗t;= addNum; i++) {
dayItems.add(Container(
margin: EdgeInsets.all(4.gitee0),
alignment: Alignment.center,
ch数组排序ild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(localizations.formatDecimal(i),
stylegitee: TextStyle(
fontSize: 14.0,
color: Cflutteredolor(0xFF888888),
fontWeight: FontWeighGitt.bold)),
Visibility(
visiblegit指令: falsgitlabe,
child:数组c言语 Container(
height数组: 6.0,
wiflutter怎样读音发音dth: 6.0,
decoration: BoxDecoration(
shape: BoxShape.circgithub中文官网网页le,
coflutter面试题lor: Color(0xFFFF8A21),
),
),
),
],
),
));
}
}
  1. 核算每个giti月从星期一开始展现能够展现几行,即核算日历高度,月份不同,高度不同,最少4行,最多6行,根据内容动态闪现不至于留很多空白
    // 核算一个月有多少天 
int daysInMonth = ChinaDateUtils.gegititDaysInMonth(
widget.initialDate.year, widget.initigithub永久回家地址alDate.month);
// 核算每个月第一天的星期
int daFlutteryOffset = ChinaDateUtils.fluttershyfirstDayOffsets(
widgetgithub.iflutter值得学吗nitialDate.year, widgiteeget.initia数组的界说lDate.month);
// 核算用多少行展现giti轮胎是什么品牌悉数日期
i数组c言语nt row = ((daysInMonth + dayOffset) / 7).ceil();

修改这些内容大约能够实现上述作用。
Demoflutter中文官网地址:ggit教程itee.com/masshub/sig…