Hibok
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

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