You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
flutter_custom_calendar/lib/base_day_view.dart

74 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/controller.dart';
import 'package:flutter_custom_calendar/model/date_model.dart';
/**
* 通过canvas自定义item只需实现相关的方法就可以
*/
abstract class BaseCustomDayWidget extends StatelessWidget {
DateModel dateModel;
BaseCustomDayWidget(
this.dateModel,
);
@override
Widget build(BuildContext context) {
return Container(
child: new CustomPaint(
painter:
//根据isSelected标志获取对应的item
dateModel.isSelected
? new CustomDayWidgetPainter(dateModel,
drawDayWidget: drawSelected)
: new CustomDayWidgetPainter(dateModel,
drawDayWidget: drawNormal),
),
);
}
void drawNormal(DateModel dateModel, Canvas canvas, Size size);
void drawSelected(DateModel dateModel, Canvas canvas, Size size);
}
class CustomDayWidgetPainter extends CustomPainter {
DateModel dateModel;
DrawDayWidget drawDayWidget; //普通样式是必须的
CustomDayWidgetPainter(this.dateModel, {this.drawDayWidget});
Paint textPaint;
@override
void paint(Canvas canvas, Size size) {
drawDayWidget(dateModel, canvas, size);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
/**
* 通过组合widget创建item只需实现相关的方法就可以
*/
abstract class BaseCombineDayWidget extends StatelessWidget {
DateModel dateModel;
BaseCombineDayWidget(this.dateModel);
@override
Widget build(BuildContext context) {
return dateModel.isSelected
? getSelectedWidget(dateModel)
: getNormalWidget(dateModel);
}
Widget getNormalWidget(DateModel dateModel);
Widget getSelectedWidget(DateModel dateModel);
}