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/default_custom_day_view.dart

127 lines
3.7 KiB

6 years ago
import 'package:flutter/material.dart';
import 'package:flutter_custom_calendar/widget/base_day_view.dart';
6 years ago
import 'package:flutter_custom_calendar/model/date_model.dart';
import 'package:flutter_custom_calendar/style/style.dart';
/**
* StatelessWidgetstate
*/
class DefaultCustomDayWidget extends BaseCustomDayWidget {
DefaultCustomDayWidget(DateModel dateModel) : super(dateModel);
@override
void drawNormal(DateModel dateModel, Canvas canvas, Size size) {
defaultDrawNormal(dateModel, canvas, size);
}
@override
void drawSelected(DateModel dateModel, Canvas canvas, Size size) {
defaultDrawSelected(dateModel, canvas, size);
}
}
//class DefaultCustomDayWidget extends StatelessWidget {
// DateModel dateModel;
//
// DefaultCustomDayWidget(this.dateModel);
//
// @override
// Widget build(BuildContext context) {
// return Container(
// child: new CustomPaint(
// painter: CustomDayWidgetPainter(
// dateModel,
// ),
// ),
// );
// }
//}
//
//class CustomDayWidgetPainter extends CustomPainter {
// DateModel dateModel;
//
// drawNormal normalDraw; //普通样式是必须的
// drawSelected selectedDraw;
//
// CustomDayWidgetPainter(this.dateModel,
// {this.normalDraw = defaultDrawNormal,
// this.selectedDraw = defaultDrawSelected});
//
// Paint textPaint;
//
// @override
// void paint(Canvas canvas, Size size) {
//// print("paint:$size");
// if (dateModel.isSelected) {
// selectedDraw(dateModel, canvas, size);
// } else {
// normalDraw(dateModel, canvas, size);
// }
// }
//
// @override
// bool shouldRepaint(CustomPainter oldDelegate) {
// return true;
// }
//}
/**
*
*/
void defaultDrawNormal(DateModel dateModel, Canvas canvas, Size size) {
//顶部的文字
TextPainter dayTextPainter = new TextPainter()
..text =
TextSpan(text: dateModel.day.toString(), style: currentMonthTextStyle)
..textDirection = TextDirection.ltr
..textAlign = TextAlign.center;
dayTextPainter.layout(minWidth: size.width, maxWidth: size.width);
dayTextPainter.paint(canvas, Offset(0, 10));
//下面的文字
TextPainter lunarTextPainter = new TextPainter()
..text = new TextSpan(text: dateModel.lunarString, style: lunarTextStyle)
..textDirection = TextDirection.ltr
..textAlign = TextAlign.center;
lunarTextPainter.layout(minWidth: size.width, maxWidth: size.width);
lunarTextPainter.paint(canvas, Offset(0, size.height / 2));
}
/**
*
*/
void defaultDrawSelected(DateModel dateModel, Canvas canvas, Size size) {
//绘制背景
Paint backGroundPaint = new Paint()
..color = Colors.blue
..style = PaintingStyle.stroke
..strokeWidth = 2;
double padding = 8;
canvas.drawRect(
Rect.fromPoints(Offset(padding, padding),
Offset(size.width - padding, size.height - padding)),
backGroundPaint);
//顶部的文字
TextPainter dayTextPainter = new TextPainter()
..text =
TextSpan(text: dateModel.day.toString(), style: currentMonthTextStyle)
..textDirection = TextDirection.ltr
..textAlign = TextAlign.center;
dayTextPainter.layout(minWidth: size.width, maxWidth: size.width);
dayTextPainter.paint(canvas, Offset(0, 10));
//下面的文字
TextPainter lunarTextPainter = new TextPainter()
..text = new TextSpan(text: dateModel.lunarString, style: lunarTextStyle)
..textDirection = TextDirection.ltr
..textAlign = TextAlign.center;
lunarTextPainter.layout(minWidth: size.width, maxWidth: size.width);
lunarTextPainter.paint(canvas, Offset(0, size.height / 2));
}