Hibok
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

311 行
11 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/map/google_map_location_picker.dart';
  3. import 'package:chat/map/location_result.dart';
  4. import 'package:chat/models/group_info_model.dart';
  5. import 'package:chat/utils/HttpUtil.dart';
  6. import 'package:chat/utils/screen.dart';
  7. import 'package:chat/utils/separator_line.dart';
  8. import 'package:flutter/cupertino.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:geolocator/geolocator.dart';
  11. import 'package:google_maps_flutter/google_maps_flutter.dart';
  12. import 'package:location_permissions/location_permissions.dart';
  13. import 'package:permission_handler/permission_handler.dart';
  14. import '../../data/constants.dart';
  15. import '../../generated/i18n.dart';
  16. import '../../utils/CustomUI.dart';
  17. class TravelButlerPage extends StatefulWidget {
  18. final GroupInfoModel groupInfoModel;
  19. TravelButlerPage({Key key, this.groupInfoModel}) : super(key: key);
  20. @override
  21. State<StatefulWidget> createState() {
  22. return TravelButlerPageState();
  23. }
  24. }
  25. class TravelButlerPageState extends State<TravelButlerPage> {
  26. LocationResult startResult;
  27. LocationResult endResult;
  28. double distanceB = 0.0;
  29. @override
  30. void initState() {
  31. super.initState();
  32. }
  33. @override
  34. void dispose() {
  35. // MessageMgr().off('Update Group Info', updateGroupInfo);
  36. super.dispose();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. List<String> disStr =getDistanceStr(distanceB).toString().split(' ');
  41. Widget appBar = AppBar(
  42. backgroundColor: AppColors.NewAppbarBgColor,
  43. title: Text(
  44. I18n.of(context).travel_butler,
  45. textScaleFactor: 1.0,
  46. style: TextStyle(color: AppColors.NewAppbarTextColor),
  47. ),
  48. // leading: CustomUI.buildCustomLeading(context),
  49. centerTitle: true,
  50. );
  51. return Scaffold(
  52. appBar: appBar,
  53. body: SafeArea(
  54. child: Container(
  55. color: Color(0xffE8EAF0),
  56. child: ListView(
  57. children: <Widget>[
  58. Container(
  59. margin: EdgeInsets.all(10),
  60. child: Card(
  61. elevation: 2, // 阴影
  62. shape: RoundedRectangleBorder(
  63. borderRadius: BorderRadius.circular(10),
  64. // side: BorderSide(color: Colors.green,width: 25),
  65. ),
  66. child: Container(
  67. // width: double.maxFinite,
  68. // color: Colors.blue,
  69. padding: EdgeInsets.all(14),
  70. child: Row(
  71. crossAxisAlignment: CrossAxisAlignment.start,
  72. // mainAxisAlignment: MainAxisAlignment.spaceAround,
  73. mainAxisSize: MainAxisSize.max,
  74. children: <Widget>[
  75. Column(
  76. children: <Widget>[
  77. SizedBox(height: 17,),
  78. ClipOval(
  79. child: Container(
  80. padding: EdgeInsets.all(4),
  81. child: ClipOval(
  82. child: Container(
  83. color: Colors.white,
  84. width: 5,height: 5,
  85. ),
  86. ),
  87. // decoration: BoxDecoration(
  88. // color: Color(0xff3875E9),
  89. // border: Border.all(
  90. // color: Color(0xff3875E9), width: 3)),
  91. color: Color(0xff3875E9),
  92. width: 17,height: 17,
  93. ),
  94. ),
  95. Padding(padding: EdgeInsets.only(top: 5,bottom: 5),child: MySeparator(color: Color(0xffDADCDE)),),
  96. ClipOval(
  97. child: Container(
  98. padding: EdgeInsets.all(4),
  99. child: ClipOval(
  100. child: Container(
  101. color: Colors.white,
  102. width: 5,height: 5,
  103. ),
  104. ),
  105. // decoration: BoxDecoration(
  106. // color: Color(0xff3875E9),
  107. // border: Border.all(
  108. // color: Color(0xff3875E9), width: 3)),
  109. color: Color(0xffFF1010),
  110. width: 17,height: 17,
  111. ),
  112. ),
  113. ],
  114. ),
  115. SizedBox(width: 12,),
  116. Expanded(child: Container( child: Column(mainAxisSize: MainAxisSize.max,children: <Widget>[
  117. InkWell(child: positionLayout(true),onTap: ()async{
  118. if (!UserData().hasLocationPermission) {
  119. CustomUI.buildOneConfirm(
  120. context, I18n.of(context).get_location, I18n.of(context).determine,
  121. () {
  122. Navigator.of(context).pop();
  123. LocationPermissions().openAppSettings();
  124. });
  125. return;
  126. }
  127. startResult = await _openMap(context);
  128. print('ddddd: $startResult');
  129. setState(() {
  130. });
  131. },),
  132. Container(color: Color(0xffD8D8D8),height: 0.8,width: double.maxFinite,),
  133. InkWell(child: positionLayout(false),onTap: ()async{
  134. if (!UserData().hasLocationPermission) {
  135. CustomUI.buildOneConfirm(
  136. context, I18n.of(context).get_location, I18n.of(context).determine,
  137. () {
  138. Navigator.of(context).pop();
  139. LocationPermissions().openAppSettings();
  140. });
  141. return;
  142. }
  143. endResult = await _openMap(context);
  144. setState(() {
  145. });
  146. },),
  147. ],),))
  148. ],
  149. ),
  150. ),
  151. ),
  152. ),
  153. Padding(
  154. padding: EdgeInsets.only(left: 15,right: 15,bottom: 20,top: 13),
  155. child: Text(
  156. I18n.of(context).travel_tips,
  157. textScaleFactor: 1.0,
  158. textAlign: TextAlign.left,
  159. style: TextStyle(
  160. color: Color(0xff797979), fontSize: 11),
  161. ),
  162. ),
  163. Container(
  164. margin: EdgeInsets.only(left: 70, right: 70 ,bottom: 30),
  165. height: 47,
  166. child: RaisedButton(
  167. color: Color(0xff3875E9),
  168. shape: RoundedRectangleBorder(
  169. borderRadius: BorderRadius.all(Radius.circular(10))),
  170. child: Text(
  171. I18n.of(context).travel_check_distance,
  172. textScaleFactor: 1.0,
  173. style: TextStyle(color: Colors.white, fontSize: 19),
  174. ),
  175. onPressed: () async{
  176. if (startResult != null && endResult != null) {
  177. distanceB = await Geolocator().distanceBetween(
  178. startResult.latLng.latitude,
  179. startResult.latLng.longitude,
  180. endResult.latLng.latitude,
  181. endResult.latLng.longitude);
  182. HttpUtil().userRanging(distanceB.toInt(),startResult.address,endResult.address);
  183. setState(() {
  184. });
  185. }
  186. }),
  187. ),
  188. Container(
  189. margin: EdgeInsets.all(10),
  190. child: Card(
  191. elevation: 2, // 阴影
  192. shape: RoundedRectangleBorder(
  193. borderRadius: BorderRadius.circular(10),
  194. // side: BorderSide(color: Colors.green,width: 25),
  195. ),
  196. child: Container(
  197. // width: double.maxFinite,
  198. // color: Colors.blue,
  199. padding: EdgeInsets.all(14),
  200. child: Column(children: <Widget>[
  201. SizedBox(height: 21,),
  202. Text(
  203. I18n.of(context).travel_check_distance_result,
  204. textScaleFactor: 1.0,
  205. style: TextStyle(color: Color(0xff797979), fontSize: 16),
  206. ),
  207. Padding(padding: EdgeInsets.only(top: 25,bottom: 25),child: RichText(
  208. maxLines: 3,
  209. textAlign: TextAlign.center,
  210. text: TextSpan(children: [
  211. TextSpan(
  212. text: disStr[0],
  213. style: TextStyle(
  214. color: Color(0xffFF1010),
  215. fontSize: 25)),
  216. TextSpan(
  217. text: ' '+disStr[1],
  218. style: TextStyle(
  219. color: Color(0xff6F4A5D),
  220. fontSize: 17)),
  221. ])),)
  222. ],),
  223. ),
  224. ),
  225. ),
  226. ],
  227. ),
  228. ),
  229. ),
  230. );
  231. }
  232. Widget positionLayout(bool isStart){
  233. String str = isStart?I18n.of(context).travel_my_location:I18n.of(context).travel_go_where;
  234. if(isStart && startResult!=null && startResult.address!=null){
  235. str = startResult.address;
  236. }else if (!isStart && endResult!=null &&endResult.address!=null){
  237. str = endResult.address;
  238. }
  239. return Container(height:50,child: Row(mainAxisSize: MainAxisSize.max, children: <Widget>[
  240. Expanded(child: Container( child: fixedText(str,color: Colors.black,fontSize: 16),)),
  241. fixedText(isStart?I18n.of(context).travel_start:I18n.of(context).travel_end,color: Color(0xff797979),fontSize: 14)
  242. ],),);
  243. }
  244. getDistanceStr(double m) {
  245. if (m < 1000) {
  246. return '${m.toInt()} M';
  247. } else {
  248. return '${(m / 1000).toStringAsFixed(2)} KM';
  249. }
  250. }
  251. _openMap(BuildContext context) async {
  252. if (await CustomUI.showPermissionSetting(
  253. context, PermissionGroup.location, I18n.of(context).open_location)) {
  254. return LocationPicker.pickLocation(
  255. context, 'AIzaSyAb9JNtW0BEZ_qLeDg87ZhvxSmZply-7hU',
  256. initialCenter: LatLng(UserData().latitude, UserData().longitude));
  257. // print('地图结果 ${result}');
  258. // return result;
  259. }
  260. }
  261. }