Hibok
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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