点击放大后锁定罗盘
This commit is contained in:
@ -1,9 +1,76 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GridClipPaint extends StatelessWidget {
|
||||
const GridClipPaint({Key key}) : super(key: key);
|
||||
// class GridClipPaint extends StatelessWidget {
|
||||
// const GridClipPaint(
|
||||
// this.left,
|
||||
// this.top,
|
||||
// this.right,
|
||||
// this.bottom, {
|
||||
// Key key,
|
||||
// }) : super(key: key);
|
||||
//
|
||||
// // ui.Image image;
|
||||
// final double left;
|
||||
// final double top;
|
||||
// final double right;
|
||||
// final double bottom;
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// ui.Image image;
|
||||
// return Container(
|
||||
// color: Colors.transparent,
|
||||
// alignment: Alignment.center,
|
||||
// child: CustomPaint(
|
||||
// // 使用CustomPaint 背景画板
|
||||
// painter: ClipPainter(image),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
class GridClipPaint extends StatefulWidget {
|
||||
const GridClipPaint(this.image, this.left, this.top, this.right, this.bottom,
|
||||
{Key key})
|
||||
: super(key: key);
|
||||
final ui.Image image;
|
||||
final double left;
|
||||
final double top;
|
||||
final double right;
|
||||
final double bottom;
|
||||
|
||||
@override
|
||||
State<GridClipPaint> createState() => _GridClipPaintState();
|
||||
}
|
||||
|
||||
class _GridClipPaintState extends State<GridClipPaint> {
|
||||
ui.Image image;
|
||||
|
||||
@override
|
||||
void initState() async {
|
||||
// TODO: implement initState
|
||||
// final appDataDirectory = await getApplicationDocumentsDirectory();
|
||||
// File file = File(join(appDataDirectory.path, 'rotate_image'));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<ui.Image> imageLoader() {
|
||||
ImageStream imageStream = const AssetImage("assets/images/arrow.png")
|
||||
.resolve(ImageConfiguration(size: Size(700, 700)));
|
||||
Completer<ui.Image> imageCompleter = Completer<ui.Image>();
|
||||
|
||||
void imageListener(ImageInfo info, bool synchronousCall) {
|
||||
ui.Image image = info.image;
|
||||
imageCompleter.complete(image);
|
||||
imageStream.removeListener(ImageStreamListener(imageListener));
|
||||
}
|
||||
|
||||
imageStream.addListener(ImageStreamListener(imageListener));
|
||||
return imageCompleter.future;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -12,32 +79,37 @@ class GridClipPaint extends StatelessWidget {
|
||||
alignment: Alignment.center,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint 背景画板
|
||||
painter: ClipPainter(),
|
||||
painter: ClipPainter(image),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ClipPainter extends CustomPainter {
|
||||
ui.Image image;
|
||||
final ui.Image image;
|
||||
final double left;
|
||||
final double top;
|
||||
final double right;
|
||||
final double bottom;
|
||||
|
||||
ClipPainter(this.image,
|
||||
{this.left = 0.3, this.top = 0.3, this.right = 0.6, this.bottom = 0.6});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
// 创建画笔
|
||||
final Paint paint = Paint();
|
||||
// TODO: implement paint
|
||||
Paint paint = Paint();
|
||||
canvas.drawImageRect(
|
||||
image,
|
||||
// Image(image: AssetImage("assets/images/arrow.png")),
|
||||
Rect.fromLTRB(0, 0, 700 / 3, 700 / 3),
|
||||
Rect.fromLTWH(0, 0, 700 / 3, 700 / 3),
|
||||
Rect.fromLTRB(image.width * left, image.height * top,
|
||||
image.width * right, image.height * bottom),
|
||||
Rect.fromLTWH(0, 0, size.width, size.height),
|
||||
paint);
|
||||
// ..color = Colors.white
|
||||
// ..strokeWidth = 2;
|
||||
// 绘制线
|
||||
// canvas.drawLine(const Offset(-400, 0), const Offset(400, 0), paintLine);
|
||||
// canvas.drawLine(const Offset(0, 500), const Offset(0, -440), paintLine);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
||||
bool shouldRepaint(CustomPainter oldDelegate) {
|
||||
// TODO: implement shouldRepaint
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user