Hibok
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

300 wiersze
11 KiB

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