更新flutter unit mac版本

This commit is contained in:
toly
2020-08-11 12:59:31 +08:00
parent 527fa566e9
commit e5251a694c
9 changed files with 328 additions and 1 deletions

Binary file not shown.

View File

@@ -0,0 +1,182 @@
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// create by 张风捷特烈 on 2020/7/22
/// contact me by email 1981462002@qq.com
/// 说明: 264 RepaintBoundary 重绘边界 为子组件创建一个单独的显示列表,提升性能。源码中在TextField、DrawerController、Scrollbar、Sliver等组件中均有应用。
// {
// "widgetId": 264,
// "name": "RepaintBoundary基本使用",
// "priority": 1,
// "subtitle": "【child】 : 子组件 【Widget】\n"
// "比如上面的绘制视图即使shouldRepaint为false,在滑动中会也会不断执行paint方法,使用RepaintBoundary可以避免不必要的绘制。",
// }
class RepaintBoundaryDemo extends StatelessWidget{
@override
Widget build(BuildContext context) {
return RepaintBoundary(
child: TempPlayBezier3Page(),
);
}
}
class TempPlayBezier3Page extends StatefulWidget {
@override
_TempPlayBezier3PageState createState() => _TempPlayBezier3PageState();
}
class _TempPlayBezier3PageState extends State<TempPlayBezier3Page> {
List<Offset> _pos = <Offset>[];
int selectPos;
@override
void initState() {
_initPoints();
super.initState();
}
void _initPoints() {
_pos = List<Offset>();
_pos.add(Offset(0, 0));
_pos.add(Offset(60, -60));
_pos.add(Offset(-90, -90));
_pos.add(Offset(-120, -40));
}
@override
Widget build(BuildContext context) {
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: CustomPaint(
painter: TempBezierPainter(pos: _pos, selectPos: selectPos),
),
);
}
}
class TempBezierPainter extends CustomPainter {
Paint _gridPaint;
Path _gridPath;
Paint _mainPaint;
Path _mainPath;
int selectPos;
Paint _helpPaint;
List<Offset> pos;
TempBezierPainter({this.pos, this.selectPos}) {
_gridPaint = Paint()..style = PaintingStyle.stroke;
_gridPath = Path();
_mainPaint = Paint()
..color = Colors.orange
..style = PaintingStyle.stroke
..strokeWidth = 2;
_mainPath = Path();
_helpPaint = Paint()
..color = Colors.purple
..style = PaintingStyle.stroke
..strokeWidth = 2
..strokeCap = StrokeCap.round;
}
@override
void paint(Canvas canvas, Size size) {
print('----------Paint-------');
canvas.clipRect(Offset.zero & size);
canvas.translate(size.width / 2, size.height / 2);
_drawGrid(canvas, size); //绘制格线
_drawAxis(canvas, size); //绘制轴线
_mainPath.moveTo(pos[0].dx, pos[0].dy);
_mainPath.cubicTo(
pos[1].dx, pos[1].dy, pos[2].dx, pos[2].dy, pos[3].dx, pos[3].dy);
canvas.drawPath(_mainPath, _mainPaint);
_drawHelp(canvas);
_drawSelectPos(canvas);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
void _drawGrid(Canvas canvas, Size size) {
_gridPaint
..color = Colors.grey
..strokeWidth = 0.5;
_gridPath = _buildGridPath(_gridPath, size);
canvas.drawPath(_buildGridPath(_gridPath, size), _gridPaint);
canvas.save();
canvas.scale(1, -1); //沿x轴镜像
canvas.drawPath(_gridPath, _gridPaint);
canvas.restore();
canvas.save();
canvas.scale(-1, 1); //沿y轴镜像
canvas.drawPath(_gridPath, _gridPaint);
canvas.restore();
canvas.save();
canvas.scale(-1, -1); //沿原点镜像
canvas.drawPath(_gridPath, _gridPaint);
canvas.restore();
}
void _drawAxis(Canvas canvas, Size size) {
canvas.drawPoints(
PointMode.lines,
[
Offset(-size.width / 2, 0),
Offset(size.width / 2, 0),
Offset(0, -size.height / 2),
Offset(0, size.height / 2),
Offset(0, size.height / 2),
Offset(0 - 7.0, size.height / 2 - 10),
Offset(0, size.height / 2),
Offset(0 + 7.0, size.height / 2 - 10),
Offset(size.width / 2, 0),
Offset(size.width / 2 - 10, 7),
Offset(size.width / 2, 0),
Offset(size.width / 2 - 10, -7),
],
_gridPaint
..color = Colors.blue
..strokeWidth = 1.5);
}
Path _buildGridPath(Path path, Size size, {step = 20.0}) {
for (int i = 0; i < size.height / 2 / step; i++) {
path.moveTo(0, step * i);
path.relativeLineTo(size.width / 2, 0);
}
for (int i = 0; i < size.width / 2 / step; i++) {
path.moveTo(step * i, 0);
path.relativeLineTo(
0,
size.height / 2,
);
}
return path;
}
void _drawHelp(Canvas canvas) {
canvas.drawPoints(PointMode.lines, pos, _helpPaint..strokeWidth = 1);
canvas.drawPoints(PointMode.points, pos, _helpPaint..strokeWidth = 8);
}
void _drawSelectPos(Canvas canvas) {
if (selectPos == null) return;
canvas.drawCircle(
pos[selectPos],
10,
_helpPaint
..color = Colors.green
..strokeWidth = 2);
}
}

View File

@@ -0,0 +1,68 @@
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:ui' as ui;
import 'node1_base.dart';
/// create by 张风捷特烈 on 2020/7/22
/// contact me by email 1981462002@qq.com
/// 说明:
// {
// "widgetId": 264,
// "name": "保存Widget成为图片",
// "priority": 2,
// "subtitle": "通过RenderRepaintBoundary可以获取子组件的Image信息从而获取字节保存为图片文件。",
// }
class RepaintBoundarySave extends StatelessWidget {
final GlobalKey _globalKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Stack(
children: [
RepaintBoundary(
key: _globalKey,
child: TempPlayBezier3Page(),
),
Positioned(right: -10, child: _buildButton3(context))
],
);
}
Widget _buildButton3(context) => MaterialButton(
child: Icon(
Icons.save_alt,
size: 15,
color: Colors.white,
),
color: Colors.green,
shape: CircleBorder(
side: BorderSide(width: 2.0, color: Color(0xFFFFDFDFDF)),
),
onPressed: () async {
var bits = await _widget2Image(_globalKey);
var dir = await getApplicationSupportDirectory();
var file = File(dir.path + "/save_img.png");
var f = await file.writeAsBytes(bits);
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
content: Text('保存成功后! 路径为:${f.path}'),
));
});
Future<Uint8List> _widget2Image(GlobalKey key) async {
RenderRepaintBoundary boundary = key.currentContext.findRenderObject();
//获得 ui.image
ui.Image img = await boundary.toImage();
//获取图片字节
var byteData = await img.toByteData(format: ui.ImageByteFormat.png);
Uint8List bits = byteData.buffer.asUint8List();
return bits;
}
}

