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/widget/base_day_view.dart

74 lines
1.8 KiB

6 years ago
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/controller.dart';
import 'package:flutter_custom_calendar/model/date_model.dart';
/**
* canvasitem
*/
abstract class BaseCustomDayWidget extends StatelessWidget {
final DateModel dateModel;
6 years ago
const BaseCustomDayWidget(
6 years ago
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;
}
}
/**
* widgetitem
*/
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);
}