点击放大后锁定罗盘
This commit is contained in:
@ -1,18 +1,23 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:fengshui_compass/components/cross_paint.dart';
|
||||
import 'package:fengshui_compass/components/my_icon.dart';
|
||||
import 'package:fengshui_compass/pages/login_page.dart';
|
||||
import 'package:fengshui_compass/states/region.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_serial_port_api/flutter_serial_port_api.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
|
||||
import '../components/grid_clip_paint.dart';
|
||||
import '../components/region_selector.dart';
|
||||
import '../states/compass_image.dart';
|
||||
import '../utils/recv_parse.dart';
|
||||
@ -317,6 +322,9 @@ class _CompassState extends State<CompassPage> {
|
||||
return result;
|
||||
}
|
||||
|
||||
double _scale = 1.0; // 放大倍数
|
||||
Offset _origin = Offset(0.0, 0.0); // 放大原点
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@ -372,23 +380,30 @@ class _CompassState extends State<CompassPage> {
|
||||
width: 700,
|
||||
height: 700,
|
||||
child: Stack(
|
||||
// fit: StackFit.loose,
|
||||
children: [
|
||||
Transform.rotate(
|
||||
angle: getCorrectionAngle((myaw +
|
||||
regionProvider.declination)) *
|
||||
2 *
|
||||
pi /
|
||||
360,
|
||||
child: Image(
|
||||
width: 700,
|
||||
height: 700,
|
||||
// alignment: Alignment.lerp(a, b, t),
|
||||
// image: compassImageProvider.rotateImage,
|
||||
image: compassImageProvider
|
||||
.rotateImage ??
|
||||
const AssetImage(
|
||||
"assets/images/compass_rotated.png"),
|
||||
fit: BoxFit.contain),
|
||||
ClipRect(
|
||||
child: Transform.scale(
|
||||
scale: _scale,
|
||||
origin: _origin,
|
||||
child: Transform.rotate(
|
||||
angle: getCorrectionAngle((myaw +
|
||||
regionProvider.declination)) *
|
||||
2 *
|
||||
pi /
|
||||
360,
|
||||
child: ClipOval(
|
||||
child: Image(
|
||||
width: 700,
|
||||
height: 700,
|
||||
image: compassImageProvider
|
||||
.rotateImage ??
|
||||
const AssetImage(
|
||||
"assets/images/compass_rotated.png"),
|
||||
fit: BoxFit.contain),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: FractionalOffset(w_x, w_y),
|
||||
@ -403,35 +418,106 @@ class _CompassState extends State<CompassPage> {
|
||||
children: List.generate(
|
||||
9,
|
||||
(index) => Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom:
|
||||
const BorderSide(width: 1),
|
||||
right:
|
||||
const BorderSide(width: 1),
|
||||
left: index % 3 == 0
|
||||
? const BorderSide(width: 1)
|
||||
: BorderSide.none,
|
||||
top: index <= 2
|
||||
? const BorderSide(width: 1)
|
||||
: BorderSide.none),
|
||||
color: const Color.fromRGBO(
|
||||
233, 233, 233, 0.3)),
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border(
|
||||
// bottom:
|
||||
// const BorderSide(width: 1),
|
||||
// right:
|
||||
// const BorderSide(width: 1),
|
||||
// left: index % 3 == 0
|
||||
// ? const BorderSide(width: 1)
|
||||
// : BorderSide.none,
|
||||
// top: index <= 2
|
||||
// ? const BorderSide(width: 1)
|
||||
// : BorderSide.none),
|
||||
// color: const Color.fromRGBO(
|
||||
// 233, 233, 233, 0.3)),
|
||||
height: 700 / 3,
|
||||
width: 700 / 3,
|
||||
child: GestureDetector(
|
||||
child: Text('grid $index'),
|
||||
// child: Text('grid $index'),
|
||||
onDoubleTap: () {
|
||||
setState(() {
|
||||
_scale = 1.0;
|
||||
});
|
||||
},
|
||||
onTap: () {
|
||||
Fluttertoast.showToast(
|
||||
msg: 'index: $index',
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
fontSize: 20.0);
|
||||
if (isLock) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
switch (index) {
|
||||
case 0:
|
||||
_origin =
|
||||
const Offset(-350, -350);
|
||||
break;
|
||||
case 1:
|
||||
_origin =
|
||||
const Offset(0, -350);
|
||||
break;
|
||||
case 2:
|
||||
_origin =
|
||||
const Offset(350, -350);
|
||||
break;
|
||||
case 3:
|
||||
_origin =
|
||||
const Offset(-350, 0);
|
||||
break;
|
||||
case 4:
|
||||
_origin = const Offset(0, 0);
|
||||
break;
|
||||
case 5:
|
||||
_origin =
|
||||
const Offset(350, 0);
|
||||
break;
|
||||
case 6:
|
||||
_origin =
|
||||
const Offset(-350, 350);
|
||||
break;
|
||||
case 7:
|
||||
_origin =
|
||||
const Offset(0, 350);
|
||||
break;
|
||||
case 8:
|
||||
_origin =
|
||||
const Offset(350, 350);
|
||||
break;
|
||||
}
|
||||
_scale = 3;
|
||||
switchCompass();
|
||||
// isLock = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// ClipRRect(
|
||||
// borderRadius: BorderRadius.circular(225.0),
|
||||
// child: Image(
|
||||
// width: 700,
|
||||
// height: 700,
|
||||
// // alignment: Alignment.lerp(a, b, t),
|
||||
// // image: compassImageProvider.rotateImage,
|
||||
// image: compassImageProvider
|
||||
// .rotateImage ??
|
||||
// const AssetImage(
|
||||
// "assets/images/compass_rotated.png"),
|
||||
// fit: BoxFit.contain),
|
||||
// )
|
||||
ClipRect(
|
||||
child: Image(
|
||||
width: 700,
|
||||
height: 700,
|
||||
color: Colors.red,
|
||||
// alignment: Alignment.lerp(a, b, t),
|
||||
// image: compassImageProvider.rotateImage,
|
||||
image: const AssetImage(
|
||||
"assets/images/compass_rotated.png"),
|
||||
fit: BoxFit.contain),
|
||||
clipper: MyClipper(),
|
||||
)
|
||||
// GridClipPaint(0,0,1,2)
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -605,3 +691,11 @@ class _CompassState extends State<CompassPage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyClipper extends CustomClipper<Rect> {
|
||||
@override
|
||||
Rect getClip(Size size) => Rect.fromLTWH(0.0, 0.0, 100.0, 100.0);
|
||||
|
||||
@override
|
||||
bool shouldReclip(CustomClipper<Rect> oldClipper) => false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user