Hibok
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

332 řádky
12 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. Padding(
  59. padding: EdgeInsets.only(left: 20, right: 10, top: 15),
  60. child: Row(children: <Widget>[
  61. Expanded(child: Text(
  62. I18n.of(context).travel_tips2,
  63. textScaleFactor: 1.0,
  64. style: TextStyle(color: Color(0xffABABAB), fontSize: 13),
  65. )),
  66. InkWell(child: Container( width: 40,height: 40,child: Align(child: Icon(
  67. IconData(0xe681, fontFamily: Constants.IconFontFamily),
  68. color: Color(0xFFFF7E00),
  69. size: 28.0,
  70. ),alignment: Alignment.center,),),onTap: (){
  71. CustomUI.buildTip(context, I18n.of(context).travel_butler, Padding(padding: EdgeInsets.all(10),child: fixedText(I18n.of(context).travel_introduction,fontSize: 14),));
  72. },)
  73. ],),
  74. ) ,
  75. Container(
  76. margin: EdgeInsets.all(10),
  77. child: Card(
  78. elevation: 2, // 阴影
  79. shape: RoundedRectangleBorder(
  80. borderRadius: BorderRadius.circular(10),
  81. // side: BorderSide(color: Colors.green,width: 25),
  82. ),
  83. child: Container(
  84. // width: double.maxFinite,
  85. // color: Colors.blue,
  86. padding: EdgeInsets.all(14),
  87. child: Row(
  88. crossAxisAlignment: CrossAxisAlignment.start,
  89. // mainAxisAlignment: MainAxisAlignment.spaceAround,
  90. mainAxisSize: MainAxisSize.max,
  91. children: <Widget>[
  92. Column(
  93. children: <Widget>[
  94. SizedBox(height: 17,),
  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(0xff3875E9),
  109. width: 17,height: 17,
  110. ),
  111. ),
  112. Padding(padding: EdgeInsets.only(top: 5,bottom: 5),child: MySeparator(color: Color(0xffDADCDE)),),
  113. ClipOval(
  114. child: Container(
  115. padding: EdgeInsets.all(4),
  116. child: ClipOval(
  117. child: Container(
  118. color: Colors.white,
  119. width: 5,height: 5,
  120. ),
  121. ),
  122. // decoration: BoxDecoration(
  123. // color: Color(0xff3875E9),
  124. // border: Border.all(
  125. // color: Color(0xff3875E9), width: 3)),
  126. color: Color(0xffFF1010),
  127. width: 17,height: 17,
  128. ),
  129. ),
  130. ],
  131. ),
  132. SizedBox(width: 12,),
  133. Expanded(child: Container( child: Column(mainAxisSize: MainAxisSize.max,children: <Widget>[
  134. InkWell(child: positionLayout(true),onTap: ()async{
  135. if (!UserData().hasLocationPermission) {
  136. CustomUI.buildOneConfirm(
  137. context, I18n.of(context).get_location, I18n.of(context).determine,
  138. () {
  139. Navigator.of(context).pop();
  140. LocationPermissions().openAppSettings();
  141. });
  142. return;
  143. }
  144. startResult = await _openMap(context);
  145. print('ddddd: $startResult');
  146. setState(() {
  147. });
  148. },),
  149. Container(color: Color(0xffD8D8D8),height: 0.8,width: double.maxFinite,),
  150. InkWell(child: positionLayout(false),onTap: ()async{
  151. if (!UserData().hasLocationPermission) {
  152. CustomUI.buildOneConfirm(
  153. context, I18n.of(context).get_location, I18n.of(context).determine,
  154. () {
  155. Navigator.of(context).pop();
  156. LocationPermissions().openAppSettings();
  157. });
  158. return;
  159. }
  160. endResult = await _openMap(context);
  161. setState(() {
  162. });
  163. },),
  164. ],),))
  165. ],
  166. ),
  167. ),
  168. ),
  169. ),
  170. Padding(
  171. padding: EdgeInsets.only(left: 15,right: 15,bottom: 20,top: 13),
  172. child: Text(
  173. I18n.of(context).travel_tips,
  174. textScaleFactor: 1.0,
  175. textAlign: TextAlign.left,
  176. style: TextStyle(
  177. color: Color(0xff797979), fontSize: 11),
  178. ),
  179. ),
  180. Container(
  181. margin: EdgeInsets.only(left: 70, right: 70 ,bottom: 30),
  182. height: 47,
  183. child: RaisedButton(
  184. color: Color(0xff3875E9),
  185. shape: RoundedRectangleBorder(
  186. borderRadius: BorderRadius.all(Radius.circular(10))),
  187. child: Text(
  188. I18n.of(context).travel_check_distance,
  189. textScaleFactor: 1.0,
  190. style: TextStyle(color: Colors.white, fontSize: 19),
  191. ),
  192. onPressed: () async{
  193. if (startResult != null && endResult != null) {
  194. distanceB = await Geolocator().distanceBetween(
  195. startResult.latLng.latitude,
  196. startResult.latLng.longitude,
  197. endResult.latLng.latitude,
  198. endResult.latLng.longitude);
  199. HttpUtil().userRanging(distanceB.toInt(),startResult.address,endResult.address);
  200. setState(() {
  201. });
  202. }
  203. }),
  204. ),
  205. Container(
  206. margin: EdgeInsets.all(10),
  207. child: Card(
  208. elevation: 2, // 阴影
  209. shape: RoundedRectangleBorder(
  210. borderRadius: BorderRadius.circular(10),
  211. // side: BorderSide(color: Colors.green,width: 25),
  212. ),
  213. child: Container(
  214. // width: double.maxFinite,
  215. // color: Colors.blue,
  216. padding: EdgeInsets.all(14),
  217. child: Column(children: <Widget>[
  218. SizedBox(height: 21,),
  219. Text(
  220. I18n.of(context).travel_check_distance_result,
  221. textScaleFactor: 1.0,
  222. style: TextStyle(color: Color(0xff797979), fontSize: 16),
  223. ),
  224. Padding(padding: EdgeInsets.only(top: 25,bottom: 25),child: RichText(
  225. maxLines: 3,
  226. textAlign: TextAlign.center,
  227. text: TextSpan(children: [
  228. TextSpan(
  229. text: disStr[0],
  230. style: TextStyle(
  231. color: Color(0xffFF1010),
  232. fontSize: 25)),
  233. TextSpan(
  234. text: ' '+disStr[1],
  235. style: TextStyle(
  236. color: Color(0xff6F4A5D),
  237. fontSize: 17)),
  238. ])),)
  239. ],),
  240. ),
  241. ),
  242. ),
  243. ],
  244. ),
  245. ),
  246. ),
  247. );
  248. }
  249. Widget positionLayout(bool isStart){
  250. String str = isStart?I18n.of(context).travel_my_location:I18n.of(context).travel_go_where;
  251. if(isStart && startResult!=null && startResult.address!=null){
  252. str = startResult.address;
  253. }else if (!isStart && endResult!=null &&endResult.address!=null){
  254. str = endResult.address;
  255. }
  256. return Container(height:50,child: Row(mainAxisSize: MainAxisSize.max, children: <Widget>[
  257. Expanded(child: Container( child: fixedText(str,color: Colors.black,fontSize: 16),)),
  258. fixedText(isStart?I18n.of(context).travel_start:I18n.of(context).travel_end,color: Color(0xff797979),fontSize: 14)
  259. ],),);
  260. }
  261. getDistanceStr(double m) {
  262. if (m < 1000) {
  263. return '${m.toInt()} M';
  264. } else {
  265. return '${(m / 1000).toStringAsFixed(2)} KM';
  266. }
  267. }
  268. _openMap(BuildContext context) async {
  269. if (await CustomUI.showPermissionSetting(
  270. context, PermissionGroup.location, I18n.of(context).open_location)) {
  271. return LocationPicker.pickLocation(
  272. context, 'AIzaSyAb9JNtW0BEZ_qLeDg87ZhvxSmZply-7hU',
  273. initialCenter: LatLng(UserData().latitude, UserData().longitude));
  274. // print('地图结果 ${result}');
  275. // return result;
  276. }
  277. }
  278. }