罗盘区域划分九宫格
This commit is contained in:
@ -77,7 +77,7 @@
|
||||
var ml = res.lMonth;
|
||||
var dl = res.lDay;
|
||||
|
||||
var using_kook = (yearDz + timeDz + ml + dl + 2) % 9;
|
||||
var using_kook = (yearDz + timeDz + ml + dl + 3) % 9;
|
||||
|
||||
// 计算阴遁或阳遁
|
||||
// 阴盘局数:(年地支序数+农历月+农历日+时地支序数) mod 9
|
||||
|
43
lib/components/grid_clip_paint.dart
Normal file
43
lib/components/grid_clip_paint.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GridClipPaint extends StatelessWidget {
|
||||
const GridClipPaint({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
alignment: Alignment.center,
|
||||
child: CustomPaint(
|
||||
// 使用CustomPaint 背景画板
|
||||
painter: ClipPainter(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ClipPainter extends CustomPainter {
|
||||
ui.Image image;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
// 创建画笔
|
||||
final 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),
|
||||
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;
|
||||
}
|
@ -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,
|
||||
)),
|
||||
|
@ -16,19 +16,13 @@ class CompassImageProvider extends ChangeNotifier {
|
||||
|
||||
ImageProvider get rotateImage => _rotateImage;
|
||||
|
||||
// 加载罗盘图片
|
||||
// 加载罗盘图片
|
||||
void loadCompassImage() async {
|
||||
final prefs = await _prefs;
|
||||
final appDataDirectory = await getApplicationDocumentsDirectory();
|
||||
String pathString = prefs.getString('rotate_image');
|
||||
if (pathString != null) {
|
||||
File file = File(join(appDataDirectory.path, pathString));
|
||||
var isFileExist = await file.exists();
|
||||
if (isFileExist) {
|
||||
_rotateImage = FileImage(file);
|
||||
} else {
|
||||
_rotateImage = null;
|
||||
}
|
||||
File file = File(join(appDataDirectory.path, 'rotate_image'));
|
||||
bool isFileExist = await file.exists();
|
||||
if (isFileExist) {
|
||||
_rotateImage = FileImage(file);
|
||||
} else {
|
||||
_rotateImage = null;
|
||||
}
|
||||
@ -37,33 +31,30 @@ class CompassImageProvider extends ChangeNotifier {
|
||||
|
||||
void setSelectedRotateImage(XFile res) async {
|
||||
final appDataDirectory = await getApplicationDocumentsDirectory();
|
||||
print(res.path);
|
||||
String pathString = res.name;
|
||||
if (pathString == null) {
|
||||
return;
|
||||
}
|
||||
// imageCache.clear();
|
||||
// res.saveTo(join(appDataDirectory.path, res.name));
|
||||
res.saveTo(
|
||||
join(appDataDirectory.path, 'rotate_image${extension(res.name)}'));
|
||||
final prefs = await _prefs;
|
||||
// final appDataDirectory = await getApplicationDocumentsDirectory();
|
||||
|
||||
// File file = File(join(appDataDirectory.path, pathString));
|
||||
// File file =
|
||||
// File(join(appDataDirectory.path, 'rotate_image${extension(res.name)}'));
|
||||
res.saveTo(join(appDataDirectory.path, 'rotate_image'));
|
||||
File file = File(res.path);
|
||||
print(file);
|
||||
var isFileExist = await file.exists();
|
||||
print(isFileExist);
|
||||
if (isFileExist) {
|
||||
_rotateImage = FileImage(file);
|
||||
} else {
|
||||
_rotateImage = null;
|
||||
}
|
||||
prefs.setString('rotate_image', 'rotate_image${extension(res.name)}');
|
||||
// prefs.setString('rotate_image', pathString);
|
||||
// imageCache.clearLiveImages();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// 将罗盘图片重置为默认
|
||||
void resetRotateImage() async {
|
||||
final appDataDirectory = await getApplicationDocumentsDirectory();
|
||||
File file = File(join(appDataDirectory.path, 'rotate_image'));
|
||||
bool isFileExist = await file.exists();
|
||||
if (isFileExist) {
|
||||
file.delete();
|
||||
}
|
||||
_rotateImage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user