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

76 lines
1.9 KiB

6 years ago
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/model/date_model.dart';
5 years ago
import 'package:flutter_custom_calendar/flutter_custom_calendar.dart';
import '../controller.dart';
6 years ago
/**
* 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
3 years ago
dateModel.isSelected!
6 years ago
? 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;
3 years ago
DrawDayWidget? drawDayWidget; //普通样式是必须的
6 years ago
CustomDayWidgetPainter(this.dateModel, {this.drawDayWidget});
3 years ago
Paint? textPaint;
6 years ago
@override
void paint(Canvas canvas, Size size) {
3 years ago
drawDayWidget!(dateModel, canvas, size);
6 years ago
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
/**
* widgetitem
*/
abstract class BaseCombineDayWidget extends StatelessWidget {
final DateModel dateModel;
6 years ago
BaseCombineDayWidget(this.dateModel);
@override
Widget build(BuildContext context) {
3 years ago
return dateModel.isSelected!
6 years ago
? getSelectedWidget(dateModel)
: getNormalWidget(dateModel);
}
Widget getNormalWidget(DateModel dateModel);
Widget getSelectedWidget(DateModel dateModel);
}