罗盘区域划分九宫格
This commit is contained in:
@ -8,8 +8,8 @@ import 'package:fengshui_compass/pages/login_page.dart';
|
||||
import 'package:fengshui_compass/states/region.dart';
|
||||
import 'package:flutter/material.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_provider/path_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
|
||||
@ -296,9 +296,25 @@ class _CompassState extends State<CompassPage> {
|
||||
});
|
||||
}
|
||||
|
||||
void initCompassImage() async {
|
||||
final directory =
|
||||
await getApplicationDocumentsDirectory(); // AppData directory
|
||||
double get radaw {
|
||||
return (myaw + Provider.of<RegionProvider>(context).declination) *
|
||||
2 *
|
||||
pi /
|
||||
360;
|
||||
}
|
||||
|
||||
double getCorrectionAngle(double angle) {
|
||||
double result;
|
||||
if (angle < 0) {
|
||||
result = angle + 360;
|
||||
} else if (angle >= 0 && angle < 180) {
|
||||
result = angle + 180;
|
||||
} else if (angle > 180) {
|
||||
result = angle - 180;
|
||||
} else {
|
||||
result = 0.0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -358,14 +374,15 @@ class _CompassState extends State<CompassPage> {
|
||||
child: Stack(
|
||||
children: [
|
||||
Transform.rotate(
|
||||
angle: (myaw + regionProvider.declination) *
|
||||
angle: getCorrectionAngle((myaw +
|
||||
regionProvider.declination)) *
|
||||
2 *
|
||||
pi /
|
||||
360,
|
||||
child: Image(
|
||||
width: 700,
|
||||
height: 700,
|
||||
// alignment: Alignment.bottomLeft,
|
||||
// alignment: Alignment.lerp(a, b, t),
|
||||
// image: compassImageProvider.rotateImage,
|
||||
image: compassImageProvider
|
||||
.rotateImage ??
|
||||
@ -381,6 +398,40 @@ class _CompassState extends State<CompassPage> {
|
||||
),
|
||||
),
|
||||
CrossPaint(),
|
||||
GridView.count(
|
||||
crossAxisCount: 3,
|
||||
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)),
|
||||
height: 700 / 3,
|
||||
width: 700 / 3,
|
||||
child: GestureDetector(
|
||||
child: Text('grid $index'),
|
||||
onTap: () {
|
||||
Fluttertoast.showToast(
|
||||
msg: 'index: $index',
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
fontSize: 20.0);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -402,7 +453,13 @@ class _CompassState extends State<CompassPage> {
|
||||
),
|
||||
Text(
|
||||
// "${azimuth.toStringAsFixed(2)}",
|
||||
(myaw + regionProvider.declination)
|
||||
// ((myaw + regionProvider.declination) < 0
|
||||
// ? 360 +
|
||||
// (myaw + regionProvider.declination)
|
||||
// : (myaw + regionProvider.declination))
|
||||
// .toStringAsFixed(2),
|
||||
getCorrectionAngle(
|
||||
myaw + regionProvider.declination)
|
||||
.toStringAsFixed(2),
|
||||
style: const TextStyle(
|
||||
color: Colors.amber, fontSize: 36),
|
||||
@ -412,27 +469,48 @@ class _CompassState extends State<CompassPage> {
|
||||
//磁偏角调整按钮
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 8,
|
||||
right: 6,
|
||||
child: IconButton(
|
||||
tooltip: '选择城市',
|
||||
iconSize: 30,
|
||||
onPressed: () => selectRegion(),
|
||||
icon: const Icon(Icons.settings, color: Colors.amber),
|
||||
)),
|
||||
Positioned(
|
||||
top: 5,
|
||||
left: 8,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
ImagePicker()
|
||||
.pickImage(source: ImageSource.gallery)
|
||||
.then((res) {
|
||||
if (res == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
compassImageProvider.setSelectedRotateImage(res);
|
||||
});
|
||||
},
|
||||
left: 6,
|
||||
child: PopupMenuButton(
|
||||
iconSize: 30,
|
||||
icon: const Icon(Icons.photo, color: Colors.amber),
|
||||
itemBuilder: (BuildContext context) => [
|
||||
PopupMenuItem(
|
||||
child: const ListTile(
|
||||
leading: Icon(Icons.photo_album_rounded),
|
||||
title: Text('选择新的罗盘图片'),
|
||||
),
|
||||
onTap: () {
|
||||
ImagePicker()
|
||||
.pickImage(source: ImageSource.gallery)
|
||||
.then((res) {
|
||||
if (res == null) {
|
||||
return;
|
||||
}
|
||||
compassImageProvider
|
||||
.setSelectedRotateImage(res);
|
||||
});
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
enabled: compassImageProvider.rotateImage != null,
|
||||
child: const ListTile(
|
||||
leading: Icon(Icons.delete_rounded),
|
||||
title: Text('恢复默认图片'),
|
||||
),
|
||||
onTap: () {
|
||||
compassImageProvider.resetRotateImage();
|
||||
},
|
||||
),
|
||||
],
|
||||
)),
|
||||
// 最下面一行,ranging value openlaser
|
||||
Positioned(
|
||||
@ -450,6 +528,7 @@ class _CompassState extends State<CompassPage> {
|
||||
height: 90,
|
||||
bottom: 60,
|
||||
child: Image(
|
||||
// alignment: ,
|
||||
image: AssetImage("assets/images/range_input.png"),
|
||||
fit: BoxFit.contain,
|
||||
)),
|
||||
|
Reference in New Issue
Block a user