Commit 452f2bae55f2f24d33835ded3886ac58a7093192

Authored by wdn127929
1 parent c27c11c0

微信通知封面样式绘制 4种类型

... ... @@ -5020,23 +5020,7 @@ class InvicationPageState extends State<InvicationPage>
return date;
}
_getDsoltStrShow() {
String dsoltStr = '${ddateHm == null || ddateHm == '' ? '' : ddateHm}';
if (detailModel.liteStyle == '1') {
dsoltStr = detailModel.detailModelAllSunModel!.ddateSolt == '1'
? '早上'
: detailModel.detailModelAllSunModel!.ddateSolt == '2'
? '中午'
: '晚上';
} else if (detailModel.liteStyle == '3') {
dsoltStr = detailModel.detailModelAllSunModel!.ddateSolt == '1'
? '早餐'
: detailModel.detailModelAllSunModel!.ddateSolt == '2'
? '午餐'
: '晚餐';
}
return dsoltStr;
}
_createReserveDeposit() async {
if (detailModel.isShowNoticeDeposit == '1') {
... ... @@ -5074,8 +5058,11 @@ class InvicationPageState extends State<InvicationPage>
context,
widget.rid,
Provider.of<UserModel>(context, listen: false).user!.openid,
'${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
returnWeek(dateTime, context) + _getDsoltStrShow(),
// '${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
// returnWeek(dateTime, context) + _getDsoltStrShow(),
ddateHm??'',
dateTime,
detailModel.detailModelAllSunModel!.ddateSolt!,
detailModel.liteStyle,
detailModel.liteStyleTitle,
depositId: detailModel.depositId);
... ... @@ -5088,15 +5075,19 @@ class InvicationPageState extends State<InvicationPage>
} else {
// 不可编辑
//页面无预订订金选项
bool isSuccess = await Utils.goShareInvicationToWeChat(
context,
widget.rid,
Provider.of<UserModel>(context, listen: false).user!.openid,
'${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
returnWeek(dateTime, context) + _getDsoltStrShow(),
detailModel.liteStyle,
detailModel.liteStyleTitle,
depositId: detailModel.depositId);
bool isSuccess = await Utils.goShareInvicationToWeChat(
context,
widget.rid,
Provider.of<UserModel>(context, listen: false).user!.openid,
// '${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
// returnWeek(dateTime, context) + _getDsoltStrShow(),
ddateHm??'',
dateTime,
detailModel.detailModelAllSunModel!.ddateSolt!,
detailModel.liteStyle,
detailModel.liteStyleTitle,
depositId: detailModel.depositId);
print(isSuccess);
if (isSuccess) {
_addForward();
... ... @@ -5105,15 +5096,19 @@ class InvicationPageState extends State<InvicationPage>
} else {
// 不可编辑
//页面无预订订金选项
bool isSuccess = await Utils.goShareInvicationToWeChat(
context,
widget.rid,
Provider.of<UserModel>(context, listen: false).user!.openid,
'${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
returnWeek(dateTime, context) + _getDsoltStrShow(),
detailModel.liteStyle,
detailModel.liteStyleTitle,
depositId: detailModel.depositId);
bool isSuccess = await Utils.goShareInvicationToWeChat(
context,
widget.rid,
Provider.of<UserModel>(context, listen: false).user!.openid,
// '${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
// returnWeek(dateTime, context) + _getDsoltStrShow(),
ddateHm??'',
dateTime,
detailModel.detailModelAllSunModel!.ddateSolt!,
detailModel.liteStyle,
detailModel.liteStyleTitle,
depositId: detailModel.depositId);
print(isSuccess);
if (isSuccess) {
_addForward();
... ... @@ -5121,15 +5116,18 @@ class InvicationPageState extends State<InvicationPage>
}
} else {
//页面无预订订金选项
bool isSuccess = await Utils.goShareInvicationToWeChat(
context,
widget.rid,
Provider.of<UserModel>(context, listen: false).user!.openid,
'${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
returnWeek(dateTime, context) + _getDsoltStrShow(),
detailModel.liteStyle,
detailModel.liteStyleTitle,
depositId: detailModel.depositId);
bool isSuccess = await Utils.goShareInvicationToWeChat(
context,
widget.rid,
Provider.of<UserModel>(context, listen: false).user!.openid,
// '${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日',
// returnWeek(dateTime, context) + _getDsoltStrShow(),
ddateHm??'',
dateTime,
detailModel.detailModelAllSunModel!.ddateSolt!,
detailModel.liteStyle,
detailModel.liteStyleTitle,
depositId: detailModel.depositId);
print(isSuccess);
if (isSuccess) {
_addForward();
... ...
... ... @@ -152,7 +152,7 @@ class _MiniprogramSettingPageState extends State<MiniprogramSettingPage> {
right: w(20),
),
decoration: BoxDecoration(
color: MyColours.color_ffffff,
color: MyColours.color_ffffff,
borderRadius: BorderRadius.circular(r(10)),
border: Border.all(
width: w(1), color: MyColours.color_DBDBDB)),
... ... @@ -366,7 +366,7 @@ class _MiniprogramSettingPageState extends State<MiniprogramSettingPage> {
} else if (subType0 == '3') {
//3号模版
String month =
'${Utils.addZeroNumber(DateTime.now().month)}月${Utils.addZeroNumber(DateTime.now().day)}日 ';
'${Utils.addZeroNumber(DateTime.now().month)}/${Utils.addZeroNumber(DateTime.now().day)} ';
String week = returnWeek(DateTime.now(), context);
String hour = subType1 == '1' || subType1 == '3'
? (user!.noon != '00:00'
... ... @@ -498,7 +498,7 @@ class _MiniprogramSettingPageState extends State<MiniprogramSettingPage> {
} else {
//4号模版
String month =
'${Utils.addZeroNumber(DateTime.now().month)}/${Utils.addZeroNumber(DateTime.now().day)} ';
'${Utils.addZeroNumber(DateTime.now().month)}/${Utils.addZeroNumber(DateTime.now().day)}';
String week = returnWeek(DateTime.now(), context);
String hour = subType1 == '1' || subType1 == '3'
? (user!.noon != '00:00'
... ... @@ -512,7 +512,7 @@ class _MiniprogramSettingPageState extends State<MiniprogramSettingPage> {
? '中午'
: '';
if (section != '') {
if (section != '' && hour != '') {
hour = hour + ' ';
}
... ... @@ -539,15 +539,16 @@ class _MiniprogramSettingPageState extends State<MiniprogramSettingPage> {
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
Expanded(
child: Text(
'${Provider.of<UserModel>(context, listen: false).user!.sellername}',
textAlign: TextAlign.center,
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color: MyColours.color_FFEFC5,
fontSize: font(10)),
),
)),
Column(
crossAxisAlignment:
CrossAxisAlignment.end,
... ...
... ... @@ -56,17 +56,13 @@ import 'dart:typed_data';
typedef BookTimeSetCallback = void Function(bool needChange);
class Utils {
static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
if(imageBytes == null ){
return false;
static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
if (imageBytes == null) {
return false;
}
var fileSize = imageBytes.lengthInBytes;
return fileSize > 64 * 1024; // 64KB = 64 * 1024 bytes
}
var fileSize = imageBytes.lengthInBytes;
return fileSize > 64 * 1024; // 64KB = 64 * 1024 bytes
}
static List<CallLogEntry> removeDuplicates(List<CallLogEntry> items) {
List<CallLogEntry> uniqueItems = []; // uniqueList
... ... @@ -1459,8 +1455,10 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
Uint8List? result;
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
var model = new WeChatShareMiniProgramModel(
miniProgramType: Constant.wxMiniProgramType,
... ... @@ -1504,8 +1502,10 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
Uint8List? result;
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
var model = new WeChatShareMiniProgramModel(
// miniProgramType: , //体验版
... ... @@ -1596,9 +1596,11 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
Fluwx fluwx = Fluwx();
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
Uint8List? result;
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
var model = new WeChatShareMiniProgramModel(
miniProgramType: Constant.wxMiniProgramType,
... ... @@ -2028,8 +2030,10 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
Uint8List? result;
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
//跳转小程序
... ... @@ -2087,9 +2091,11 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
// Uint8List source = await testComporessList(context, _thumbnail);
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
Uint8List? result;
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
//跳转小程序
Fluwx fluwx = Fluwx();
... ... @@ -2192,8 +2198,10 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
Uint8List? result;
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
// print(result!.length/1024);
//跳转小程序
... ... @@ -2256,9 +2264,11 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
Fluwx fluwx = Fluwx();
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
Uint8List? result;
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
... ... @@ -2432,39 +2442,485 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
// Uint8List result = await testFromFileComporessList(context, pngBytes);
// return result;
// }
static String returnWeek(DateTime day, BuildContext context) {
String date = "周${Utils.formatWeekDayNum(day.weekday)} ";
static Future<Uint8List> canvas(
context, String _thumbnail, String month, String week) async {
return date;
}
static Future<Uint8List> canvas(context, String _thumbnail, DateTime date,
String liteStyle, String dsolt, String ddateHm) async {
var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
print(images);
// Paint _linePaint = new Paint()
// ..color = Colors.blue
// ..style = PaintingStyle.fill
// ..isAntiAlias = true
// ..strokeCap = StrokeCap.round
// ..strokeWidth = 500;
// Paint selfPaint = Paint()
// ..color = Colors.red
// ..style = PaintingStyle.fill
// ..isAntiAlias = true
// ..strokeCap = StrokeCap.butt
// ..strokeWidth = 2;
Paint paint = Paint()
..color = Color.fromRGBO(81, 81, 81, 0.4)
..style = PaintingStyle.fill;
final Paint paint = Paint();
canvas.drawImage(images, Offset.zero, paint); //绘制原始图片
List<String> subType = liteStyle.split('-');
// String subType0 = subType[0]; //几号模版
String subType1 = subType[1]; //模版下面的子样式
String month =
'${Utils.addZeroNumber(date.month)}月${Utils.addZeroNumber(date.day)}日 ';
String week = returnWeek(date, context);
String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm} ' : '';
String section = subType1 == '1' || subType1 == '4'
? _getDsoltStrShow(dsolt)
: subType1 == '2'
? _getDsoltStrShow(dsolt, isCan: false)
: '';
String time = month + week + hour + section;
paint.color = MyColours.color_99000000;
paint.style = PaintingStyle.fill;
if (Platform.isIOS) {
paint.style = PaintingStyle.fill;
}
// 定义源矩形,通常是图像的全部
// final Rect source = Rect.fromLTWH(
// 0.0, 0.0, images.width.toDouble(), images.height.toDouble());
// // 定义目标矩形,即画布的大小
// final Rect destination = Rect.fromLTWH(0.0, 0.0, w(210), w(168));
// // 绘制图像
canvas.drawRect(Rect.fromLTWH(0, 0, 500, 52), paint);
// canvas.drawImageRect(images, source, destination, paint);
// 定义源矩形,通常是图像的全部
// final Rect source2 = Rect.fromLTWH(
// 0.0, w(142), images.width.toDouble(), images.height.toDouble());
// // 定义目标矩形,即画布的大小
// final Rect destination2 = Rect.fromLTWH(0.0, 0.0, 500, 400);
// // 绘制图像
// canvas.drawImageRect(images, source2, destination2, paint);
if (Platform.isIOS) {
final paint1 = Paint()
..color = MyColours.color_99000000
..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
..style = PaintingStyle.fill;
// 绘制一个矩形作为蒙版
canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
}
// 绘制文字
ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
maxLines: 1,
ellipsis: '3',
fontSize: 24));
pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 24));
pb2.addText(
'${Provider.of<UserModel>(context, listen: false).user!.sellername}');
// 设置文本的宽度约束
ParagraphConstraints pc2 = ui.ParagraphConstraints(width: 500);
ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
canvas.drawParagraph(paragraph2, Offset(0, 12));
canvas.drawRect(Rect.fromLTWH(0, 348, 500, 52), paint);
// 绘制文字
ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 24));
pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 24));
pb.addText(time);
// 设置文本的宽度约束
ParagraphConstraints pc = ui.ParagraphConstraints(width: 500);
ui.Paragraph paragraph = pb.build()..layout(pc);
canvas.drawParagraph(paragraph, Offset(0, 360));
// 绘制文字
// ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
// textAlign: TextAlign.center,
// fontWeight: FontWeight.bold,
// fontStyle: FontStyle.normal,
// fontSize: 42));
// pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 42));
// pb3.addText(week);
// // 设置文本的宽度约束
// ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 500);
// ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
// canvas.drawParagraph(paragraph3, Offset(10, 230));
//下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
var picture =
await pictureRecorder.endRecording().toImage(500, 400); //设置生成图片的宽和高
var pngImageBytes =
(await picture.toByteData(format: ui.ImageByteFormat.png))!;
// var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
print(pngBytes); //pngBytes可以放在Image.memory()中预览
Uint8List result = await realComporessList(pngBytes); //压缩图片
return result;
}
static Future<Uint8List> canvas2(context, String _thumbnail, DateTime date,
String liteStyle, String dsolt, String ddateHm) async {
var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
print(images);
final Paint paint = Paint();
canvas.drawImage(images, Offset.zero, paint); //绘制原始图片
List<String> subType = liteStyle.split('-');
// String subType0 = subType[0]; //几号模版
String subType1 = subType[1]; //模版下面的子样式
String month =
'${Utils.addZeroNumber(date.month)}/${Utils.addZeroNumber(date.day)}';
String week = returnWeek(date, context);
String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm} ' : '';
String section = subType1 == '1' || subType1 == '4'
? _getDsoltStrShow(dsolt)
: subType1 == '2'
? _getDsoltStrShow(dsolt, isCan: false)
: '';
String time = week + hour + section;
paint.color = MyColours.color_99000000;
paint.style = PaintingStyle.fill;
if (Platform.isIOS) {
paint.style = PaintingStyle.fill;
}
// // 绘制图像
canvas.drawRect(Rect.fromLTWH(0, 0, 500, 400), paint);
if (Platform.isIOS) {
final paint1 = Paint()
..color = MyColours.color_99000000
..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
..style = PaintingStyle.fill;
// 绘制一个矩形作为蒙版
canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
}
// 绘制文字
ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
maxLines: 2,
fontStyle: FontStyle.normal,
fontSize: 24));
pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 24));
pb2.addText(
'${Provider.of<UserModel>(context, listen: false).user!.sellername}');
// 设置文本的宽度约束
ParagraphConstraints pc2 = ui.ParagraphConstraints(width: 500);
ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
canvas.drawParagraph(paragraph2, Offset(0, 86));
// 绘制文字
ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 48));
pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 48));
pb3.addText(month);
// 设置文本的宽度约束
ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 500);
ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
canvas.drawParagraph(paragraph3, Offset(0, 190));
// 绘制文字
ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 24));
pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 24));
pb.addText(time);
// 设置文本的宽度约束
ParagraphConstraints pc = ui.ParagraphConstraints(width: 500);
ui.Paragraph paragraph = pb.build()..layout(pc);
canvas.drawParagraph(paragraph, Offset(0, 270));
//下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
var picture =
await pictureRecorder.endRecording().toImage(500, 400); //设置生成图片的宽和高
var pngImageBytes =
(await picture.toByteData(format: ui.ImageByteFormat.png))!;
// var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
print(pngBytes); //pngBytes可以放在Image.memory()中预览
Uint8List result = await realComporessList(pngBytes); //压缩图片
return result;
}
static Future<Uint8List> canvas3(context, String _thumbnail, DateTime date,
String liteStyle, String dsolt, String ddateHm) async {
var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
print(images);
final Paint paint = Paint();
canvas.drawImage(images, Offset.zero, paint); //绘制原始图片
List<String> subType = liteStyle.split('-');
// String subType0 = subType[0]; //几号模版
String subType1 = subType[1]; //模版下面的子样式
String month =
'${Utils.addZeroNumber(date.month)}/${Utils.addZeroNumber(date.day)}';
String week = returnWeek(date, context);
String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm}' : '';
String section = subType1 == '1' || subType1 == '4'
? _getDsoltStrShow(dsolt)
: subType1 == '2'
? _getDsoltStrShow(dsolt, isCan: false)
: '';
if (hour != '') {
section = section + ' ';
}
String time = section + hour;
paint.color = MyColours.color_99000000;
paint.style = PaintingStyle.fill;
if (Platform.isIOS) {
paint.style = PaintingStyle.fill;
}
// // 绘制图像
canvas.drawRect(Rect.fromLTWH(0, 0, 500, 400), paint);
if (Platform.isIOS) {
final paint1 = Paint()
..color = MyColours.color_99000000
..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
..style = PaintingStyle.fill;
// 绘制一个矩形作为蒙版
canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
}
// 绘制文字
ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.left,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
maxLines: 2,
fontSize: 24));
pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 24));
pb2.addText(
'${Provider.of<UserModel>(context, listen: false).user!.sellername}');
// 设置文本的宽度约束
ParagraphConstraints pc2 = ui.ParagraphConstraints(width: 500);
ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
canvas.drawParagraph(paragraph2, Offset(35, 50));
// 绘制文字
ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 48));
pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 48));
pb3.addText(month);
// 设置文本的宽度约束
ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 170);
ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
canvas.drawParagraph(paragraph3, Offset(265, 250));
// 绘制文字
ui.ParagraphBuilder pb4 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
height: 1,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 20));
pb4.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 20));
pb4.addText(week);
// 设置文本的宽度约束
ParagraphConstraints pc4 = ui.ParagraphConstraints(width: 30);
ui.Paragraph paragraph4 = pb4.build()..layout(pc4);
canvas.drawParagraph(paragraph4, Offset(430, 264));
Rect rect = subType1 == '1'
? Rect.fromLTWH(315, 317, 140, 38)
: Rect.fromLTWH(387, 317, 67, 36);
paint.color = MyColours.color_66FFEFC5;
RRect rRect = RRect.fromRectAndRadius(rect, Radius.circular(6));
canvas.drawRRect(rRect, paint);
paint.color = MyColours.color_99000000;
// 绘制文字
ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 24));
pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 24));
pb.addText(time);
// 设置文本的宽度约束
double width = subType1 == '1' ? 200 : 100;
Offset offset = subType1 == '1' ? Offset(285, 320) : Offset(370, 320);
ParagraphConstraints pc = ui.ParagraphConstraints(width: width);
ui.Paragraph paragraph = pb.build()..layout(pc);
canvas.drawParagraph(paragraph, offset);
//下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
var picture =
await pictureRecorder.endRecording().toImage(500, 400); //设置生成图片的宽和高
var pngImageBytes =
(await picture.toByteData(format: ui.ImageByteFormat.png))!;
// var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
print(pngBytes); //pngBytes可以放在Image.memory()中预览
Uint8List result = await realComporessList(pngBytes); //压缩图片
return result;
}
static Future<Uint8List> canvas4(context, String _thumbnail, DateTime date,
String liteStyle, String dsolt, String ddateHm) async {
var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
print(images);
final Paint paint = Paint();
canvas.drawImage(images, Offset.zero, paint); //绘制原始图片
List<String> subType = liteStyle.split('-');
// String subType0 = subType[0]; //几号模版
String subType1 = subType[1]; //模版下面的子样式
String month =
'${Utils.addZeroNumber(date.month)}/${Utils.addZeroNumber(date.day)}';
String week = returnWeek(date, context);
String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm}' : '';
String section = subType1 == '1' || subType1 == '4'
? _getDsoltStrShow(dsolt)
: subType1 == '2'
? _getDsoltStrShow(dsolt, isCan: false)
: '';
if (section != ''&& hour != '') {
hour = hour + ' ';
}
String time = hour + section;
paint.color = MyColours.color_99000000;
paint.style = PaintingStyle.fill;
if (Platform.isIOS) {
paint = Paint()
// ..color = Colors.red
// ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
paint.style = PaintingStyle.fill;
}
// // 绘制图像
canvas.drawRect(Rect.fromLTWH(0, 300, 500, 100), paint);
if (Platform.isIOS) {
final paint1 = Paint()
..color = MyColours.color_99000000
..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
..style = PaintingStyle.fill;
// 绘制一个矩形作为蒙版
canvas.drawRect(Rect.fromLTWH(0, 300, 500, 100), paint1);
}
// 绘制文字
ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.left,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
maxLines: 1,
fontSize: 20));
pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 20));
pb2.addText(
'${Provider.of<UserModel>(context, listen: false).user!.sellername}');
// 设置文本的宽度约束
ParagraphConstraints pc2 = ui.ParagraphConstraints(width: 320);
ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
canvas.drawParagraph(paragraph2, Offset(20, 337));
// 绘制文字
ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 20));
pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 20));
pb3.addText(month);
// 设置文本的宽度约束
ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 80);
ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
canvas.drawParagraph(paragraph3, Offset(340, 320));
// 绘制文字
ui.ParagraphBuilder pb4 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
// height: 1,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 20));
pb4.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 20));
pb4.addText(week);
// 设置文本的宽度约束
ParagraphConstraints pc4 = ui.ParagraphConstraints(width: 50);
ui.Paragraph paragraph4 = pb4.build()..layout(pc4);
canvas.drawParagraph(paragraph4, Offset(420, 320));
Rect rect = Rect.fromLTWH(350, 351, 118, 30);
paint.color = MyColours.color_66FFEFC5;
RRect rRect = RRect.fromRectAndRadius(rect, Radius.circular(6));
canvas.drawRRect(rRect, paint);
paint.color = MyColours.color_99000000;
// 绘制文字
ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 20));
pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 20));
pb.addText(time);
// canvas.drawRect(Rect.fromLTWH(0, 0, 500, 400), paint);
// 设置文本的宽度约束
Offset offset = subType1 == '1' ? Offset(348, 353) : Offset(348, 353);
ParagraphConstraints pc = ui.ParagraphConstraints(width: 118);
ui.Paragraph paragraph = pb.build()..layout(pc);
canvas.drawParagraph(paragraph, offset);
//下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
var picture =
await pictureRecorder.endRecording().toImage(500, 400); //设置生成图片的宽和高
var pngImageBytes =
(await picture.toByteData(format: ui.ImageByteFormat.png))!;
// var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
print(pngBytes); //pngBytes可以放在Image.memory()中预览
// canvas.drawImage(images, Offset(0, 0), paint);
Uint8List result = await realComporessList(pngBytes); //压缩图片
return result;
}
static Future<Uint8List> canvasold(
context, String _thumbnail, String month, String week) async {
var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
print(images);
Paint paint = Paint()
..color = Color.fromRGBO(81, 81, 81, 0.4)
..style = PaintingStyle.fill;
if (Platform.isIOS) {
paint = Paint()..style = PaintingStyle.fill;
}
// 定义源矩形,通常是图像的全部
final Rect source = Rect.fromLTWH(
0.0, 0.0, images.width.toDouble(), images.height.toDouble());
... ... @@ -2472,31 +2928,19 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
final Rect destination = Rect.fromLTWH(0.0, 0.0, 500, 400);
// 绘制图像
canvas.drawImageRect(images, source, destination, paint);
if (Platform.isIOS) {
final paint1 = Paint()
..color = Colors.black.withOpacity(0.6)
..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
..style = PaintingStyle.fill;
// 绘制一个矩形作为蒙版
canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
}
// 在画布上绘制图片,使用BoxFit来适配画布大小
// canvas.drawImageRect(
// images,
// Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
// Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
// paint);
// 绘制文字
ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
textAlign: TextAlign.center,
fontWeight: FontWeight.normal,
fontStyle: FontStyle.normal,
// :MyColours.color_000000,
fontSize: 26));
pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 26));
pb2.addText(
... ... @@ -2512,8 +2956,6 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
// :MyColours.color_000000,
fontSize: 48));
pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 48));
pb.addText(month);
... ... @@ -2528,8 +2970,6 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
// :MyColours.color_000000,
fontSize: 42));
pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 42));
pb3.addText(week);
... ... @@ -2540,19 +2980,16 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
canvas.drawParagraph(paragraph3, Offset(10, 230));
//下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
var picture =
await pictureRecorder.endRecording().toImage(500, 400); //设置生成图片的宽和高
var picture = await pictureRecorder
.endRecording()
.toImage(w(210).toInt(), w(168).toInt()); //设置生成图片的宽和高
var pngImageBytes =
(await picture.toByteData(format: ui.ImageByteFormat.png))!;
// var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
print(pngBytes); //pngBytes可以放在Image.memory()中预览
// setState(() {
// imageMemory = pngBytes;
// Uint8List result = await resizeImage(pngBytes); //重置图片尺寸
Uint8List result = await realComporessList(pngBytes); //压缩图片
// Uint8List result = await testFromFileComporessList(context, pngBytes,needResize: true);
return result;
}
... ... @@ -2605,13 +3042,13 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
late Uint8List _thumbnailUint8List;
print(size(_thumbnail.length));
if (liteStyle != '0') {
_thumbnailUint8List = await canvas(
context,
sellerImage == null || sellerImage == ''
? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
: sellerImage,
month,
week);
// _thumbnailUint8List = await canvas(
// context,
// sellerImage == null || sellerImage == ''
// ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
// : sellerImage,
// month,
// week);
}
String _title =
"您预订的${Provider.of<UserModel>(context, listen: false).user!.sellername},已经安排,点击查看详情";
... ... @@ -2643,23 +3080,26 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
}
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
}
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
miniProgramType: Constant.wxMiniProgramType, //
// miniProgramType: WXMiniProgramType.RELEASE, //正式版
// miniProgramType: //开发版
// thumbnail: WeChatImage.binary(source)
// thumbnail: WeChatImage.network(_thumbnail)
thumbData: liteStyle == '0' ? result : _thumbnailUint8List);
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
miniProgramType: Constant.wxMiniProgramType, //
// miniProgramType: WXMiniProgramType.RELEASE, //正式版
// miniProgramType: //开发版
// thumbnail: WeChatImage.binary(source)
// thumbnail: WeChatImage.network(_thumbnail)
// thumbData: liteStyle == '0' ? result : _thumbnailUint8List
);
isSuccess = await fluwx.share(model);
} else {
... ... @@ -2702,13 +3142,32 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
return isSuccess;
}
static _getDsoltStrShow(String ddateSolt, {bool isCan = true}) {
String dsoltStr = '';
if (!isCan) {
dsoltStr = ddateSolt == '1'
? '早上'
: ddateSolt == '2'
? '中午'
: '晚上';
} else {
dsoltStr = ddateSolt == '1'
? '早餐'
: ddateSolt == '2'
? '午餐'
: '晚餐';
}
return dsoltStr;
}
//分享邀请函
static goShareInvicationToWeChat(
BuildContext context,
String rid,
String? uid,
String month,
String week,
String ddateHm,
DateTime dateTime,
String ddateSolt,
String? liteStyle,
String? liteStyleTitle,
{bool isWechat = true,
... ... @@ -2725,14 +3184,55 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
: sellerImage;
late Uint8List _thumbnailUint8List;
print(size(_thumbnail.length));
String dsoltStr = '${ddateHm == null || ddateHm == '' ? '' : ddateHm}';
// dsoltStr = _getDsoltStrShow(liteStyle!, ddateSolt);
if (liteStyle != '0') {
_thumbnailUint8List = await canvas(
context,
sellerImage == null || sellerImage == ''
? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
: sellerImage,
month,
week);
//画图
// 4种情况的图分别画出来
List<String> subType = liteStyle!.split('-');
String subType0 = subType[0]; //几号模版
if (subType0 == '1') {
_thumbnailUint8List = await canvas(
context,
sellerImage == null || sellerImage == ''
? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
: sellerImage,
dateTime,
liteStyle,
ddateSolt,
ddateHm);
} else if (subType0 == '2') {
_thumbnailUint8List = await canvas2(
context,
sellerImage == null || sellerImage == ''
? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
: sellerImage,
dateTime,
liteStyle,
ddateSolt,
ddateHm);
} else if (subType0 == '3') {
_thumbnailUint8List = await canvas3(
context,
sellerImage == null || sellerImage == ''
? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
: sellerImage,
dateTime,
liteStyle,
ddateSolt,
ddateHm);
} else {
_thumbnailUint8List = await canvas4(
context,
sellerImage == null || sellerImage == ''
? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
: sellerImage,
dateTime,
liteStyle,
ddateSolt,
ddateHm);
}
}
String _title = liteStyleTitle ??
"您预订的${Provider.of<UserModel>(context, listen: false).user!.sellername},已经安排,点击查看详情";
... ... @@ -2759,14 +3259,16 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
"pages/customer/detail_owner_invitation_new?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid&paymentId=$depositId";
}
Fluwx fluwx = Fluwx();
Uint8List? result;
Uint8List? result;
if (liteStyle == '0') {
Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
if (pngByte != null && await isImageLargerThan64KB(pngByte)) {
Uint8List? resultnew= await realComporessList(pngByte); //压缩图片
result=resultnew ==null ? null : await compressImage(resultnew,mb:64/1024);
}
Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
result = resultnew == null
? null
: await compressImage(resultnew, mb: 64 / 1024);
}
}
// print(_thumbnailUint8List.length/1024);
var model = new WeChatShareMiniProgramModel(
... ... @@ -2780,9 +3282,7 @@ static Future<bool> isImageLargerThan64KB(Uint8List? imageBytes) async {
// miniProgramType: //开发版
// thumbnail: WeChatImage.binary(source)
// thumbnail: WeChatImage.network(_thumbnail)
thumbData: liteStyle == '0'
? result
: _thumbnailUint8List);
thumbData: liteStyle == '0' ? result : _thumbnailUint8List);
// thumbData: );
... ...