diff --git a/assets/images/compass_rotated.png b/assets/images/compass_rotated.png new file mode 100644 index 0000000..6ad1020 Binary files /dev/null and b/assets/images/compass_rotated.png differ diff --git a/lib/components/cross_paint.dart b/lib/components/cross_paint.dart index 27c9cd3..5123c8a 100644 --- a/lib/components/cross_paint.dart +++ b/lib/components/cross_paint.dart @@ -19,11 +19,11 @@ class MyPainter extends CustomPainter { void paint(Canvas canvas, Size size) { // 创建画笔 final Paint paintLine = Paint() - ..color = Colors.grey + ..color = Colors.white ..strokeWidth = 2; // 绘制线 - canvas.drawLine(Offset(-400, 0), Offset(400, 0), paintLine); - canvas.drawLine(Offset(0, 500), Offset(0, -440), paintLine); + canvas.drawLine(const Offset(-400, 0), const Offset(400, 0), paintLine); + canvas.drawLine(const Offset(0, 500), const Offset(0, -440), paintLine); // 创建画笔 // final Paint paintPoint = Paint()..color = Colors.red; // 绘制圆点 diff --git a/lib/components/region_selector.dart b/lib/components/region_selector.dart index 6069565..2b5c852 100644 --- a/lib/components/region_selector.dart +++ b/lib/components/region_selector.dart @@ -12,7 +12,6 @@ class RegionSelector extends StatelessWidget { if (pname == '') return '未选择城市'; StringBuffer sb = StringBuffer(); sb.write(pname); - // if (cname == '') return sb.toString(); if (cname == '') return '未选择城市'; sb.write(' - '); sb.write(cname); @@ -31,8 +30,8 @@ class RegionSelector extends StatelessWidget { onTap: () { Pickers.showAddressPicker(context, addAllItem: false, - initProvince: regionProvider.provinceName, - initCity: regionProvider.cityName, + initProvince: regionProvider.tempProvinceName, + initCity: regionProvider.tempCityName, onConfirm: (p, c, t) { regionProvider.updateRegion(p, c); }); diff --git a/lib/pages/birthcal_page.dart b/lib/pages/birthcal_page.dart index 2cdb897..1f5f0e2 100644 --- a/lib/pages/birthcal_page.dart +++ b/lib/pages/birthcal_page.dart @@ -1,10 +1,12 @@ import 'dart:convert'; +import 'package:fengshui_compass/components/my_icon.dart'; import 'package:fengshui_compass/models/et_date.dart'; import 'package:fengshui_compass/pages/pan_page.dart'; import 'package:flutter/material.dart'; -import 'package:fengshui_compass/components/my_icon.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_pickers/pickers.dart'; +import 'package:flutter_pickers/time_picker/model/date_mode.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -96,6 +98,29 @@ class _BirthCalState extends State { }); } + _showDateTimePicker() { + Pickers.showDatePicker(context, mode: DateMode.YMDHMS, onConfirm: (p) { + setState(() { + hour = p.hour; + minute = p.minute; + if (isLunar) { + lunar_year = p.year; + lunar_month = p.month; + lunar_day = p.day; + + _controllerDate.text = + "${lunar_year}年${lunar_month}月${lunar_day}日 $hour时$minute分"; + } else { + year = p.year; + month = p.month; + day = p.day; + + _controllerDate.text = "${year}年${month}月${day}日 $hour时$minute分"; + } + }); + }); + } + // 通过公历算农历 calLunar() { if (_controllerWebView != null) { @@ -150,10 +175,10 @@ class _BirthCalState extends State { calPan() { if (_controllerWebView != null) { - if(qmType == 0) { + if (qmType == 0) { _controllerWebView .runJavascriptReturningResult( - "flutterCallPaiPan($year, $month, $day, $hour, $minute)") + "flutterCallPaiPan($year, $month, $day, $hour, $minute)") .then((value) { String tmp = value .replaceAll(r'\"', '"') @@ -166,24 +191,24 @@ class _BirthCalState extends State { MaterialPageRoute( builder: (context) => PanPage( solarDate: EtDate( - cYear: year, - cMonth: month, - cDay: day, - lYear: lunar_year, - lMonth: lunar_month, - lDay: lunar_day, - hour: hour, - minute: minute) + cYear: year, + cMonth: month, + cDay: day, + lYear: lunar_year, + lMonth: lunar_month, + lDay: lunar_day, + hour: hour, + minute: minute) .getSolar(), lunarDate: EtDate( - cYear: year, - cMonth: month, - cDay: day, - lYear: lunar_year, - lMonth: lunar_month, - lDay: lunar_day, - hour: hour, - minute: minute) + cYear: year, + cMonth: month, + cDay: day, + lYear: lunar_year, + lMonth: lunar_month, + lDay: lunar_day, + hour: hour, + minute: minute) .getLunar(), jieqi: qm.jieqi, dunju: qm.dunju, @@ -191,13 +216,12 @@ class _BirthCalState extends State { zhishi: qm.zhishi, zhifu: qm.zhifu, kong: qm.kong, - qimenResult: qm.qimenResult - ))); + qimenResult: qm.qimenResult))); }); } else if (qmType == 1) { _controllerWebView .runJavascriptReturningResult( - "flutterCallYinPan($year, $month, $day, $hour, $minute)") + "flutterCallYinPan($year, $month, $day, $hour, $minute)") .then((value) { String tmp = value .replaceAll(r'\"', '"') @@ -210,24 +234,24 @@ class _BirthCalState extends State { MaterialPageRoute( builder: (context) => PanPage( solarDate: EtDate( - cYear: year, - cMonth: month, - cDay: day, - lYear: lunar_year, - lMonth: lunar_month, - lDay: lunar_day, - hour: hour, - minute: minute) + cYear: year, + cMonth: month, + cDay: day, + lYear: lunar_year, + lMonth: lunar_month, + lDay: lunar_day, + hour: hour, + minute: minute) .getSolar(), lunarDate: EtDate( - cYear: year, - cMonth: month, - cDay: day, - lYear: lunar_year, - lMonth: lunar_month, - lDay: lunar_day, - hour: hour, - minute: minute) + cYear: year, + cMonth: month, + cDay: day, + lYear: lunar_year, + lMonth: lunar_month, + lDay: lunar_day, + hour: hour, + minute: minute) .getLunar(), jieqi: qm.jieqi, dunju: qm.dunju, @@ -235,13 +259,12 @@ class _BirthCalState extends State { zhishi: qm.zhishi, zhifu: qm.zhifu, kong: qm.kong, - qimenResult: qm.qimenResult - ))); + qimenResult: qm.qimenResult))); }); } else { _controllerWebView .runJavascriptReturningResult( - "flutterCallPaiPan($year, $month, $day, $hour, $minute)") + "flutterCallPaiPan($year, $month, $day, $hour, $minute)") .then((value) { String tmp = value .replaceAll(r'\"', '"') @@ -254,24 +277,24 @@ class _BirthCalState extends State { MaterialPageRoute( builder: (context) => PanPage( solarDate: EtDate( - cYear: year, - cMonth: month, - cDay: day, - lYear: lunar_year, - lMonth: lunar_month, - lDay: lunar_day, - hour: hour, - minute: minute) + cYear: year, + cMonth: month, + cDay: day, + lYear: lunar_year, + lMonth: lunar_month, + lDay: lunar_day, + hour: hour, + minute: minute) .getSolar(), lunarDate: EtDate( - cYear: year, - cMonth: month, - cDay: day, - lYear: lunar_year, - lMonth: lunar_month, - lDay: lunar_day, - hour: hour, - minute: minute) + cYear: year, + cMonth: month, + cDay: day, + lYear: lunar_year, + lMonth: lunar_month, + lDay: lunar_day, + hour: hour, + minute: minute) .getLunar(), jieqi: qm.jieqi, dunju: qm.dunju, @@ -279,8 +302,7 @@ class _BirthCalState extends State { zhishi: qm.zhishi, zhifu: qm.zhifu, kong: qm.kong, - qimenResult: qm.qimenResult - ))); + qimenResult: qm.qimenResult))); }); } } @@ -357,7 +379,7 @@ class _BirthCalState extends State { lunar_day = json.decode(tmp)['lDay']; _controllerDate.text = - "${year}年${month}月${day}日"; + "${year}年${month}月${day}日 $hour时$minute分"; }); }); } @@ -410,7 +432,7 @@ class _BirthCalState extends State { day = json.decode(tmp)['cDay']; _controllerDate.text = - "${lunar_year}年${lunar_month}月${lunar_day}日"; + "${lunar_year}年${lunar_month}月${lunar_day}日 $hour时$minute分"; }); }); } @@ -434,7 +456,7 @@ class _BirthCalState extends State { )) ], ), - const Padding(padding: EdgeInsets.only(top: 40)), + const Padding(padding: EdgeInsets.only(top: 80)), Row( children: [ const Padding( @@ -455,64 +477,73 @@ class _BirthCalState extends State { readOnly: true, )), IconButton( - onPressed: _showDatePicker, + // onPressed: _showDatePicker, + onPressed: _showDateTimePicker, icon: Icon(MyIcons.icon_rili)) ], ), - const Padding(padding: EdgeInsets.only(top: 40)), + // const Padding(padding: EdgeInsets.only(top: 40)), + // Row( + // children: [ + // const Padding( + // padding: EdgeInsets.only( + // left: 10, + // right: 10, + // ), + // child: Text( + // "出生时间:", + // style: TextStyle(fontSize: 18), + // ), + // ), + // Expanded( + // child: TextField( + // controller: _controllerTime, + // decoration: InputDecoration( + // contentPadding: const EdgeInsets.all(10.0), + // border: OutlineInputBorder( + // borderRadius: BorderRadius.circular(10.0), + // )), + // readOnly: true, + // )), + // IconButton( + // onPressed: _showTimePicker, + // icon: Icon(Icons.timelapse_outlined)) + // ], + // ), + Padding(padding: EdgeInsets.only(top: 80)), + // 切换奇门类型,单选框 Row( children: [ - const Padding( - padding: EdgeInsets.only( - left: 10, - right: 10, - ), - child: Text( - "出生时间:", - style: TextStyle(fontSize: 18), - ), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Radio( + value: 0, + groupValue: qmType, + onChanged: (v) { + setState(() { + qmType = v; + }); + }), + const Text("拆补法") + ], ), - Expanded( - child: TextField( - controller: _controllerTime, - decoration: InputDecoration( - contentPadding: const EdgeInsets.all(10.0), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10.0), - )), - readOnly: true, - )), - IconButton( - onPressed: _showTimePicker, - icon: Icon(Icons.timelapse_outlined)) + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Radio( + value: 1, + groupValue: qmType, + onChanged: (v) { + setState(() { + qmType = v; + }); + }), + const Text("阴盘") + ], + ) ], ), - Padding(padding: EdgeInsets.only(top: 40)), - // 切换奇门类型,单选框 - Row(children: [ - Row( - mainAxisSize: MainAxisSize.min, - children: [ - Radio(value: 0, groupValue: qmType, onChanged: (v){ - setState(() { - qmType = v; - }); - }), - const Text("拆补法") - ], - ), - Row( - mainAxisSize: MainAxisSize.min, - children: [ - Radio(value: 1, groupValue: qmType, onChanged: (v){ - setState(() { - qmType = v; - }); - }), - const Text("阴盘") - ], - ) - ],), Row( mainAxisSize: MainAxisSize.min, children: [ diff --git a/lib/pages/compass_page.dart b/lib/pages/compass_page.dart index 1653268..4a1daba 100644 --- a/lib/pages/compass_page.dart +++ b/lib/pages/compass_page.dart @@ -327,152 +327,167 @@ class _CompassState extends State { body: SafeArea( child: ConstrainedBox( constraints: const BoxConstraints(minHeight: 600), - child: Stack( - alignment: Alignment.center, - children: [ - // 罗盘 - Column( + child: Consumer( + builder: (builder, regionProvider, child) { + return Stack( + alignment: Alignment.center, children: [ - const Padding(padding: EdgeInsets.only(top: 145)), - Row( + // 罗盘 + Column( children: [ - Spacer(flex: 1), - Container( - width: 700, - height: 700, - child: Stack( - children: [ - Transform.rotate( - angle: myaw * pi / 360, - child: const Image( - image: - AssetImage("assets/images/compass.png"), - fit: BoxFit.fill), + const Padding(padding: EdgeInsets.only(top: 145)), + Row( + children: [ + Spacer(flex: 1), + Container( + width: 700, + height: 700, + child: Stack( + children: [ + Transform.rotate( + angle: myaw * pi / 360 + + regionProvider.declination, + child: const Image( + image: AssetImage( + "assets/images/compass_rotated.png"), + fit: BoxFit.fill), + ), + Align( + alignment: FractionalOffset(w_x, w_y), + child: const Image( + image: + AssetImage("assets/images/water.png"), + ), + ), + CrossPaint(), + ], ), - Align( - alignment: FractionalOffset(w_x, w_y), - child: const Image( - image: AssetImage("assets/images/water.png"), - ), - ), - CrossPaint(), - ], - ), - ), - const Spacer(flex: 1), + ), + const Spacer(flex: 1), + ], + ) ], + ), + // 最上面一行, lock azimuth login + Positioned( + top: 5, + child: Column( + children: [ + const Image( + width: 15, + height: 15, + image: AssetImage("assets/images/arrow.png"), + fit: BoxFit.contain, + ), + Text( + // "${azimuth.toStringAsFixed(2)}", + (myaw + regionProvider.declination) + .toStringAsFixed(2), + style: const TextStyle( + color: Colors.amber, fontSize: 36), + ), + ], + )), + //磁偏角调整按钮 + Positioned( + top: 5, + right: 8, + child: IconButton( + onPressed: () => selectRegion(), + icon: const Icon(Icons.settings, color: Colors.amber), + )), + Positioned( + top: 45, + right: 8, + child: IconButton( + onPressed: () => selectRegion(), + icon: const Icon(Icons.photo, color: Colors.amber), + )), + // 最下面一行,ranging value openlaser + Positioned( + bottom: 80, + left: 50, + child: IconButton( + onPressed: raging, + icon: const Icon( + MyIcons.icon_celiang, + size: 34, + ), + color: Colors.amber)), + const Positioned( + width: 180, + height: 90, + bottom: 60, + child: Image( + image: AssetImage("assets/images/range_input.png"), + fit: BoxFit.contain, + )), + Positioned( + width: 180, + height: 90, + bottom: 60, + child: Align( + alignment: Alignment.centerRight, + child: Padding( + padding: const EdgeInsets.only(right: 15), + child: Text( + "${distance} m", + style: const TextStyle( + color: Colors.amber, fontSize: 28), + ), + ), + )), + + Positioned( + bottom: 60, + right: 40, + height: 120, + width: 100, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + IconButton( + color: Colors.amber, + onPressed: () { + if (isUpClose) { + openUpLaser(); + } else { + closeUpLaser(); + } + setState(() { + isUpClose = !isUpClose; + }); + }, + icon: Icon( + isUpClose + ? MyIcons.icon_shangdeng + : MyIcons.icon_shangdnegguanbi, + size: 36)), + IconButton( + color: Colors.amber, + onPressed: () { + if (isSideClose) { + openSideLaser(); + } else { + closeSideLaser(); + } + setState(() { + isSideClose = !isSideClose; + }); + }, + icon: Icon( + isSideClose + ? MyIcons.icon_zuoyoudneg + : MyIcons.icon_zuoyoudengguanbi, + size: 32, + )) + ], + ), ) ], - ), - // 最上面一行, lock azimuth login - Positioned( - top: 5, - child: Column( - children: [ - const Image( - width: 15, - height: 15, - image: AssetImage("assets/images/arrow.png"), - fit: BoxFit.contain, - ), - Text( - // "${azimuth.toStringAsFixed(2)}", - myaw.toStringAsFixed(2), - style: - const TextStyle(color: Colors.amber, fontSize: 36), - ), - ], - )), - Positioned( - top: 5, - right: 8, - child: IconButton( - onPressed: () => selectRegion(), - icon: const Icon(Icons.settings, color: Colors.amber), - )), - // 最下面一行,ranging value openlaser - Positioned( - bottom: 80, - left: 50, - child: IconButton( - onPressed: raging, - icon: const Icon( - MyIcons.icon_celiang, - size: 34, - ), - color: Colors.amber)), - const Positioned( - width: 180, - height: 90, - bottom: 60, - child: Image( - image: AssetImage("assets/images/range_input.png"), - fit: BoxFit.contain, - )), - Positioned( - width: 180, - height: 90, - bottom: 60, - child: Align( - alignment: Alignment.centerRight, - child: Padding( - padding: const EdgeInsets.only(right: 15), - child: Text( - "${distance} m", - style: - const TextStyle(color: Colors.amber, fontSize: 28), - ), - ), - )), - - Positioned( - bottom: 60, - right: 40, - height: 120, - width: 100, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - IconButton( - color: Colors.amber, - onPressed: () { - if (isUpClose) { - openUpLaser(); - } else { - closeUpLaser(); - } - setState(() { - isUpClose = !isUpClose; - }); - }, - icon: Icon( - isUpClose - ? MyIcons.icon_shangdeng - : MyIcons.icon_shangdnegguanbi, - size: 36)), - IconButton( - color: Colors.amber, - onPressed: () { - if (isSideClose) { - openSideLaser(); - } else { - closeSideLaser(); - } - setState(() { - isSideClose = !isSideClose; - }); - }, - icon: Icon( - isSideClose - ? MyIcons.icon_zuoyoudneg - : MyIcons.icon_zuoyoudengguanbi, - size: 32, - )) - ], - ), - ) - ], + ); + }, ), )), ), diff --git a/lib/pages/personal_login_page.dart b/lib/pages/personal_login_page.dart index 698b04d..29daea8 100644 --- a/lib/pages/personal_login_page.dart +++ b/lib/pages/personal_login_page.dart @@ -4,7 +4,6 @@ import 'package:provider/provider.dart'; import '../bottom_navigation_widget.dart'; import '../states/token.dart'; -import '../utils/token_helper.dart'; // 用户未登录页面 class PersonalLoginPage extends StatefulWidget { @@ -17,7 +16,7 @@ class PersonalLoginPage extends StatefulWidget { class _PersonalLoginPageState extends State { @override Widget build(BuildContext context) { - bool isLogin = TokenHelper.getInstance.isLogin; + // bool isLogin = TokenHelper.getInstance.isLogin; return Scaffold( appBar: AppBar(