View File

@@ -29,6 +29,8 @@ export '../SingleChildRenderObjectWidget/Align/node1_base.dart';
export '../SingleChildRenderObjectWidget/Align/node2_other.dart';
export '../SingleChildRenderObjectWidget/CustomSingleChildLayout/node1_base.dart';
export '../SingleChildRenderObjectWidget/CustomSingleChildLayout/node2_offset.dart';
export '../SingleChildRenderObjectWidget/RepaintBoundary/node1_base.dart';
export '../SingleChildRenderObjectWidget/RepaintBoundary/node2_save.dart';
export '../SingleChildRenderObjectWidget/ConstrainedBox/node1_base.dart';
export '../SingleChildRenderObjectWidget/FractionalTranslation/node1_base.dart';

View File

@@ -149,6 +149,11 @@ class WidgetsMap {
CustomVisibility(),
ReplacementVisibility(),
];
case "RepaintBoundary":
return [
RepaintBoundaryDemo(),
RepaintBoundarySave(),
];
case "Chip":
return [
CustomChip(),

View File

@@ -5,11 +5,13 @@
import FlutterMacOS
import Foundation
import path_provider_macos
import shared_preferences_macos
import sqflite
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))

View File

@@ -3,6 +3,9 @@ PODS:
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5)
- path_provider (0.0.1)
- path_provider_macos (0.0.1):
- FlutterMacOS
- shared_preferences (0.0.1)
- shared_preferences_macos (0.0.1):
- FlutterMacOS
@@ -15,6 +18,8 @@ PODS:
DEPENDENCIES:
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`)
- path_provider (from `Flutter/ephemeral/.symlinks/plugins/path_provider/macos`)
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
- shared_preferences (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences/macos`)
- shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`)
- sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/macos`)
@@ -28,6 +33,10 @@ SPEC REPOS:
EXTERNAL SOURCES:
FlutterMacOS:
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64
path_provider:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider/macos
path_provider_macos:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
shared_preferences:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences/macos
shared_preferences_macos:
@@ -42,6 +51,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
FlutterMacOS: 15bea8a44d2fa024068daa0140371c020b4b6ff9
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
path_provider: e0848572d1d38b9a7dd099e79cf83f5b7e2cde9f
path_provider_macos: a0a3fd666cb7cd0448e936fb4abad4052961002b
shared_preferences: 9fec34d1bd906196a4da48fcf6c3ad521cc00b8d
shared_preferences_macos: 5e5c2839894accb56b7d23328905b757f2bafaf6
sqflite: 6c1f07e1d4399d619ea619fea9171251dd24d058

View File

@@ -71,6 +71,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
file:
dependency: transitive
description:
name: file
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.2.1"
flutter:
dependency: "direct main"
description: flutter
@@ -135,6 +142,41 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.11"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.1+2"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.4+3"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
plugin_platform_interface:
dependency: transitive
description:
@@ -142,6 +184,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
process:
dependency: transitive
description:
name: process
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.13"
provider:
dependency: transitive
description:
@@ -308,6 +357,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.0"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.12.13+hotfix.4 <2.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"

View File

@@ -29,6 +29,7 @@ dependencies:
flutter_star: ^0.1.2 # 星星组件
shared_preferences: ^0.5.6+3 # xml 固化
url_launcher: ^5.4.2 # url
path_provider: ^1.6.11
intl: ^0.16.1 # 格式化
share: ^0.6.3+6
dev_dependencies: