Showing
9 changed files
with
2436 additions
and
2372 deletions
Too many changes to show.
To preserve performance only 9 of 9+ files are displayed.
| @@ -4,13 +4,13 @@ | @@ -4,13 +4,13 @@ | ||
| 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
| 5 | "version": "0.2.0", | 5 | "version": "0.2.0", |
| 6 | "configurations": [ | 6 | "configurations": [ |
| 7 | - | 7 | + |
| 8 | { | 8 | { |
| 9 | "name": "Flutter-ReserveApp", | 9 | "name": "Flutter-ReserveApp", |
| 10 | "request": "launch", | 10 | "request": "launch", |
| 11 | "type": "dart" | 11 | "type": "dart" |
| 12 | }, | 12 | }, |
| 13 | - { | 13 | + { |
| 14 | "name": "Flutter-ReserveApp (profile mode)", | 14 | "name": "Flutter-ReserveApp (profile mode)", |
| 15 | "request": "launch", | 15 | "request": "launch", |
| 16 | "type": "dart", | 16 | "type": "dart", |
| @@ -263,6 +263,26 @@ | @@ -263,6 +263,26 @@ | ||
| 263 | "flutterMode": "release" | 263 | "flutterMode": "release" |
| 264 | }, | 264 | }, |
| 265 | { | 265 | { |
| 266 | + "name": "fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new", | ||
| 267 | + "cwd": "library/fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new", | ||
| 268 | + "request": "launch", | ||
| 269 | + "type": "dart" | ||
| 270 | + }, | ||
| 271 | + { | ||
| 272 | + "name": "fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new (profile mode)", | ||
| 273 | + "cwd": "library/fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new", | ||
| 274 | + "request": "launch", | ||
| 275 | + "type": "dart", | ||
| 276 | + "flutterMode": "profile" | ||
| 277 | + }, | ||
| 278 | + { | ||
| 279 | + "name": "fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new (release mode)", | ||
| 280 | + "cwd": "library/fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new", | ||
| 281 | + "request": "launch", | ||
| 282 | + "type": "dart", | ||
| 283 | + "flutterMode": "release" | ||
| 284 | + }, | ||
| 285 | + { | ||
| 266 | "name": "save_file", | 286 | "name": "save_file", |
| 267 | "cwd": "library/save_file", | 287 | "cwd": "library/save_file", |
| 268 | "request": "launch", | 288 | "request": "launch", |
| @@ -604,6 +624,26 @@ | @@ -604,6 +624,26 @@ | ||
| 604 | }, | 624 | }, |
| 605 | { | 625 | { |
| 606 | "name": "example", | 626 | "name": "example", |
| 627 | + "cwd": "library/fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new/example", | ||
| 628 | + "request": "launch", | ||
| 629 | + "type": "dart" | ||
| 630 | + }, | ||
| 631 | + { | ||
| 632 | + "name": "example (profile mode)", | ||
| 633 | + "cwd": "library/fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new/example", | ||
| 634 | + "request": "launch", | ||
| 635 | + "type": "dart", | ||
| 636 | + "flutterMode": "profile" | ||
| 637 | + }, | ||
| 638 | + { | ||
| 639 | + "name": "example (release mode)", | ||
| 640 | + "cwd": "library/fluttertpc_open_filex-e4f9a98a434ff18ffdb4db406b5798f88e5f3ded_new/example", | ||
| 641 | + "request": "launch", | ||
| 642 | + "type": "dart", | ||
| 643 | + "flutterMode": "release" | ||
| 644 | + }, | ||
| 645 | + { | ||
| 646 | + "name": "example", | ||
| 607 | "cwd": "library/table_calendar-3.1.3/example", | 647 | "cwd": "library/table_calendar-3.1.3/example", |
| 608 | "request": "launch", | 648 | "request": "launch", |
| 609 | "type": "dart" | 649 | "type": "dart" |
.vscode/settings.json
deleted
100644 → 0
| @@ -355,10 +355,14 @@ | @@ -355,10 +355,14 @@ | ||
| 355 | inputFileListPaths = ( | 355 | inputFileListPaths = ( |
| 356 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", | 356 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", |
| 357 | ); | 357 | ); |
| 358 | + inputPaths = ( | ||
| 359 | + ); | ||
| 358 | name = "[CP] Embed Pods Frameworks"; | 360 | name = "[CP] Embed Pods Frameworks"; |
| 359 | outputFileListPaths = ( | 361 | outputFileListPaths = ( |
| 360 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", | 362 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", |
| 361 | ); | 363 | ); |
| 364 | + outputPaths = ( | ||
| 365 | + ); | ||
| 362 | runOnlyForDeploymentPostprocessing = 0; | 366 | runOnlyForDeploymentPostprocessing = 0; |
| 363 | shellPath = /bin/sh; | 367 | shellPath = /bin/sh; |
| 364 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; | 368 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; |
| @@ -372,10 +376,14 @@ | @@ -372,10 +376,14 @@ | ||
| 372 | inputFileListPaths = ( | 376 | inputFileListPaths = ( |
| 373 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", | 377 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", |
| 374 | ); | 378 | ); |
| 379 | + inputPaths = ( | ||
| 380 | + ); | ||
| 375 | name = "[CP] Copy Pods Resources"; | 381 | name = "[CP] Copy Pods Resources"; |
| 376 | outputFileListPaths = ( | 382 | outputFileListPaths = ( |
| 377 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", | 383 | "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", |
| 378 | ); | 384 | ); |
| 385 | + outputPaths = ( | ||
| 386 | + ); | ||
| 379 | runOnlyForDeploymentPostprocessing = 0; | 387 | runOnlyForDeploymentPostprocessing = 0; |
| 380 | shellPath = /bin/sh; | 388 | shellPath = /bin/sh; |
| 381 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; | 389 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; |
| @@ -530,6 +538,7 @@ | @@ -530,6 +538,7 @@ | ||
| 530 | CURRENT_PROJECT_VERSION = 6100; | 538 | CURRENT_PROJECT_VERSION = 6100; |
| 531 | DEVELOPMENT_TEAM = 8J59HM8B82; | 539 | DEVELOPMENT_TEAM = 8J59HM8B82; |
| 532 | ENABLE_BITCODE = NO; | 540 | ENABLE_BITCODE = NO; |
| 541 | + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; | ||
| 533 | INFOPLIST_FILE = Runner/Info.plist; | 542 | INFOPLIST_FILE = Runner/Info.plist; |
| 534 | IPHONEOS_DEPLOYMENT_TARGET = 18.0; | 543 | IPHONEOS_DEPLOYMENT_TARGET = 18.0; |
| 535 | LD_RUNPATH_SEARCH_PATHS = ( | 544 | LD_RUNPATH_SEARCH_PATHS = ( |
| @@ -541,6 +550,7 @@ | @@ -541,6 +550,7 @@ | ||
| 541 | PRODUCT_NAME = "$(TARGET_NAME)"; | 550 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 542 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; | 551 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; |
| 543 | SWIFT_VERSION = 5.0; | 552 | SWIFT_VERSION = 5.0; |
| 553 | + VALID_ARCHS = "i386 arm64 x86_64 armv7"; | ||
| 544 | VERSIONING_SYSTEM = "apple-generic"; | 554 | VERSIONING_SYSTEM = "apple-generic"; |
| 545 | }; | 555 | }; |
| 546 | name = Profile; | 556 | name = Profile; |
| @@ -713,6 +723,7 @@ | @@ -713,6 +723,7 @@ | ||
| 713 | CURRENT_PROJECT_VERSION = 6100; | 723 | CURRENT_PROJECT_VERSION = 6100; |
| 714 | DEVELOPMENT_TEAM = 8J59HM8B82; | 724 | DEVELOPMENT_TEAM = 8J59HM8B82; |
| 715 | ENABLE_BITCODE = NO; | 725 | ENABLE_BITCODE = NO; |
| 726 | + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; | ||
| 716 | INFOPLIST_FILE = Runner/Info.plist; | 727 | INFOPLIST_FILE = Runner/Info.plist; |
| 717 | IPHONEOS_DEPLOYMENT_TARGET = 18.0; | 728 | IPHONEOS_DEPLOYMENT_TARGET = 18.0; |
| 718 | LD_RUNPATH_SEARCH_PATHS = ( | 729 | LD_RUNPATH_SEARCH_PATHS = ( |
| @@ -725,6 +736,7 @@ | @@ -725,6 +736,7 @@ | ||
| 725 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; | 736 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; |
| 726 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; | 737 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; |
| 727 | SWIFT_VERSION = 5.0; | 738 | SWIFT_VERSION = 5.0; |
| 739 | + VALID_ARCHS = "i386 arm64 x86_64 armv7"; | ||
| 728 | VERSIONING_SYSTEM = "apple-generic"; | 740 | VERSIONING_SYSTEM = "apple-generic"; |
| 729 | }; | 741 | }; |
| 730 | name = Debug; | 742 | name = Debug; |
| @@ -739,6 +751,7 @@ | @@ -739,6 +751,7 @@ | ||
| 739 | CURRENT_PROJECT_VERSION = 6100; | 751 | CURRENT_PROJECT_VERSION = 6100; |
| 740 | DEVELOPMENT_TEAM = 8J59HM8B82; | 752 | DEVELOPMENT_TEAM = 8J59HM8B82; |
| 741 | ENABLE_BITCODE = NO; | 753 | ENABLE_BITCODE = NO; |
| 754 | + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; | ||
| 742 | INFOPLIST_FILE = Runner/Info.plist; | 755 | INFOPLIST_FILE = Runner/Info.plist; |
| 743 | IPHONEOS_DEPLOYMENT_TARGET = 18.0; | 756 | IPHONEOS_DEPLOYMENT_TARGET = 18.0; |
| 744 | LD_RUNPATH_SEARCH_PATHS = ( | 757 | LD_RUNPATH_SEARCH_PATHS = ( |
| @@ -750,6 +763,7 @@ | @@ -750,6 +763,7 @@ | ||
| 750 | PRODUCT_NAME = "$(TARGET_NAME)"; | 763 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 751 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; | 764 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; |
| 752 | SWIFT_VERSION = 5.0; | 765 | SWIFT_VERSION = 5.0; |
| 766 | + VALID_ARCHS = "i386 arm64 x86_64 armv7"; | ||
| 753 | VERSIONING_SYSTEM = "apple-generic"; | 767 | VERSIONING_SYSTEM = "apple-generic"; |
| 754 | }; | 768 | }; |
| 755 | name = Release; | 769 | name = Release; |
| @@ -71,6 +71,18 @@ | @@ -71,6 +71,18 @@ | ||
| 71 | ReferencedContainer = "container:Runner.xcodeproj"> | 71 | ReferencedContainer = "container:Runner.xcodeproj"> |
| 72 | </BuildableReference> | 72 | </BuildableReference> |
| 73 | </BuildableProductRunnable> | 73 | </BuildableProductRunnable> |
| 74 | + <AdditionalOptions> | ||
| 75 | + <AdditionalOption | ||
| 76 | + key = "NSZombieEnabled" | ||
| 77 | + value = "YES" | ||
| 78 | + isEnabled = "YES"> | ||
| 79 | + </AdditionalOption> | ||
| 80 | + <AdditionalOption | ||
| 81 | + key = "MallocScribble" | ||
| 82 | + value = "" | ||
| 83 | + isEnabled = "YES"> | ||
| 84 | + </AdditionalOption> | ||
| 85 | + </AdditionalOptions> | ||
| 74 | </LaunchAction> | 86 | </LaunchAction> |
| 75 | <ProfileAction | 87 | <ProfileAction |
| 76 | buildConfiguration = "Profile" | 88 | buildConfiguration = "Profile" |
| 1 | -// import 'package:csp_amap_flutter_base/csp_amap_flutter_base.dart'; | 1 | +import 'package:csp_amap_flutter_base/csp_amap_flutter_base.dart'; |
| 2 | 2 | ||
| 3 | -// class ConstConfig { | ||
| 4 | -// static const AMapApiKey amapApiKeys = AMapApiKey( | ||
| 5 | -// androidKey: '900f72eeee0f21e435cebb0ef155582a', //测试key | ||
| 6 | -// iosKey: '4dfdec97b7bf0b8c13e94777103015a9', //测试key | ||
| 7 | -// ohosKey: '7c2081e92ec65bfffa2df0a5464f0c7b'); //我的账户下面的ceshikey | ||
| 8 | -// static const AMapPrivacyStatement amapPrivacyStatement = | ||
| 9 | -// AMapPrivacyStatement(hasContains: true, hasShow: true, hasAgree: true); | ||
| 10 | -// } | 3 | +class ConstConfig { |
| 4 | + static const AMapApiKey amapApiKeys = AMapApiKey( | ||
| 5 | + androidKey: '900f72eeee0f21e435cebb0ef155582a', //测试key | ||
| 6 | + iosKey: '4dfdec97b7bf0b8c13e94777103015a9', //测试key | ||
| 7 | + ohosKey: '7c2081e92ec65bfffa2df0a5464f0c7b'); //我的账户下面的ceshikey | ||
| 8 | + static const AMapPrivacyStatement amapPrivacyStatement = | ||
| 9 | + AMapPrivacyStatement(hasContains: true, hasShow: true, hasAgree: true); | ||
| 10 | +} |
| 1 | -import 'dart:async'; | ||
| 2 | - | ||
| 3 | -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; | ||
| 4 | -import 'package:flutter/cupertino.dart'; | ||
| 5 | - | ||
| 6 | -import 'package:flutter/material.dart'; | ||
| 7 | - | ||
| 8 | -import 'package:flutter_easyrefresh/easy_refresh.dart'; | ||
| 9 | - | ||
| 10 | - | ||
| 11 | -import 'package:one_key/res/colors.dart'; | ||
| 12 | - | ||
| 13 | -import 'package:one_key/utils/misc.dart'; | ||
| 14 | - | ||
| 15 | -import 'package:one_key/utils/screen_util.dart'; | ||
| 16 | -import 'package:one_key/utils/utils.dart'; | ||
| 17 | - | ||
| 18 | -import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 19 | -import 'package:permission_handler/permission_handler.dart'; | ||
| 20 | - | ||
| 21 | -import '../../utils/common_utils.dart'; | ||
| 22 | -// import 'package:demo/resources/custom_text_style.dart'; | ||
| 23 | -// import 'package:demo/utils/misc.dart'; | ||
| 24 | - | ||
| 25 | -// import 'package:demo/widgets/network_state/page_loading.dart'; | ||
| 26 | - | ||
| 27 | -class MapChoicePointPage extends StatefulWidget { | ||
| 28 | - final String? long; | ||
| 29 | - final String? lat; | ||
| 30 | - MapChoicePointPage({Key? key, this.long, this.lat}) : super(key: key); | ||
| 31 | - | ||
| 32 | - @override | ||
| 33 | - _MapChoicePointPageState createState() => _MapChoicePointPageState(); | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -class _MapChoicePointPageState extends State<MapChoicePointPage> { | ||
| 37 | - AmapController? _controller; | ||
| 38 | - List<Poi>? poiList; | ||
| 39 | - static List<PoiModel?> list = []; | ||
| 40 | - static List<PoiModel> searchlist = []; | ||
| 41 | - PoiModel? poiModel; | ||
| 42 | - String keyword = ""; | ||
| 43 | - String? address = ""; | ||
| 44 | - bool isloading = true; | ||
| 45 | - | ||
| 46 | - double latitude = 39.684670899; | ||
| 47 | - double longitude = 118.17630045; | ||
| 48 | - | ||
| 49 | - double latitudeLocation = 39.684670899; | ||
| 50 | - double longitudeLocation = 118.17630045; | ||
| 51 | - | ||
| 52 | - List<InputTip> inputTipDatas = []; | ||
| 53 | - int page = 1; | ||
| 54 | - EasyRefreshController refreshController = EasyRefreshController(); | ||
| 55 | - bool flag = true; | ||
| 56 | - | ||
| 57 | - @override | ||
| 58 | - void initState() { | ||
| 59 | - super.initState(); | ||
| 60 | - | ||
| 61 | - if (widget.long != null && widget.long != '' && widget.long != 'null') { | ||
| 62 | - longitude = double.parse(widget.long!); | ||
| 63 | - } | ||
| 64 | - if (widget.lat != null && widget.lat != '' && widget.lat != 'null') { | ||
| 65 | - latitude = double.parse(widget.lat!); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - WidgetsBinding.instance.addPostFrameCallback((_) async { | ||
| 69 | - _requestLocationPermission(); | ||
| 70 | - | ||
| 71 | - // ama | ||
| 72 | - // let marker = new AMap.Marker({//添加标记点 | ||
| 73 | - // position: this.position, | ||
| 74 | - // map: map | ||
| 75 | - }); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - // Future<bool> checkLocationPermission() async { | ||
| 79 | - // PermissionStatus permissionStatus = await Permission.location.status; | ||
| 80 | - // if (permissionStatus == PermissionStatus.granted) { | ||
| 81 | - // return true; | ||
| 82 | - // } else { | ||
| 83 | - // return false; | ||
| 84 | - // } | ||
| 85 | - // } | ||
| 86 | - | ||
| 87 | - /// 检查权限并定 | ||
| 88 | - // _getLocationPermission() async { | ||
| 89 | - // if (!(await checkPermission(Permission.location))) { | ||
| 90 | - // //没有定位权限 | ||
| 91 | - | ||
| 92 | - // //申请定位权限 | ||
| 93 | - // _requestLocationPermission(); | ||
| 94 | - // } else { | ||
| 95 | - // //去定位 | ||
| 96 | - // _requestLocationPermission(); | ||
| 97 | - // } | ||
| 98 | - // } | ||
| 99 | - | ||
| 100 | - /// 获取定位权限 | ||
| 101 | - _requestLocationPermission() async { | ||
| 102 | - await AmapLocation.instance.updatePrivacyShow(true); | ||
| 103 | - await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 104 | - bool canLocation = false; | ||
| 105 | - | ||
| 106 | - if (!(await checkPermission(Permission.location))) { | ||
| 107 | - //没有定位权限 | ||
| 108 | - | ||
| 109 | - //申请定位权限 | ||
| 110 | - canLocation = await requestPermission(Permission.location); | ||
| 111 | - } else { | ||
| 112 | - canLocation = true; | ||
| 113 | - } | ||
| 114 | - // bool canLocation = await requestPermission(Permission.location); | ||
| 115 | - // 单次定位 | ||
| 116 | - if (canLocation) { | ||
| 117 | - Future.delayed(Duration(milliseconds: 200), () async { | ||
| 118 | - await AmapLocation.instance.updatePrivacyShow(true); | ||
| 119 | - await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 120 | - final location = await AmapLocation.instance.fetchLocation( | ||
| 121 | - // needAddress: true, | ||
| 122 | - // mode: LocationAccuracy.High, | ||
| 123 | - // timeout: Duration(seconds: 10) | ||
| 124 | - ); | ||
| 125 | - | ||
| 126 | - if (location.city == null || location.city == '') //网络不好,定位失败 | ||
| 127 | - { | ||
| 128 | - // App.sp.setString("lat", "39.684670899"); | ||
| 129 | - // App.sp.setString("lng", "118.17630045"); | ||
| 130 | - } else { | ||
| 131 | - if (widget.long == null || | ||
| 132 | - widget.long == '' || | ||
| 133 | - widget.long == 'null') { | ||
| 134 | - latitude = location.latLng!.latitude; | ||
| 135 | - longitude = location.latLng!.longitude; | ||
| 136 | - if (_controller != null) { | ||
| 137 | - _controller!.setCenterCoordinate(LatLng( | ||
| 138 | - location.latLng!.latitude, location.latLng!.longitude)); | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | - page = 1; | ||
| 142 | - | ||
| 143 | - _loadData( | ||
| 144 | - LatLng(location.latLng!.latitude, location.latLng!.longitude)); | ||
| 145 | - | ||
| 146 | - setState(() {}); | ||
| 147 | - } | ||
| 148 | - latitudeLocation = location.latLng!.latitude; | ||
| 149 | - longitudeLocation = location.latLng!.longitude; | ||
| 150 | - } | ||
| 151 | - }); | ||
| 152 | - } else { | ||
| 153 | - //无权限 | ||
| 154 | - } | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - @override | ||
| 158 | - Widget build(BuildContext context) { | ||
| 159 | - return Scaffold( | ||
| 160 | - resizeToAvoidBottomInset: false, //防止底部布局被顶起 | ||
| 161 | - appBar: SystemAppBar( | ||
| 162 | - '选择位置信息', | ||
| 163 | - onTap: () { | ||
| 164 | - if (Navigator.canPop(context)) { | ||
| 165 | - Navigator.pop(context); | ||
| 166 | - } | ||
| 167 | - }, | ||
| 168 | - ), | ||
| 169 | - | ||
| 170 | - body: Column( | ||
| 171 | - children: <Widget>[ | ||
| 172 | - // Theme( | ||
| 173 | - // data: new | ||
| 174 | - // ThemeData( | ||
| 175 | - // // primaryColor: MyColours.color_438E93, | ||
| 176 | - // // hintColor: MyColours.color_438E93), | ||
| 177 | - // child: | ||
| 178 | - // Container( | ||
| 179 | - // color: MyColours.color_438E93, | ||
| 180 | - // decoration: BoxDecoration( | ||
| 181 | - // color: MyColours.color_438E93, | ||
| 182 | - // boxShadow: [ | ||
| 183 | - // BoxShadow(color: Colors.white, spreadRadius: 1), | ||
| 184 | - // ], | ||
| 185 | - // ), | ||
| 186 | - | ||
| 187 | - // padding: EdgeInsets.all(5), | ||
| 188 | - // child: | ||
| 189 | - | ||
| 190 | - // ), | ||
| 191 | - // ), | ||
| 192 | - // ListView.builder( | ||
| 193 | - // shrinkWrap: true, | ||
| 194 | - // itemCount: inputTipDatas.length, | ||
| 195 | - // itemBuilder: (context, index) { | ||
| 196 | - // InputTip inputTip = inputTipDatas[index]; | ||
| 197 | - // return InkWell( | ||
| 198 | - // onTap: () { | ||
| 199 | - // // searchAroundAddress(inputTip.name ?? ''); | ||
| 200 | - // // searchPoiId(inputTip.poiId ?? ''); | ||
| 201 | - // // _loadData(inputTip.coordinate ?? | ||
| 202 | - // // LatLng(latitude, longitude)); | ||
| 203 | - // }, | ||
| 204 | - // child: Container( | ||
| 205 | - // child: Row( | ||
| 206 | - // children: [ | ||
| 207 | - // Text( | ||
| 208 | - // inputTip.name ?? '', | ||
| 209 | - // style: TextStyle( | ||
| 210 | - // fontSize: font(15), | ||
| 211 | - // color: MyColours.color_515151), | ||
| 212 | - // ), | ||
| 213 | - // HEmptyView(10), | ||
| 214 | - // Expanded( | ||
| 215 | - // child: Text( | ||
| 216 | - // (inputTip.district ?? '') + | ||
| 217 | - // (inputTip.address ?? ''), | ||
| 218 | - // style: TextStyle( | ||
| 219 | - // fontSize: font(13), | ||
| 220 | - // color: MyColours.color_999999), | ||
| 221 | - // ), | ||
| 222 | - // ), | ||
| 223 | - // ], | ||
| 224 | - // ))); | ||
| 225 | - // }) | ||
| 226 | - // ], | ||
| 227 | - // ), | ||
| 228 | - | ||
| 229 | - Stack( | ||
| 230 | - children: [ | ||
| 231 | - Container( | ||
| 232 | - height: w(300), | ||
| 233 | - child: Stack( | ||
| 234 | - children: <Widget>[ | ||
| 235 | - AmapView( | ||
| 236 | - showZoomControl: false, | ||
| 237 | - | ||
| 238 | - /// 是否显示指南针控件 | ||
| 239 | - showCompass: true, | ||
| 240 | - | ||
| 241 | - /// 是否显示比例尺控件 | ||
| 242 | - showScaleControl: true, | ||
| 243 | - | ||
| 244 | - /// 是否使能缩放手势 | ||
| 245 | - zoomGesturesEnabled: true, | ||
| 246 | - | ||
| 247 | - /// 是否使能滚动手势 | ||
| 248 | - scrollGesturesEnabled: true, | ||
| 249 | - | ||
| 250 | - /// 是否使能旋转手势 | ||
| 251 | - rotateGestureEnabled: false, | ||
| 252 | - centerCoordinate: LatLng(latitude, longitude), | ||
| 253 | - maskDelay: Duration(milliseconds: 500), | ||
| 254 | - zoomLevel: 19, | ||
| 255 | - onMapCreated: (controller) async { | ||
| 256 | - _controller = controller; | ||
| 257 | - _controller! | ||
| 258 | - .setCenterCoordinate(LatLng(latitude, longitude)); | ||
| 259 | - // if (await requestPermission(PermissionGroup.location)) { | ||
| 260 | - // await controller.showMyLocation(true); | ||
| 261 | - // await controller?.showLocateControl(true); | ||
| 262 | - // final latLng = await _controller?.getLocation( | ||
| 263 | - // delay: Duration(seconds: 2)); | ||
| 264 | - // await enableFluttifyLog(false); // 关闭log | ||
| 265 | - // _loadData(latLng); | ||
| 266 | - // } else { | ||
| 267 | - // //无权限 | ||
| 268 | - // _showLocPemWidget(); | ||
| 269 | - // } | ||
| 270 | - }, | ||
| 271 | - // markers: [], | ||
| 272 | - onMapMoveEnd: (MapMove move) async { | ||
| 273 | - latitude = move.coordinate!.latitude; | ||
| 274 | - longitude = move.coordinate!.longitude; | ||
| 275 | - page = 1; | ||
| 276 | - _loadData(move.coordinate!); | ||
| 277 | - }, | ||
| 278 | - ), | ||
| 279 | - Center( | ||
| 280 | - child: Icon( | ||
| 281 | - Icons.place, | ||
| 282 | - size: w(32), | ||
| 283 | - color: Color(0xFFFF0000), | ||
| 284 | - ), | ||
| 285 | - ), | ||
| 286 | - Positioned( | ||
| 287 | - right: w(10), | ||
| 288 | - bottom: w(10), | ||
| 289 | - child: InkWell( | ||
| 290 | - onTap: () { | ||
| 291 | - _controller!.setCenterCoordinate( | ||
| 292 | - LatLng(latitudeLocation, longitudeLocation)); | ||
| 293 | - }, | ||
| 294 | - child: Container( | ||
| 295 | - decoration: BoxDecoration( | ||
| 296 | - color: MyColours.color_ffffff, | ||
| 297 | - borderRadius: BorderRadius.circular(r(5))), | ||
| 298 | - padding: EdgeInsets.all(w(5)), | ||
| 299 | - child: Image.asset( | ||
| 300 | - Utils.getImgPath('location_map'), | ||
| 301 | - width: w(25), | ||
| 302 | - ), | ||
| 303 | - )), | ||
| 304 | - ) | ||
| 305 | - ], | ||
| 306 | - ), | ||
| 307 | - ), | ||
| 308 | - Positioned( | ||
| 309 | - top: w(10), | ||
| 310 | - left: w(20), | ||
| 311 | - right: w(20), | ||
| 312 | - child: Container( | ||
| 313 | - // height: w(45), | ||
| 314 | - padding: EdgeInsets.symmetric(vertical: w(10)), | ||
| 315 | - decoration: BoxDecoration( | ||
| 316 | - color: Colors.white, | ||
| 317 | - borderRadius: BorderRadius.circular(r(10))), | ||
| 318 | - child: TextField( | ||
| 319 | - textAlignVertical: TextAlignVertical.center, | ||
| 320 | - style: TextStyle( | ||
| 321 | - color: MyColours.color_515151, | ||
| 322 | - fontSize: font(15), | ||
| 323 | - ), | ||
| 324 | - controller: | ||
| 325 | - TextEditingController.fromValue(TextEditingValue( | ||
| 326 | - // 设置内容 | ||
| 327 | - text: keyword, | ||
| 328 | - selection: TextSelection.fromPosition(TextPosition( | ||
| 329 | - affinity: TextAffinity.downstream, | ||
| 330 | - offset: keyword.length)), | ||
| 331 | - // 保持光标在最后 | ||
| 332 | - )), | ||
| 333 | - decoration: InputDecoration( | ||
| 334 | - // border: b, | ||
| 335 | - // border: OutlineInputBorder( | ||
| 336 | - // borderRadius: BorderRadius.all(Radius.circular(40)), | ||
| 337 | - // ), | ||
| 338 | - border: OutlineInputBorder(borderSide: BorderSide.none), | ||
| 339 | - hintText: '输入关键字', | ||
| 340 | - isCollapsed: true, | ||
| 341 | - | ||
| 342 | - hintStyle: TextStyle( | ||
| 343 | - color: MyColours.color_999999, fontSize: font(15)), | ||
| 344 | - // contentPadding: const EdgeInsets.symmetric( | ||
| 345 | - // vertical: 8, horizontal: 1), | ||
| 346 | - prefixIconConstraints: BoxConstraints(maxWidth: w(40)), | ||
| 347 | - prefixIcon: Padding( | ||
| 348 | - padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 349 | - child: SizedBox( | ||
| 350 | - width: w(30), | ||
| 351 | - child: Image.asset( | ||
| 352 | - Utils.getImgPath('search_black'), | ||
| 353 | - ))), | ||
| 354 | - suffixIconConstraints: BoxConstraints(maxWidth: w(32)), | ||
| 355 | - suffixIcon: InkWell( | ||
| 356 | - child: Padding( | ||
| 357 | - padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 358 | - child: SizedBox( | ||
| 359 | - width: w(22), | ||
| 360 | - child: Image.asset( | ||
| 361 | - Utils.getImgPath('delete_black'), | ||
| 362 | - ))), | ||
| 363 | - onTap: () { | ||
| 364 | - keyword = ""; | ||
| 365 | - setState(() {}); | ||
| 366 | - }, | ||
| 367 | - ), | ||
| 368 | - fillColor: Colors.white, | ||
| 369 | - filled: true, | ||
| 370 | - ), | ||
| 371 | - | ||
| 372 | - inputFormatters: [], | ||
| 373 | - //内容改变的回调 | ||
| 374 | - onChanged: (text) { | ||
| 375 | - print('change $text'); | ||
| 376 | - keyword = text; | ||
| 377 | - | ||
| 378 | - //搜索 | ||
| 379 | - | ||
| 380 | - JhCommonUtils.debounce( | ||
| 381 | - () => _fetchInputTips(text.toString())); | ||
| 382 | - }, | ||
| 383 | - //内容提交(按回车)的回调 | ||
| 384 | - onSubmitted: (text) { | ||
| 385 | - print('submit $text'); | ||
| 386 | - // 触发关闭弹出来的键盘。 | ||
| 387 | - keyword = text; | ||
| 388 | - FocusScope.of(context).requestFocus(FocusNode()); | ||
| 389 | - setState(() { | ||
| 390 | - // isloading = true; | ||
| 391 | - }); | ||
| 392 | - | ||
| 393 | - // _fetchInputTips(text.toString()); | ||
| 394 | - | ||
| 395 | - // searchAroundAddress(text.toString()); | ||
| 396 | - }, | ||
| 397 | - //按回车时调用 | ||
| 398 | - onEditingComplete: () { | ||
| 399 | - print('onEditingComplete'); | ||
| 400 | - }, | ||
| 401 | - ), | ||
| 402 | - ), | ||
| 403 | - ) | ||
| 404 | - ], | ||
| 405 | - ), | ||
| 406 | - | ||
| 407 | - Expanded( | ||
| 408 | - flex: 1, | ||
| 409 | - child: Visibility( | ||
| 410 | - visible: !isloading, | ||
| 411 | - maintainSize: false, | ||
| 412 | - maintainSemantics: false, | ||
| 413 | - maintainInteractivity: false, | ||
| 414 | - replacement: Center( | ||
| 415 | - child: CupertinoActivityIndicator(), | ||
| 416 | - ), | ||
| 417 | - child: EasyRefresh.custom( | ||
| 418 | - controller: refreshController, | ||
| 419 | - slivers: [ | ||
| 420 | - SliverList( | ||
| 421 | - delegate: SliverChildBuilderDelegate( | ||
| 422 | - (BuildContext context, int position) { | ||
| 423 | - print("itemBuilder" + list.length.toString()); | ||
| 424 | - PoiModel item = list[position]!; | ||
| 425 | - return InkWell( | ||
| 426 | - child: Column( | ||
| 427 | - children: <Widget>[ | ||
| 428 | - Container( | ||
| 429 | - margin: EdgeInsets.only( | ||
| 430 | - top: 8, bottom: 5, left: 10), | ||
| 431 | - child: Row( | ||
| 432 | - children: <Widget>[ | ||
| 433 | - Icon( | ||
| 434 | - Icons.place, | ||
| 435 | - size: 20.0, | ||
| 436 | - color: position == 0 | ||
| 437 | - ? Colors.green | ||
| 438 | - : Colors.grey, | ||
| 439 | - ), | ||
| 440 | - Expanded( | ||
| 441 | - child: Text(item.title, | ||
| 442 | - style: TextStyle( | ||
| 443 | - fontSize: 16, | ||
| 444 | - color: position == 0 | ||
| 445 | - ? Colors.green | ||
| 446 | - : Color(0xFF787878)))) | ||
| 447 | - ], | ||
| 448 | - ), | ||
| 449 | - ), | ||
| 450 | - Container( | ||
| 451 | - margin: EdgeInsets.only( | ||
| 452 | - top: 5, bottom: 5, left: 18), | ||
| 453 | - alignment: Alignment.centerLeft, | ||
| 454 | - child: Text( | ||
| 455 | - item.address!, | ||
| 456 | - style: TextStyle( | ||
| 457 | - fontSize: 14, | ||
| 458 | - color: Color(0xFF646464), | ||
| 459 | - ), | ||
| 460 | - ), | ||
| 461 | - ), | ||
| 462 | - Divider( | ||
| 463 | - height: 1, | ||
| 464 | - ) | ||
| 465 | - ], | ||
| 466 | - ), | ||
| 467 | - onTap: () async { | ||
| 468 | - // await _controller.setCenterCoordinate( | ||
| 469 | - // LatLng(item.latLng.latitude, item.latLng.longitude), | ||
| 470 | - // zoomLevel: 16); | ||
| 471 | - if (Navigator.canPop(context)) { | ||
| 472 | - Navigator.pop(context, { | ||
| 473 | - 'address': item.address, | ||
| 474 | - 'lat': item.latLng!.latitude.toString(), | ||
| 475 | - 'lng': item.latLng!.longitude.toString() | ||
| 476 | - }); | ||
| 477 | - } | ||
| 478 | - }, | ||
| 479 | - ); | ||
| 480 | - }, | ||
| 481 | - childCount: list.length, | ||
| 482 | - ), | ||
| 483 | - ) | ||
| 484 | - ], | ||
| 485 | - onRefresh: () async { | ||
| 486 | - if (flag) { | ||
| 487 | - page = 1; | ||
| 488 | - _loadData(LatLng(latitude, longitude)); | ||
| 489 | - } | ||
| 490 | - }, | ||
| 491 | - onLoad: () async { | ||
| 492 | - if (flag) { | ||
| 493 | - page++; | ||
| 494 | - _loadData(LatLng(latitude, longitude), | ||
| 495 | - showloading: false); | ||
| 496 | - } | ||
| 497 | - }, | ||
| 498 | - )), | ||
| 499 | - ), | ||
| 500 | - ], | ||
| 501 | - ), | ||
| 502 | - ); | ||
| 503 | - } | ||
| 504 | - | ||
| 505 | - _fetchInputTips(String text) async { | ||
| 506 | - flag = false; | ||
| 507 | - page = 1; | ||
| 508 | - // setState(() { | ||
| 509 | - // isloading = true; | ||
| 510 | - // }); | ||
| 511 | - | ||
| 512 | - /// 逆地理编码(坐标转地址) | ||
| 513 | - /// | ||
| 514 | - /// | ||
| 515 | - await AmapLocation.instance.updatePrivacyShow(true); | ||
| 516 | - await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 517 | - | ||
| 518 | - LatLng latLng = LatLng(latitude, longitude); | ||
| 519 | - ReGeocode reGeocodeList = await AmapSearch.instance.searchReGeocode(latLng); | ||
| 520 | - | ||
| 521 | - // print(await reGeocodeList.toFutureString()); | ||
| 522 | - address = reGeocodeList.formatAddress; | ||
| 523 | - | ||
| 524 | - await AmapLocation.instance.updatePrivacyShow(true); | ||
| 525 | - await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 526 | - inputTipDatas = await AmapSearch.instance.fetchInputTips( | ||
| 527 | - text, | ||
| 528 | - city: "", | ||
| 529 | - ); | ||
| 530 | - print(inputTipDatas); | ||
| 531 | - | ||
| 532 | - poiModel = new PoiModel("当前位置", address, latLng); | ||
| 533 | - list.clear(); | ||
| 534 | - list.add(poiModel); | ||
| 535 | - for (var inputTip in inputTipDatas) { | ||
| 536 | - String? title = await inputTip.name ?? ''; | ||
| 537 | - String? cityStr = | ||
| 538 | - await (inputTip.district ?? '') + (inputTip.address ?? ''); | ||
| 539 | - | ||
| 540 | - LatLng? latLng = await inputTip.coordinate; | ||
| 541 | - | ||
| 542 | - list.add(new PoiModel(title.toString(), cityStr, latLng)); | ||
| 543 | - } | ||
| 544 | - | ||
| 545 | - | ||
| 546 | - print(list); | ||
| 547 | - | ||
| 548 | - setState(() { | ||
| 549 | - // isloading = false; | ||
| 550 | - }); | ||
| 551 | - } | ||
| 552 | - | ||
| 553 | - void _loadData(LatLng latLng, {showloading = true}) async { | ||
| 554 | - flag = true; | ||
| 555 | - setState(() { | ||
| 556 | - if (showloading) { | ||
| 557 | - isloading = true; | ||
| 558 | - } | ||
| 559 | - }); | ||
| 560 | - | ||
| 561 | - /// 逆地理编码(坐标转地址) | ||
| 562 | - /// | ||
| 563 | - /// | ||
| 564 | - | ||
| 565 | - await AmapLocation.instance.updatePrivacyShow(true); | ||
| 566 | - await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 567 | - if (page == 1) { | ||
| 568 | - ReGeocode reGeocodeList = await AmapSearch.instance.searchReGeocode( | ||
| 569 | - latLng, | ||
| 570 | - ); | ||
| 571 | - // print(await reGeocodeList.toFutureString()); | ||
| 572 | - address = reGeocodeList.formatAddress; | ||
| 573 | - poiModel = new PoiModel("当前位置", address, latLng); | ||
| 574 | - list.clear(); | ||
| 575 | - list.add(poiModel); | ||
| 576 | - } | ||
| 577 | - final poiList = | ||
| 578 | - await AmapSearch.instance.searchAround(latLng, city: "", page: page); | ||
| 579 | - | ||
| 580 | - for (var poi in poiList) { | ||
| 581 | - String? title = await poi.title; | ||
| 582 | - String? cityName = await poi.cityName; | ||
| 583 | - String? provinceName = await poi.provinceName; | ||
| 584 | - String? address = await poi.address; | ||
| 585 | - LatLng? latLng = await poi.latLng; | ||
| 586 | - String? bussniss = poi.businessArea; | ||
| 587 | - | ||
| 588 | - list.add(new PoiModel( | ||
| 589 | - title.toString(), | ||
| 590 | - provinceName.toString() + | ||
| 591 | - cityName.toString() + | ||
| 592 | - address.toString() + | ||
| 593 | - bussniss.toString(), | ||
| 594 | - latLng)); | ||
| 595 | - } | ||
| 596 | - | ||
| 597 | - setState(() { | ||
| 598 | - if (showloading) { | ||
| 599 | - isloading = false; | ||
| 600 | - } | ||
| 601 | - }); | ||
| 602 | - } | ||
| 603 | - | ||
| 604 | - // void searchPoiId(String text) async { | ||
| 605 | - // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 606 | - // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 607 | - // Poi? poi = await AmapSearch.instance.searchPoiId( | ||
| 608 | - // text, | ||
| 609 | - // ); | ||
| 610 | - // print(poi); | ||
| 611 | - // } | ||
| 612 | - | ||
| 613 | - // void searchAroundAddress(String text) async { | ||
| 614 | - // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 615 | - // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 616 | - // final poiList = await AmapSearch.instance.searchKeyword( | ||
| 617 | - // text, | ||
| 618 | - // city: "", | ||
| 619 | - // ); | ||
| 620 | - // // final poiList = await AmapSearch.instance.searchAround( | ||
| 621 | - // // LatLng(latitude, longitude), | ||
| 622 | - // // city: "", | ||
| 623 | - // // radius: 100000000000000 | ||
| 624 | - | ||
| 625 | - // // ); | ||
| 626 | - | ||
| 627 | - // list.clear(); | ||
| 628 | - // list.add(poiModel); | ||
| 629 | - // for (var poi in poiList) { | ||
| 630 | - // String? title = await poi.title; | ||
| 631 | - // LatLng? latLng = await poi.latLng; | ||
| 632 | - // String? cityName = await poi.cityName; | ||
| 633 | - // String? provinceName = await poi.provinceName; | ||
| 634 | - // String? address = await poi.address; | ||
| 635 | - // list.add(new PoiModel( | ||
| 636 | - // title.toString(), | ||
| 637 | - // provinceName.toString() + cityName.toString() + address.toString(), | ||
| 638 | - // latLng)); | ||
| 639 | - // } | ||
| 640 | - // setState(() { | ||
| 641 | - // isloading = false; | ||
| 642 | - // FocusScope.of(context).requestFocus(FocusNode()); | ||
| 643 | - // }); | ||
| 644 | - // } | ||
| 645 | -} | ||
| 646 | - | ||
| 647 | -class PoiModel { | ||
| 648 | - LatLng? latLng; | ||
| 649 | - String title; | ||
| 650 | - String? address; | ||
| 651 | - | ||
| 652 | - PoiModel(this.title, this.address, this.latLng); | ||
| 653 | -} | 1 | +// import 'dart:async'; |
| 2 | + | ||
| 3 | +// import 'package:amap_map_fluttify/amap_map_fluttify.dart'; | ||
| 4 | +// import 'package:flutter/cupertino.dart'; | ||
| 5 | + | ||
| 6 | +// import 'package:flutter/material.dart'; | ||
| 7 | + | ||
| 8 | +// import 'package:flutter_easyrefresh/easy_refresh.dart'; | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +// import 'package:one_key/res/colors.dart'; | ||
| 12 | + | ||
| 13 | +// import 'package:one_key/utils/misc.dart'; | ||
| 14 | + | ||
| 15 | +// import 'package:one_key/utils/screen_util.dart'; | ||
| 16 | +// import 'package:one_key/utils/utils.dart'; | ||
| 17 | + | ||
| 18 | +// import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 19 | +// import 'package:permission_handler/permission_handler.dart'; | ||
| 20 | + | ||
| 21 | +// import '../../utils/common_utils.dart'; | ||
| 22 | +// // import 'package:demo/resources/custom_text_style.dart'; | ||
| 23 | +// // import 'package:demo/utils/misc.dart'; | ||
| 24 | + | ||
| 25 | +// // import 'package:demo/widgets/network_state/page_loading.dart'; | ||
| 26 | + | ||
| 27 | +// class MapChoicePointPage extends StatefulWidget { | ||
| 28 | +// final String? long; | ||
| 29 | +// final String? lat; | ||
| 30 | +// MapChoicePointPage({Key? key, this.long, this.lat}) : super(key: key); | ||
| 31 | + | ||
| 32 | +// @override | ||
| 33 | +// _MapChoicePointPageState createState() => _MapChoicePointPageState(); | ||
| 34 | +// } | ||
| 35 | + | ||
| 36 | +// class _MapChoicePointPageState extends State<MapChoicePointPage> { | ||
| 37 | +// AmapController? _controller; | ||
| 38 | +// List<Poi>? poiList; | ||
| 39 | +// static List<PoiModel?> list = []; | ||
| 40 | +// static List<PoiModel> searchlist = []; | ||
| 41 | +// PoiModel? poiModel; | ||
| 42 | +// String keyword = ""; | ||
| 43 | +// String? address = ""; | ||
| 44 | +// bool isloading = true; | ||
| 45 | + | ||
| 46 | +// double latitude = 39.684670899; | ||
| 47 | +// double longitude = 118.17630045; | ||
| 48 | + | ||
| 49 | +// double latitudeLocation = 39.684670899; | ||
| 50 | +// double longitudeLocation = 118.17630045; | ||
| 51 | + | ||
| 52 | +// List<InputTip> inputTipDatas = []; | ||
| 53 | +// int page = 1; | ||
| 54 | +// EasyRefreshController refreshController = EasyRefreshController(); | ||
| 55 | +// bool flag = true; | ||
| 56 | + | ||
| 57 | +// @override | ||
| 58 | +// void initState() { | ||
| 59 | +// super.initState(); | ||
| 60 | + | ||
| 61 | +// if (widget.long != null && widget.long != '' && widget.long != 'null') { | ||
| 62 | +// longitude = double.parse(widget.long!); | ||
| 63 | +// } | ||
| 64 | +// if (widget.lat != null && widget.lat != '' && widget.lat != 'null') { | ||
| 65 | +// latitude = double.parse(widget.lat!); | ||
| 66 | +// } | ||
| 67 | + | ||
| 68 | +// WidgetsBinding.instance.addPostFrameCallback((_) async { | ||
| 69 | +// _requestLocationPermission(); | ||
| 70 | + | ||
| 71 | +// // ama | ||
| 72 | +// // let marker = new AMap.Marker({//添加标记点 | ||
| 73 | +// // position: this.position, | ||
| 74 | +// // map: map | ||
| 75 | +// }); | ||
| 76 | +// } | ||
| 77 | + | ||
| 78 | +// // Future<bool> checkLocationPermission() async { | ||
| 79 | +// // PermissionStatus permissionStatus = await Permission.location.status; | ||
| 80 | +// // if (permissionStatus == PermissionStatus.granted) { | ||
| 81 | +// // return true; | ||
| 82 | +// // } else { | ||
| 83 | +// // return false; | ||
| 84 | +// // } | ||
| 85 | +// // } | ||
| 86 | + | ||
| 87 | +// /// 检查权限并定 | ||
| 88 | +// // _getLocationPermission() async { | ||
| 89 | +// // if (!(await checkPermission(Permission.location))) { | ||
| 90 | +// // //没有定位权限 | ||
| 91 | + | ||
| 92 | +// // //申请定位权限 | ||
| 93 | +// // _requestLocationPermission(); | ||
| 94 | +// // } else { | ||
| 95 | +// // //去定位 | ||
| 96 | +// // _requestLocationPermission(); | ||
| 97 | +// // } | ||
| 98 | +// // } | ||
| 99 | + | ||
| 100 | +// /// 获取定位权限 | ||
| 101 | +// _requestLocationPermission() async { | ||
| 102 | +// await AmapLocation.instance.updatePrivacyShow(true); | ||
| 103 | +// await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 104 | +// bool canLocation = false; | ||
| 105 | + | ||
| 106 | +// if (!(await checkPermission(Permission.location))) { | ||
| 107 | +// //没有定位权限 | ||
| 108 | + | ||
| 109 | +// //申请定位权限 | ||
| 110 | +// canLocation = await requestPermission(Permission.location); | ||
| 111 | +// } else { | ||
| 112 | +// canLocation = true; | ||
| 113 | +// } | ||
| 114 | +// // bool canLocation = await requestPermission(Permission.location); | ||
| 115 | +// // 单次定位 | ||
| 116 | +// if (canLocation) { | ||
| 117 | +// Future.delayed(Duration(milliseconds: 200), () async { | ||
| 118 | +// await AmapLocation.instance.updatePrivacyShow(true); | ||
| 119 | +// await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 120 | +// final location = await AmapLocation.instance.fetchLocation( | ||
| 121 | +// // needAddress: true, | ||
| 122 | +// // mode: LocationAccuracy.High, | ||
| 123 | +// // timeout: Duration(seconds: 10) | ||
| 124 | +// ); | ||
| 125 | + | ||
| 126 | +// if (location.city == null || location.city == '') //网络不好,定位失败 | ||
| 127 | +// { | ||
| 128 | +// // App.sp.setString("lat", "39.684670899"); | ||
| 129 | +// // App.sp.setString("lng", "118.17630045"); | ||
| 130 | +// } else { | ||
| 131 | +// if (widget.long == null || | ||
| 132 | +// widget.long == '' || | ||
| 133 | +// widget.long == 'null') { | ||
| 134 | +// latitude = location.latLng!.latitude; | ||
| 135 | +// longitude = location.latLng!.longitude; | ||
| 136 | +// if (_controller != null) { | ||
| 137 | +// _controller!.setCenterCoordinate(LatLng( | ||
| 138 | +// location.latLng!.latitude, location.latLng!.longitude)); | ||
| 139 | +// } | ||
| 140 | + | ||
| 141 | +// page = 1; | ||
| 142 | + | ||
| 143 | +// _loadData( | ||
| 144 | +// LatLng(location.latLng!.latitude, location.latLng!.longitude)); | ||
| 145 | + | ||
| 146 | +// setState(() {}); | ||
| 147 | +// } | ||
| 148 | +// latitudeLocation = location.latLng!.latitude; | ||
| 149 | +// longitudeLocation = location.latLng!.longitude; | ||
| 150 | +// } | ||
| 151 | +// }); | ||
| 152 | +// } else { | ||
| 153 | +// //无权限 | ||
| 154 | +// } | ||
| 155 | +// } | ||
| 156 | + | ||
| 157 | +// @override | ||
| 158 | +// Widget build(BuildContext context) { | ||
| 159 | +// return Scaffold( | ||
| 160 | +// resizeToAvoidBottomInset: false, //防止底部布局被顶起 | ||
| 161 | +// appBar: SystemAppBar( | ||
| 162 | +// '选择位置信息', | ||
| 163 | +// onTap: () { | ||
| 164 | +// if (Navigator.canPop(context)) { | ||
| 165 | +// Navigator.pop(context); | ||
| 166 | +// } | ||
| 167 | +// }, | ||
| 168 | +// ), | ||
| 169 | + | ||
| 170 | +// body: Column( | ||
| 171 | +// children: <Widget>[ | ||
| 172 | +// // Theme( | ||
| 173 | +// // data: new | ||
| 174 | +// // ThemeData( | ||
| 175 | +// // // primaryColor: MyColours.color_438E93, | ||
| 176 | +// // // hintColor: MyColours.color_438E93), | ||
| 177 | +// // child: | ||
| 178 | +// // Container( | ||
| 179 | +// // color: MyColours.color_438E93, | ||
| 180 | +// // decoration: BoxDecoration( | ||
| 181 | +// // color: MyColours.color_438E93, | ||
| 182 | +// // boxShadow: [ | ||
| 183 | +// // BoxShadow(color: Colors.white, spreadRadius: 1), | ||
| 184 | +// // ], | ||
| 185 | +// // ), | ||
| 186 | + | ||
| 187 | +// // padding: EdgeInsets.all(5), | ||
| 188 | +// // child: | ||
| 189 | + | ||
| 190 | +// // ), | ||
| 191 | +// // ), | ||
| 192 | +// // ListView.builder( | ||
| 193 | +// // shrinkWrap: true, | ||
| 194 | +// // itemCount: inputTipDatas.length, | ||
| 195 | +// // itemBuilder: (context, index) { | ||
| 196 | +// // InputTip inputTip = inputTipDatas[index]; | ||
| 197 | +// // return InkWell( | ||
| 198 | +// // onTap: () { | ||
| 199 | +// // // searchAroundAddress(inputTip.name ?? ''); | ||
| 200 | +// // // searchPoiId(inputTip.poiId ?? ''); | ||
| 201 | +// // // _loadData(inputTip.coordinate ?? | ||
| 202 | +// // // LatLng(latitude, longitude)); | ||
| 203 | +// // }, | ||
| 204 | +// // child: Container( | ||
| 205 | +// // child: Row( | ||
| 206 | +// // children: [ | ||
| 207 | +// // Text( | ||
| 208 | +// // inputTip.name ?? '', | ||
| 209 | +// // style: TextStyle( | ||
| 210 | +// // fontSize: font(15), | ||
| 211 | +// // color: MyColours.color_515151), | ||
| 212 | +// // ), | ||
| 213 | +// // HEmptyView(10), | ||
| 214 | +// // Expanded( | ||
| 215 | +// // child: Text( | ||
| 216 | +// // (inputTip.district ?? '') + | ||
| 217 | +// // (inputTip.address ?? ''), | ||
| 218 | +// // style: TextStyle( | ||
| 219 | +// // fontSize: font(13), | ||
| 220 | +// // color: MyColours.color_999999), | ||
| 221 | +// // ), | ||
| 222 | +// // ), | ||
| 223 | +// // ], | ||
| 224 | +// // ))); | ||
| 225 | +// // }) | ||
| 226 | +// // ], | ||
| 227 | +// // ), | ||
| 228 | + | ||
| 229 | +// Stack( | ||
| 230 | +// children: [ | ||
| 231 | +// Container( | ||
| 232 | +// height: w(300), | ||
| 233 | +// child: Stack( | ||
| 234 | +// children: <Widget>[ | ||
| 235 | +// AmapView( | ||
| 236 | +// showZoomControl: false, | ||
| 237 | + | ||
| 238 | +// /// 是否显示指南针控件 | ||
| 239 | +// showCompass: true, | ||
| 240 | + | ||
| 241 | +// /// 是否显示比例尺控件 | ||
| 242 | +// showScaleControl: true, | ||
| 243 | + | ||
| 244 | +// /// 是否使能缩放手势 | ||
| 245 | +// zoomGesturesEnabled: true, | ||
| 246 | + | ||
| 247 | +// /// 是否使能滚动手势 | ||
| 248 | +// scrollGesturesEnabled: true, | ||
| 249 | + | ||
| 250 | +// /// 是否使能旋转手势 | ||
| 251 | +// rotateGestureEnabled: false, | ||
| 252 | +// centerCoordinate: LatLng(latitude, longitude), | ||
| 253 | +// maskDelay: Duration(milliseconds: 500), | ||
| 254 | +// zoomLevel: 19, | ||
| 255 | +// onMapCreated: (controller) async { | ||
| 256 | +// _controller = controller; | ||
| 257 | +// _controller! | ||
| 258 | +// .setCenterCoordinate(LatLng(latitude, longitude)); | ||
| 259 | +// // if (await requestPermission(PermissionGroup.location)) { | ||
| 260 | +// // await controller.showMyLocation(true); | ||
| 261 | +// // await controller?.showLocateControl(true); | ||
| 262 | +// // final latLng = await _controller?.getLocation( | ||
| 263 | +// // delay: Duration(seconds: 2)); | ||
| 264 | +// // await enableFluttifyLog(false); // 关闭log | ||
| 265 | +// // _loadData(latLng); | ||
| 266 | +// // } else { | ||
| 267 | +// // //无权限 | ||
| 268 | +// // _showLocPemWidget(); | ||
| 269 | +// // } | ||
| 270 | +// }, | ||
| 271 | +// // markers: [], | ||
| 272 | +// onMapMoveEnd: (MapMove move) async { | ||
| 273 | +// latitude = move.coordinate!.latitude; | ||
| 274 | +// longitude = move.coordinate!.longitude; | ||
| 275 | +// page = 1; | ||
| 276 | +// _loadData(move.coordinate!); | ||
| 277 | +// }, | ||
| 278 | +// ), | ||
| 279 | +// Center( | ||
| 280 | +// child: Icon( | ||
| 281 | +// Icons.place, | ||
| 282 | +// size: w(32), | ||
| 283 | +// color: Color(0xFFFF0000), | ||
| 284 | +// ), | ||
| 285 | +// ), | ||
| 286 | +// Positioned( | ||
| 287 | +// right: w(10), | ||
| 288 | +// bottom: w(10), | ||
| 289 | +// child: InkWell( | ||
| 290 | +// onTap: () { | ||
| 291 | +// _controller!.setCenterCoordinate( | ||
| 292 | +// LatLng(latitudeLocation, longitudeLocation)); | ||
| 293 | +// }, | ||
| 294 | +// child: Container( | ||
| 295 | +// decoration: BoxDecoration( | ||
| 296 | +// color: MyColours.color_ffffff, | ||
| 297 | +// borderRadius: BorderRadius.circular(r(5))), | ||
| 298 | +// padding: EdgeInsets.all(w(5)), | ||
| 299 | +// child: Image.asset( | ||
| 300 | +// Utils.getImgPath('location_map'), | ||
| 301 | +// width: w(25), | ||
| 302 | +// ), | ||
| 303 | +// )), | ||
| 304 | +// ) | ||
| 305 | +// ], | ||
| 306 | +// ), | ||
| 307 | +// ), | ||
| 308 | +// Positioned( | ||
| 309 | +// top: w(10), | ||
| 310 | +// left: w(20), | ||
| 311 | +// right: w(20), | ||
| 312 | +// child: Container( | ||
| 313 | +// // height: w(45), | ||
| 314 | +// padding: EdgeInsets.symmetric(vertical: w(10)), | ||
| 315 | +// decoration: BoxDecoration( | ||
| 316 | +// color: Colors.white, | ||
| 317 | +// borderRadius: BorderRadius.circular(r(10))), | ||
| 318 | +// child: TextField( | ||
| 319 | +// textAlignVertical: TextAlignVertical.center, | ||
| 320 | +// style: TextStyle( | ||
| 321 | +// color: MyColours.color_515151, | ||
| 322 | +// fontSize: font(15), | ||
| 323 | +// ), | ||
| 324 | +// controller: | ||
| 325 | +// TextEditingController.fromValue(TextEditingValue( | ||
| 326 | +// // 设置内容 | ||
| 327 | +// text: keyword, | ||
| 328 | +// selection: TextSelection.fromPosition(TextPosition( | ||
| 329 | +// affinity: TextAffinity.downstream, | ||
| 330 | +// offset: keyword.length)), | ||
| 331 | +// // 保持光标在最后 | ||
| 332 | +// )), | ||
| 333 | +// decoration: InputDecoration( | ||
| 334 | +// // border: b, | ||
| 335 | +// // border: OutlineInputBorder( | ||
| 336 | +// // borderRadius: BorderRadius.all(Radius.circular(40)), | ||
| 337 | +// // ), | ||
| 338 | +// border: OutlineInputBorder(borderSide: BorderSide.none), | ||
| 339 | +// hintText: '输入关键字', | ||
| 340 | +// isCollapsed: true, | ||
| 341 | + | ||
| 342 | +// hintStyle: TextStyle( | ||
| 343 | +// color: MyColours.color_999999, fontSize: font(15)), | ||
| 344 | +// // contentPadding: const EdgeInsets.symmetric( | ||
| 345 | +// // vertical: 8, horizontal: 1), | ||
| 346 | +// prefixIconConstraints: BoxConstraints(maxWidth: w(40)), | ||
| 347 | +// prefixIcon: Padding( | ||
| 348 | +// padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 349 | +// child: SizedBox( | ||
| 350 | +// width: w(30), | ||
| 351 | +// child: Image.asset( | ||
| 352 | +// Utils.getImgPath('search_black'), | ||
| 353 | +// ))), | ||
| 354 | +// suffixIconConstraints: BoxConstraints(maxWidth: w(32)), | ||
| 355 | +// suffixIcon: InkWell( | ||
| 356 | +// child: Padding( | ||
| 357 | +// padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 358 | +// child: SizedBox( | ||
| 359 | +// width: w(22), | ||
| 360 | +// child: Image.asset( | ||
| 361 | +// Utils.getImgPath('delete_black'), | ||
| 362 | +// ))), | ||
| 363 | +// onTap: () { | ||
| 364 | +// keyword = ""; | ||
| 365 | +// setState(() {}); | ||
| 366 | +// }, | ||
| 367 | +// ), | ||
| 368 | +// fillColor: Colors.white, | ||
| 369 | +// filled: true, | ||
| 370 | +// ), | ||
| 371 | + | ||
| 372 | +// inputFormatters: [], | ||
| 373 | +// //内容改变的回调 | ||
| 374 | +// onChanged: (text) { | ||
| 375 | +// print('change $text'); | ||
| 376 | +// keyword = text; | ||
| 377 | + | ||
| 378 | +// //搜索 | ||
| 379 | + | ||
| 380 | +// JhCommonUtils.debounce( | ||
| 381 | +// () => _fetchInputTips(text.toString())); | ||
| 382 | +// }, | ||
| 383 | +// //内容提交(按回车)的回调 | ||
| 384 | +// onSubmitted: (text) { | ||
| 385 | +// print('submit $text'); | ||
| 386 | +// // 触发关闭弹出来的键盘。 | ||
| 387 | +// keyword = text; | ||
| 388 | +// FocusScope.of(context).requestFocus(FocusNode()); | ||
| 389 | +// setState(() { | ||
| 390 | +// // isloading = true; | ||
| 391 | +// }); | ||
| 392 | + | ||
| 393 | +// // _fetchInputTips(text.toString()); | ||
| 394 | + | ||
| 395 | +// // searchAroundAddress(text.toString()); | ||
| 396 | +// }, | ||
| 397 | +// //按回车时调用 | ||
| 398 | +// onEditingComplete: () { | ||
| 399 | +// print('onEditingComplete'); | ||
| 400 | +// }, | ||
| 401 | +// ), | ||
| 402 | +// ), | ||
| 403 | +// ) | ||
| 404 | +// ], | ||
| 405 | +// ), | ||
| 406 | + | ||
| 407 | +// Expanded( | ||
| 408 | +// flex: 1, | ||
| 409 | +// child: Visibility( | ||
| 410 | +// visible: !isloading, | ||
| 411 | +// maintainSize: false, | ||
| 412 | +// maintainSemantics: false, | ||
| 413 | +// maintainInteractivity: false, | ||
| 414 | +// replacement: Center( | ||
| 415 | +// child: CupertinoActivityIndicator(), | ||
| 416 | +// ), | ||
| 417 | +// child: EasyRefresh.custom( | ||
| 418 | +// controller: refreshController, | ||
| 419 | +// slivers: [ | ||
| 420 | +// SliverList( | ||
| 421 | +// delegate: SliverChildBuilderDelegate( | ||
| 422 | +// (BuildContext context, int position) { | ||
| 423 | +// print("itemBuilder" + list.length.toString()); | ||
| 424 | +// PoiModel item = list[position]!; | ||
| 425 | +// return InkWell( | ||
| 426 | +// child: Column( | ||
| 427 | +// children: <Widget>[ | ||
| 428 | +// Container( | ||
| 429 | +// margin: EdgeInsets.only( | ||
| 430 | +// top: 8, bottom: 5, left: 10), | ||
| 431 | +// child: Row( | ||
| 432 | +// children: <Widget>[ | ||
| 433 | +// Icon( | ||
| 434 | +// Icons.place, | ||
| 435 | +// size: 20.0, | ||
| 436 | +// color: position == 0 | ||
| 437 | +// ? Colors.green | ||
| 438 | +// : Colors.grey, | ||
| 439 | +// ), | ||
| 440 | +// Expanded( | ||
| 441 | +// child: Text(item.title, | ||
| 442 | +// style: TextStyle( | ||
| 443 | +// fontSize: 16, | ||
| 444 | +// color: position == 0 | ||
| 445 | +// ? Colors.green | ||
| 446 | +// : Color(0xFF787878)))) | ||
| 447 | +// ], | ||
| 448 | +// ), | ||
| 449 | +// ), | ||
| 450 | +// Container( | ||
| 451 | +// margin: EdgeInsets.only( | ||
| 452 | +// top: 5, bottom: 5, left: 18), | ||
| 453 | +// alignment: Alignment.centerLeft, | ||
| 454 | +// child: Text( | ||
| 455 | +// item.address!, | ||
| 456 | +// style: TextStyle( | ||
| 457 | +// fontSize: 14, | ||
| 458 | +// color: Color(0xFF646464), | ||
| 459 | +// ), | ||
| 460 | +// ), | ||
| 461 | +// ), | ||
| 462 | +// Divider( | ||
| 463 | +// height: 1, | ||
| 464 | +// ) | ||
| 465 | +// ], | ||
| 466 | +// ), | ||
| 467 | +// onTap: () async { | ||
| 468 | +// // await _controller.setCenterCoordinate( | ||
| 469 | +// // LatLng(item.latLng.latitude, item.latLng.longitude), | ||
| 470 | +// // zoomLevel: 16); | ||
| 471 | +// if (Navigator.canPop(context)) { | ||
| 472 | +// Navigator.pop(context, { | ||
| 473 | +// 'address': item.address, | ||
| 474 | +// 'lat': item.latLng!.latitude.toString(), | ||
| 475 | +// 'lng': item.latLng!.longitude.toString() | ||
| 476 | +// }); | ||
| 477 | +// } | ||
| 478 | +// }, | ||
| 479 | +// ); | ||
| 480 | +// }, | ||
| 481 | +// childCount: list.length, | ||
| 482 | +// ), | ||
| 483 | +// ) | ||
| 484 | +// ], | ||
| 485 | +// onRefresh: () async { | ||
| 486 | +// if (flag) { | ||
| 487 | +// page = 1; | ||
| 488 | +// _loadData(LatLng(latitude, longitude)); | ||
| 489 | +// } | ||
| 490 | +// }, | ||
| 491 | +// onLoad: () async { | ||
| 492 | +// if (flag) { | ||
| 493 | +// page++; | ||
| 494 | +// _loadData(LatLng(latitude, longitude), | ||
| 495 | +// showloading: false); | ||
| 496 | +// } | ||
| 497 | +// }, | ||
| 498 | +// )), | ||
| 499 | +// ), | ||
| 500 | +// ], | ||
| 501 | +// ), | ||
| 502 | +// ); | ||
| 503 | +// } | ||
| 504 | + | ||
| 505 | +// _fetchInputTips(String text) async { | ||
| 506 | +// flag = false; | ||
| 507 | +// page = 1; | ||
| 508 | +// // setState(() { | ||
| 509 | +// // isloading = true; | ||
| 510 | +// // }); | ||
| 511 | + | ||
| 512 | +// /// 逆地理编码(坐标转地址) | ||
| 513 | +// /// | ||
| 514 | +// /// | ||
| 515 | +// await AmapLocation.instance.updatePrivacyShow(true); | ||
| 516 | +// await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 517 | + | ||
| 518 | +// LatLng latLng = LatLng(latitude, longitude); | ||
| 519 | +// ReGeocode reGeocodeList = await AmapSearch.instance.searchReGeocode(latLng); | ||
| 520 | + | ||
| 521 | +// // print(await reGeocodeList.toFutureString()); | ||
| 522 | +// address = reGeocodeList.formatAddress; | ||
| 523 | + | ||
| 524 | +// await AmapLocation.instance.updatePrivacyShow(true); | ||
| 525 | +// await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 526 | +// inputTipDatas = await AmapSearch.instance.fetchInputTips( | ||
| 527 | +// text, | ||
| 528 | +// city: "", | ||
| 529 | +// ); | ||
| 530 | +// print(inputTipDatas); | ||
| 531 | + | ||
| 532 | +// poiModel = new PoiModel("当前位置", address, latLng); | ||
| 533 | +// list.clear(); | ||
| 534 | +// list.add(poiModel); | ||
| 535 | +// for (var inputTip in inputTipDatas) { | ||
| 536 | +// String? title = await inputTip.name ?? ''; | ||
| 537 | +// String? cityStr = | ||
| 538 | +// await (inputTip.district ?? '') + (inputTip.address ?? ''); | ||
| 539 | + | ||
| 540 | +// LatLng? latLng = await inputTip.coordinate; | ||
| 541 | + | ||
| 542 | +// list.add(new PoiModel(title.toString(), cityStr, latLng)); | ||
| 543 | +// } | ||
| 544 | + | ||
| 545 | + | ||
| 546 | +// print(list); | ||
| 547 | + | ||
| 548 | +// setState(() { | ||
| 549 | +// // isloading = false; | ||
| 550 | +// }); | ||
| 551 | +// } | ||
| 552 | + | ||
| 553 | +// void _loadData(LatLng latLng, {showloading = true}) async { | ||
| 554 | +// flag = true; | ||
| 555 | +// setState(() { | ||
| 556 | +// if (showloading) { | ||
| 557 | +// isloading = true; | ||
| 558 | +// } | ||
| 559 | +// }); | ||
| 560 | + | ||
| 561 | +// /// 逆地理编码(坐标转地址) | ||
| 562 | +// /// | ||
| 563 | +// /// | ||
| 564 | + | ||
| 565 | +// await AmapLocation.instance.updatePrivacyShow(true); | ||
| 566 | +// await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 567 | +// if (page == 1) { | ||
| 568 | +// ReGeocode reGeocodeList = await AmapSearch.instance.searchReGeocode( | ||
| 569 | +// latLng, | ||
| 570 | +// ); | ||
| 571 | +// // print(await reGeocodeList.toFutureString()); | ||
| 572 | +// address = reGeocodeList.formatAddress; | ||
| 573 | +// poiModel = new PoiModel("当前位置", address, latLng); | ||
| 574 | +// list.clear(); | ||
| 575 | +// list.add(poiModel); | ||
| 576 | +// } | ||
| 577 | +// final poiList = | ||
| 578 | +// await AmapSearch.instance.searchAround(latLng, city: "", page: page); | ||
| 579 | + | ||
| 580 | +// for (var poi in poiList) { | ||
| 581 | +// String? title = await poi.title; | ||
| 582 | +// String? cityName = await poi.cityName; | ||
| 583 | +// String? provinceName = await poi.provinceName; | ||
| 584 | +// String? address = await poi.address; | ||
| 585 | +// LatLng? latLng = await poi.latLng; | ||
| 586 | +// String? bussniss = poi.businessArea; | ||
| 587 | + | ||
| 588 | +// list.add(new PoiModel( | ||
| 589 | +// title.toString(), | ||
| 590 | +// provinceName.toString() + | ||
| 591 | +// cityName.toString() + | ||
| 592 | +// address.toString() + | ||
| 593 | +// bussniss.toString(), | ||
| 594 | +// latLng)); | ||
| 595 | +// } | ||
| 596 | + | ||
| 597 | +// setState(() { | ||
| 598 | +// if (showloading) { | ||
| 599 | +// isloading = false; | ||
| 600 | +// } | ||
| 601 | +// }); | ||
| 602 | +// } | ||
| 603 | + | ||
| 604 | +// // void searchPoiId(String text) async { | ||
| 605 | +// // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 606 | +// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 607 | +// // Poi? poi = await AmapSearch.instance.searchPoiId( | ||
| 608 | +// // text, | ||
| 609 | +// // ); | ||
| 610 | +// // print(poi); | ||
| 611 | +// // } | ||
| 612 | + | ||
| 613 | +// // void searchAroundAddress(String text) async { | ||
| 614 | +// // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 615 | +// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 616 | +// // final poiList = await AmapSearch.instance.searchKeyword( | ||
| 617 | +// // text, | ||
| 618 | +// // city: "", | ||
| 619 | +// // ); | ||
| 620 | +// // // final poiList = await AmapSearch.instance.searchAround( | ||
| 621 | +// // // LatLng(latitude, longitude), | ||
| 622 | +// // // city: "", | ||
| 623 | +// // // radius: 100000000000000 | ||
| 624 | + | ||
| 625 | +// // // ); | ||
| 626 | + | ||
| 627 | +// // list.clear(); | ||
| 628 | +// // list.add(poiModel); | ||
| 629 | +// // for (var poi in poiList) { | ||
| 630 | +// // String? title = await poi.title; | ||
| 631 | +// // LatLng? latLng = await poi.latLng; | ||
| 632 | +// // String? cityName = await poi.cityName; | ||
| 633 | +// // String? provinceName = await poi.provinceName; | ||
| 634 | +// // String? address = await poi.address; | ||
| 635 | +// // list.add(new PoiModel( | ||
| 636 | +// // title.toString(), | ||
| 637 | +// // provinceName.toString() + cityName.toString() + address.toString(), | ||
| 638 | +// // latLng)); | ||
| 639 | +// // } | ||
| 640 | +// // setState(() { | ||
| 641 | +// // isloading = false; | ||
| 642 | +// // FocusScope.of(context).requestFocus(FocusNode()); | ||
| 643 | +// // }); | ||
| 644 | +// // } | ||
| 645 | +// } | ||
| 646 | + | ||
| 647 | +// class PoiModel { | ||
| 648 | +// LatLng? latLng; | ||
| 649 | +// String title; | ||
| 650 | +// String? address; | ||
| 651 | + | ||
| 652 | +// PoiModel(this.title, this.address, this.latLng); | ||
| 653 | +// } |
| 1 | -// import 'dart:async'; | ||
| 2 | -// // import 'dart:js_interop'; | 1 | +import 'dart:async'; |
| 2 | +// import 'dart:js_interop'; | ||
| 3 | 3 | ||
| 4 | -// import 'package:flutter/material.dart'; | 4 | +import 'package:flutter/material.dart'; |
| 5 | 5 | ||
| 6 | -// import 'package:csp_amap_flutter_map/csp_amap_flutter_map.dart'; | ||
| 7 | -// import 'package:csp_amap_flutter_location/amap_flutter_location.dart'; | ||
| 8 | -// import 'package:csp_amap_flutter_location/amap_location_option.dart'; | ||
| 9 | -// import 'package:flutter/cupertino.dart'; | 6 | +import 'package:csp_amap_flutter_map/csp_amap_flutter_map.dart'; |
| 7 | +import 'package:csp_amap_flutter_location/amap_flutter_location.dart'; | ||
| 8 | +import 'package:csp_amap_flutter_location/amap_location_option.dart'; | ||
| 9 | +import 'package:flutter/cupertino.dart'; | ||
| 10 | 10 | ||
| 11 | -// // import 'package:flutter/material.dart'; | 11 | +// import 'package:flutter/material.dart'; |
| 12 | 12 | ||
| 13 | -// import 'package:csp_amap_flutter_base/csp_amap_flutter_base.dart'; | 13 | +import 'package:csp_amap_flutter_base/csp_amap_flutter_base.dart'; |
| 14 | 14 | ||
| 15 | -// import 'package:flutter_easyrefresh/easy_refresh.dart'; | ||
| 16 | - | ||
| 17 | -// import 'package:one_key/pages/create_store/const_config.dart'; | ||
| 18 | -// import 'package:one_key/pages/create_store/map_inputs_model.dart'; | ||
| 19 | - | ||
| 20 | -// import 'package:one_key/res/colors.dart'; | ||
| 21 | -// import 'package:one_key/utils/common_utils.dart'; | ||
| 22 | - | ||
| 23 | -// import 'package:one_key/utils/misc.dart'; | ||
| 24 | - | ||
| 25 | -// import 'package:one_key/utils/screen_util.dart'; | ||
| 26 | -// import 'package:one_key/utils/utils.dart'; | ||
| 27 | - | ||
| 28 | -// import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 29 | -// import 'package:permission_handler/permission_handler.dart'; | ||
| 30 | - | ||
| 31 | -// // import '../../utils/common_utils.dart'; | ||
| 32 | -// // import 'package:demo/resources/custom_text_style.dart'; | ||
| 33 | -// // import 'package:demo/utils/misc.dart'; | ||
| 34 | - | ||
| 35 | -// // import 'package:demo/widgets/network_state/page_loading.dart'; | ||
| 36 | - | ||
| 37 | -// class MapChoicePointPage extends StatefulWidget { | ||
| 38 | -// final String? long; | ||
| 39 | -// final String? lat; | ||
| 40 | -// MapChoicePointPage({Key? key, this.long, this.lat}) : super(key: key); | ||
| 41 | - | ||
| 42 | -// @override | ||
| 43 | -// _MapChoicePointPageState createState() => _MapChoicePointPageState(); | ||
| 44 | -// } | ||
| 45 | - | ||
| 46 | -// class _MapChoicePointPageState extends State<MapChoicePointPage> { | ||
| 47 | -// late AMapController _mapController; | ||
| 48 | -// final double _minZoom = 3; | ||
| 49 | -// final double _maxZoom = 20; | ||
| 50 | -// String? _currentZoom; | ||
| 51 | -// // List<Poi>? poiList; | ||
| 52 | -// static List<PoiModel?> list = []; | ||
| 53 | -// static List<PoiModel> searchlist = []; | ||
| 54 | -// PoiModel? poiModel; | ||
| 55 | -// String keyword = ""; | ||
| 56 | -// String? address = ""; | ||
| 57 | -// bool isloading = true; | ||
| 58 | - | ||
| 59 | -// double latitude = 39.684670899; | ||
| 60 | -// double longitude = 118.17630045; | ||
| 61 | - | ||
| 62 | -// double latitudeLocation = 39.684670899; | ||
| 63 | -// double longitudeLocation = 118.17630045; | ||
| 64 | - | ||
| 65 | -// List<MapInputsModel> inputTipDatas = []; | ||
| 66 | -// int page = 1; | ||
| 67 | -// EasyRefreshController refreshController = EasyRefreshController(); | ||
| 68 | -// bool flag = true; | ||
| 69 | - | ||
| 70 | -// /// 存储定位结果 | ||
| 71 | -// Map<String, Object>? _locationResult; | ||
| 72 | - | ||
| 73 | -// /// 定位结果监听器 | ||
| 74 | -// StreamSubscription<Map<String, Object>>? _locationListener; | ||
| 75 | - | ||
| 76 | -// /// 地理位置解析结果监听器 | ||
| 77 | -// StreamSubscription<Map<String, Object>>? _geocodeSearchListener; | ||
| 78 | - | ||
| 79 | -// /// 高德定位插件实例 | ||
| 80 | -// final AMapFlutterLocation _locationPlugin = new AMapFlutterLocation(); | ||
| 81 | - | ||
| 82 | -// @override | ||
| 83 | -// void initState() { | ||
| 84 | -// super.initState(); | ||
| 85 | - | ||
| 86 | -// if (widget.long != null && widget.long != '' && widget.long != 'null') { | ||
| 87 | -// longitude = double.parse(widget.long!); | ||
| 88 | -// } | ||
| 89 | -// if (widget.lat != null && widget.lat != '' && widget.lat != 'null') { | ||
| 90 | -// latitude = double.parse(widget.lat!); | ||
| 91 | -// } | ||
| 92 | - | ||
| 93 | -// WidgetsBinding.instance.addPostFrameCallback((_) async { | ||
| 94 | -// AMapInitializer.init(context, apiKey: ConstConfig.amapApiKeys); | ||
| 95 | -// AMapInitializer.updatePrivacyAgree(ConstConfig.amapPrivacyStatement); | ||
| 96 | - | ||
| 97 | -// AMapFlutterLocation.setApiKey("1dbf56e2e8a4d0e4cdc2df9efd36bc71", | ||
| 98 | -// "dfb64c0463cb53927914364b5c09aba0", | ||
| 99 | -// ohosKey: "7c2081e92ec65bfffa2df0a5464f0c7b"); | ||
| 100 | - | ||
| 101 | -// /// 设置是否已经包含高德隐私政策并弹窗展示显示用户查看,如果未包含或者没有弹窗展示,高德定位SDK将不会工作 | ||
| 102 | -// /// | ||
| 103 | -// /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy | ||
| 104 | -// /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b> | ||
| 105 | -// /// | ||
| 106 | -// /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy | ||
| 107 | -// /// | ||
| 108 | -// /// [hasContains] 隐私声明中是否包含高德隐私政策说明 | ||
| 109 | -// /// | ||
| 110 | -// /// [hasShow] 隐私权政策是否弹窗展示告知用户 | ||
| 111 | -// AMapFlutterLocation.updatePrivacyShow(true, true); | ||
| 112 | - | ||
| 113 | -// /// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作 | ||
| 114 | -// /// | ||
| 115 | -// /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy | ||
| 116 | -// /// | ||
| 117 | -// /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b> | ||
| 118 | -// /// | ||
| 119 | -// /// [hasAgree] 隐私权政策是否已经取得用户同意 | ||
| 120 | -// AMapFlutterLocation.updatePrivacyAgree(true); | ||
| 121 | -// _requestLocationPermission(); | ||
| 122 | - | ||
| 123 | -// // ama | ||
| 124 | -// // let marker = new AMap.Marker({//添加标记点 | ||
| 125 | -// // position: this.position, | ||
| 126 | -// // map: map | ||
| 127 | -// }); | ||
| 128 | - | ||
| 129 | -// _geocodeSearchListener = _locationPlugin | ||
| 130 | -// .onGeocodeSearchChange() | ||
| 131 | -// .listen((Map<String, Object> result) { | ||
| 132 | -// // setState(() { | ||
| 133 | - | ||
| 134 | -// if (result.containsKey('errorCode')) { | ||
| 135 | -// Utils.showToast(result['errorInfo'].toString()); | ||
| 136 | -// } else { | ||
| 137 | -// _locationResult = result; | ||
| 138 | - | ||
| 139 | -// print(_locationResult); | ||
| 140 | -// } | ||
| 141 | -// }); | ||
| 142 | - | ||
| 143 | -// /// 注册定位结果监听 | ||
| 144 | -// /// 通过监听器接收定位结果并更新UI | ||
| 145 | -// _locationListener = _locationPlugin | ||
| 146 | -// .onLocationChanged() | ||
| 147 | -// .listen((Map<String, Object> result) { | ||
| 148 | -// // setState(() { | ||
| 149 | - | ||
| 150 | -// if (result.containsKey('errorCode')) { | ||
| 151 | -// Utils.showToast(result['errorInfo'].toString()); | ||
| 152 | -// } else { | ||
| 153 | -// _locationResult = result; | ||
| 154 | - | ||
| 155 | -// print(_locationResult); | ||
| 156 | - | ||
| 157 | -// if (result['latitude'] == null || result['latitude'] == '') //网络不好,定位失败 | ||
| 158 | -// { | ||
| 159 | -// // App.sp.setString("lat", "39.684670899"); | ||
| 160 | -// // App.sp.setString("lng", "118.17630045"); | ||
| 161 | -// } else { | ||
| 162 | -// if (widget.long == null || | ||
| 163 | -// widget.long == '' || | ||
| 164 | -// widget.long == 'null') { | ||
| 165 | -// latitude = double.parse(result['latitude'].toString()); | ||
| 166 | -// longitude = double.parse(result['longitude'].toString()); | ||
| 167 | -// // if (_mapController != null) { | ||
| 168 | -// _mapController.moveCamera( | ||
| 169 | -// CameraUpdate.newLatLng(LatLng(latitude, longitude))); | ||
| 170 | - | ||
| 171 | -// // } | ||
| 172 | -// page = 1; | ||
| 173 | - | ||
| 174 | -// // _loadData(LatLng(latitude, longitude)); | ||
| 175 | - | ||
| 176 | -// // setState(() {}); | ||
| 177 | -// } | ||
| 178 | -// latitudeLocation = latitude; | ||
| 179 | -// longitudeLocation = longitude; | ||
| 180 | -// _mapController.moveCamera( | ||
| 181 | -// CameraUpdate.newLatLng(LatLng(latitudeLocation, longitudeLocation)), | ||
| 182 | -// animated: true, | ||
| 183 | -// ); | ||
| 184 | -// _loadData(LatLng(latitude, longitude)); | ||
| 185 | -// } | ||
| 186 | -// } | ||
| 187 | -// }); | ||
| 188 | -// } | ||
| 189 | - | ||
| 190 | -// @override | ||
| 191 | -// void dispose() { | ||
| 192 | -// super.dispose(); | ||
| 193 | - | ||
| 194 | -// /// 移除定位监听 | ||
| 195 | -// /// 防止内存泄漏 | ||
| 196 | -// if (null != _locationListener) { | ||
| 197 | -// _locationListener?.cancel(); | ||
| 198 | -// } | ||
| 199 | - | ||
| 200 | -// if (null != _geocodeSearchListener) { | ||
| 201 | -// _geocodeSearchListener?.cancel(); | ||
| 202 | -// } | ||
| 203 | - | ||
| 204 | -// /// 销毁定位 | ||
| 205 | -// /// 释放定位资源 | ||
| 206 | -// _locationPlugin.destroy(); | ||
| 207 | -// } | ||
| 208 | - | ||
| 209 | -// // Future<bool> checkLocationPermission() async { | ||
| 210 | -// // PermissionStatus permissionStatus = await Permission.location.status; | ||
| 211 | -// // if (permissionStatus == PermissionStatus.granted) { | ||
| 212 | -// // return true; | ||
| 213 | -// // } else { | ||
| 214 | -// // return false; | ||
| 215 | -// // } | ||
| 216 | -// // } | ||
| 217 | - | ||
| 218 | -// /// 检查权限并定 | ||
| 219 | -// // _getLocationPermission() async { | ||
| 220 | -// // if (!(await checkPermission(Permission.location))) { | ||
| 221 | -// // //没有定位权限 | ||
| 222 | - | ||
| 223 | -// // //申请定位权限 | ||
| 224 | -// // _requestLocationPermission(); | ||
| 225 | -// // } else { | ||
| 226 | -// // //去定位 | ||
| 227 | -// // _requestLocationPermission(); | ||
| 228 | -// // } | ||
| 229 | -// // } | ||
| 230 | - | ||
| 231 | -// /// 设置定位参数 | ||
| 232 | -// /// 配置定位选项,如精度、频率等 | ||
| 233 | -// void _setLocationOption() { | ||
| 234 | -// AMapLocationOption locationOption = new AMapLocationOption(); | ||
| 235 | - | ||
| 236 | -// /// 是否单次定位 | ||
| 237 | -// /// false表示连续定位 | ||
| 238 | -// locationOption.onceLocation = true; | ||
| 239 | - | ||
| 240 | -// /// 是否需要返回逆地理信息 | ||
| 241 | -// /// true表示需要返回地址信息 | ||
| 242 | -// locationOption.needAddress = true; | ||
| 243 | - | ||
| 244 | -// /// 是否需要返回逆地理编码信息 | ||
| 245 | -// locationOption.locatingWithReGeocode = true; | ||
| 246 | - | ||
| 247 | -// /// 逆地理信息的语言类型 | ||
| 248 | -// /// 默认为自动适配当前系统语言 | ||
| 249 | -// locationOption.geoLanguage = GeoLanguage.DEFAULT; | ||
| 250 | - | ||
| 251 | -// /// iOS 14定位精度权限设置 | ||
| 252 | -// /// 设置为模糊定位精度 | ||
| 253 | -// locationOption.desiredLocationAccuracyAuthorizationMode = | ||
| 254 | -// AMapLocationAccuracyAuthorizationMode.ReduceAccuracy; | ||
| 255 | - | ||
| 256 | -// /// iOS 14精确定位目的key | ||
| 257 | -// /// 需要与info.plist中配置一致 | ||
| 258 | -// locationOption.fullAccuracyPurposeKey = "AMapLocationScene"; | ||
| 259 | - | ||
| 260 | -// /// 设置Android端连续定位的定位间隔 | ||
| 261 | -// /// 单位:毫秒 | ||
| 262 | -// locationOption.locationInterval = 2000; | ||
| 263 | - | ||
| 264 | -// /// 设置Android端的定位模式 | ||
| 265 | -// /// 可选值: | ||
| 266 | -// /// [AMapLocationMode.Battery_Saving] 低功耗模式 | ||
| 267 | -// /// [AMapLocationMode.Device_Sensors] 仅设备模式 | ||
| 268 | -// /// [AMapLocationMode.Hight_Accuracy] 高精度模式 | ||
| 269 | -// locationOption.locationMode = AMapLocationMode.Hight_Accuracy; | ||
| 270 | - | ||
| 271 | -// /// 设置iOS端的定位最小更新距离 | ||
| 272 | -// /// -1表示不限制距离 | ||
| 273 | -// locationOption.distanceFilter = -1; | ||
| 274 | - | ||
| 275 | -// /// 设置iOS端期望的定位精度 | ||
| 276 | -// /// 可选值: | ||
| 277 | -// /// [DesiredAccuracy.Best] 最高精度 | ||
| 278 | -// /// [DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 | ||
| 279 | -// /// [DesiredAccuracy.NearestTenMeters] 10米 | ||
| 280 | -// /// [DesiredAccuracy.Kilometer] 1000米 | ||
| 281 | -// /// [DesiredAccuracy.ThreeKilometers] 3000米 | ||
| 282 | -// locationOption.desiredAccuracy = DesiredAccuracy.Best; | ||
| 283 | - | ||
| 284 | -// /// 设置iOS端是否允许系统暂停定位 | ||
| 285 | -// /// false表示不允许系统暂停定位 | ||
| 286 | -// locationOption.pausesLocationUpdatesAutomatically = false; | ||
| 287 | - | ||
| 288 | -// /// 将定位参数设置给定位插件 | ||
| 289 | -// _locationPlugin.setLocationOption(locationOption); | ||
| 290 | -// } | ||
| 291 | - | ||
| 292 | -// /// 获取定位权限 | ||
| 293 | -// _requestLocationPermission() async { | ||
| 294 | -// /// [hasShow] 隐私权政策是否弹窗展示告知用户 | ||
| 295 | -// AMapFlutterLocation.updatePrivacyShow(true, true); | ||
| 296 | - | ||
| 297 | -// /// [hasAgree] 隐私权政策是否已经取得用户同意 | ||
| 298 | -// AMapFlutterLocation.updatePrivacyAgree(true); | ||
| 299 | -// // await AMapFlutterLocation.instance.updatePrivacyShow(true); | ||
| 300 | -// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 301 | -// bool canLocation = false; | ||
| 302 | - | ||
| 303 | -// if (!(await checkPermission(Permission.location))) { | ||
| 304 | -// //没有定位权限 | ||
| 305 | - | ||
| 306 | -// //申请定位权限 | ||
| 307 | -// canLocation = await requestPermission(Permission.location); | ||
| 308 | -// } else { | ||
| 309 | -// canLocation = true; | ||
| 310 | -// } | ||
| 311 | -// // bool canLocation = await requestPermission(Permission.location); | ||
| 312 | -// // 单次定位 | ||
| 313 | -// if (canLocation) { | ||
| 314 | -// Future.delayed(Duration(milliseconds: 200), () async { | ||
| 315 | -// /// [hasShow] 隐私权政策是否弹窗展示告知用户 | ||
| 316 | -// AMapFlutterLocation.updatePrivacyShow(true, true); | ||
| 317 | - | ||
| 318 | -// /// [hasAgree] 隐私权政策是否已经取得用户同意 | ||
| 319 | -// AMapFlutterLocation.updatePrivacyAgree(true); | ||
| 320 | -// _startLocation(); | ||
| 321 | -// // final location = await AmapLocation.instance.fetchLocation( | ||
| 322 | -// // // needAddress: true, | ||
| 323 | -// // // mode: LocationAccuracy.High, | ||
| 324 | -// // // timeout: Duration(seconds: 10) | ||
| 325 | -// // ); | ||
| 326 | - | ||
| 327 | -// // if (location.city == null || location.city == '') //网络不好,定位失败 | ||
| 328 | -// // { | ||
| 329 | -// // // App.sp.setString("lat", "39.684670899"); | ||
| 330 | -// // // App.sp.setString("lng", "118.17630045"); | ||
| 331 | -// // } else { | ||
| 332 | -// // if (widget.long == null || | ||
| 333 | -// // widget.long == '' || | ||
| 334 | -// // widget.long == 'null') { | ||
| 335 | -// // latitude = location.latLng!.latitude; | ||
| 336 | -// // longitude = location.latLng!.longitude; | ||
| 337 | -// // if (_controller != null) { | ||
| 338 | -// // _controller!.setCenterCoordinate(LatLng( | ||
| 339 | -// // location.latLng!.latitude, location.latLng!.longitude)); | ||
| 340 | -// // } | ||
| 341 | - | ||
| 342 | -// // page = 1; | ||
| 343 | - | ||
| 344 | -// // _loadData( | ||
| 345 | -// // LatLng(location.latLng!.latitude, location.latLng!.longitude)); | ||
| 346 | - | ||
| 347 | -// // setState(() {}); | ||
| 348 | -// // } | ||
| 349 | -// // latitudeLocation = location.latLng!.latitude; | ||
| 350 | -// // longitudeLocation = location.latLng!.longitude; | ||
| 351 | -// // } | ||
| 352 | -// }); | ||
| 353 | -// } else { | ||
| 354 | -// //无权限 | ||
| 355 | -// } | ||
| 356 | -// } | ||
| 357 | - | ||
| 358 | -// // 开始定位 | ||
| 359 | -// /// 设置定位参数并启动定位 | ||
| 360 | -// void _startLocation() { | ||
| 361 | -// /// 开始定位之前设置定位参数 | ||
| 362 | -// _setLocationOption(); | ||
| 363 | -// _locationPlugin.startLocation(); | ||
| 364 | -// } | ||
| 365 | - | ||
| 366 | -// /// 停止定位 | ||
| 367 | -// /// 停止定位服务 | ||
| 368 | -// void _stopLocation() { | ||
| 369 | -// _locationPlugin.stopLocation(); | ||
| 370 | -// } | ||
| 371 | - | ||
| 372 | -// void onMapCreated(AMapController controller) { | ||
| 373 | -// // setState(() { | ||
| 374 | -// _mapController = controller; | ||
| 375 | -// // _mapController.moveCamera( | ||
| 376 | -// // CameraUpdate.newLatLng(LatLng(latitudeLocation, longitudeLocation)), | ||
| 377 | -// // animated: true, | ||
| 378 | -// // ); | ||
| 379 | -// // getApprovalNumber(); | ||
| 380 | -// // }); | ||
| 381 | -// } | ||
| 382 | - | ||
| 383 | -// /// 获取审图号 | ||
| 384 | -// // void getApprovalNumber() async { | ||
| 385 | -// // //普通地图审图号 | ||
| 386 | -// // String mapContentApprovalNumber = | ||
| 387 | -// // (await _mapController.getMapContentApprovalNumber()); | ||
| 388 | -// // //卫星地图审图号 | ||
| 389 | -// // String satelliteImageApprovalNumber = | ||
| 390 | -// // (await _mapController.getSatelliteImageApprovalNumber()); | ||
| 391 | - | ||
| 392 | -// // print('地图审图号(普通地图): $mapContentApprovalNumber'); | ||
| 393 | -// // print('地图审图号(卫星地图): $satelliteImageApprovalNumber'); | ||
| 394 | -// // } | ||
| 395 | - | ||
| 396 | -// //移动视野 | ||
| 397 | -// // void _onCameraMove(CameraPosition cameraPosition) { | ||
| 398 | -// // latitude = cameraPosition.target.latitude; | ||
| 399 | -// // longitude = cameraPosition.target.longitude; | ||
| 400 | -// // page = 1; | ||
| 401 | -// // _loadData(cameraPosition.target); | ||
| 402 | -// // } | ||
| 403 | - | ||
| 404 | -// //移动地图结束 | ||
| 405 | -// void _onCameraMoveEnd(CameraPosition cameraPosition) { | ||
| 406 | -// setState(() { | ||
| 407 | -// _currentZoom = '当前缩放级别:${cameraPosition.zoom}'; | ||
| 408 | -// }); | ||
| 409 | - | ||
| 410 | -// _mapController.moveCamera( | ||
| 411 | -// CameraUpdate.zoomTo(cameraPosition.zoom), | ||
| 412 | -// animated: true, | ||
| 413 | -// ); | ||
| 414 | -// latitude = cameraPosition.target.latitude; | ||
| 415 | -// longitude = cameraPosition.target.longitude; | ||
| 416 | -// page = 1; | ||
| 417 | -// _loadData(cameraPosition.target); | ||
| 418 | -// } | ||
| 419 | - | ||
| 420 | -// @override | ||
| 421 | -// Widget build(BuildContext context) { | ||
| 422 | -// final AMapWidget amap = AMapWidget( | ||
| 423 | -// initialCameraPosition: | ||
| 424 | -// CameraPosition(target: LatLng(latitude, longitude), zoom: 16), | ||
| 425 | -// onMapCreated: onMapCreated, | ||
| 426 | -// // onCameraMove: _onCameraMove, | ||
| 427 | -// onCameraMoveEnd: _onCameraMoveEnd, | ||
| 428 | -// minMaxZoomPreference: MinMaxZoomPreference(_minZoom, _maxZoom), | ||
| 429 | -// scaleEnabled: true, | ||
| 430 | -// ); | ||
| 431 | - | ||
| 432 | -// return Scaffold( | ||
| 433 | -// resizeToAvoidBottomInset: false, //防止底部布局被顶起 | ||
| 434 | -// appBar: SystemAppBar( | ||
| 435 | -// '选择位置信息', | ||
| 436 | -// onTap: () { | ||
| 437 | -// if (Navigator.canPop(context)) { | ||
| 438 | -// Navigator.pop(context); | ||
| 439 | -// } | ||
| 440 | -// }, | ||
| 441 | -// ), | ||
| 442 | - | ||
| 443 | -// body: Column( | ||
| 444 | -// children: <Widget>[ | ||
| 445 | -// // Theme( | ||
| 446 | -// // data: new | ||
| 447 | -// // ThemeData( | ||
| 448 | -// // // primaryColor: MyColours.color_438E93, | ||
| 449 | -// // // hintColor: MyColours.color_438E93), | ||
| 450 | -// // child: | ||
| 451 | -// // Container( | ||
| 452 | -// // color: MyColours.color_438E93, | ||
| 453 | -// // decoration: BoxDecoration( | ||
| 454 | -// // color: MyColours.color_438E93, | ||
| 455 | -// // boxShadow: [ | ||
| 456 | -// // BoxShadow(color: Colors.white, spreadRadius: 1), | ||
| 457 | -// // ], | ||
| 458 | -// // ), | ||
| 459 | - | ||
| 460 | -// // padding: EdgeInsets.all(5), | ||
| 461 | -// // child: | ||
| 462 | - | ||
| 463 | -// // ), | ||
| 464 | -// // ), | ||
| 465 | -// // ListView.builder( | ||
| 466 | -// // shrinkWrap: true, | ||
| 467 | -// // itemCount: inputTipDatas.length, | ||
| 468 | -// // itemBuilder: (context, index) { | ||
| 469 | -// // InputTip inputTip = inputTipDatas[index]; | ||
| 470 | -// // return InkWell( | ||
| 471 | -// // onTap: () { | ||
| 472 | -// // // searchAroundAddress(inputTip.name ?? ''); | ||
| 473 | -// // // searchPoiId(inputTip.poiId ?? ''); | ||
| 474 | -// // // _loadData(inputTip.coordinate ?? | ||
| 475 | -// // // LatLng(latitude, longitude)); | ||
| 476 | -// // }, | ||
| 477 | -// // child: Container( | ||
| 478 | -// // child: Row( | ||
| 479 | -// // children: [ | ||
| 480 | -// // Text( | ||
| 481 | -// // inputTip.name ?? '', | ||
| 482 | -// // style: TextStyle( | ||
| 483 | -// // fontSize: font(15), | ||
| 484 | -// // color: MyColours.color_515151), | ||
| 485 | -// // ), | ||
| 486 | -// // HEmptyView(10), | ||
| 487 | -// // Expanded( | ||
| 488 | -// // child: Text( | ||
| 489 | -// // (inputTip.district ?? '') + | ||
| 490 | -// // (inputTip.address ?? ''), | ||
| 491 | -// // style: TextStyle( | ||
| 492 | -// // fontSize: font(13), | ||
| 493 | -// // color: MyColours.color_999999), | ||
| 494 | -// // ), | ||
| 495 | -// // ), | ||
| 496 | -// // ], | ||
| 497 | -// // ))); | ||
| 498 | -// // }) | ||
| 499 | -// // ], | ||
| 500 | -// // ), | ||
| 501 | - | ||
| 502 | -// Stack( | ||
| 503 | -// children: [ | ||
| 504 | -// Container( | ||
| 505 | -// height: w(300), | ||
| 506 | -// child: Stack( | ||
| 507 | -// children: <Widget>[ | ||
| 508 | -// amap, | ||
| 509 | -// // AmapView( | ||
| 510 | -// // showZoomControl: false, | ||
| 511 | - | ||
| 512 | -// // /// 是否显示指南针控件 | ||
| 513 | -// // showCompass: true, | ||
| 514 | - | ||
| 515 | -// // /// 是否显示比例尺控件 | ||
| 516 | -// // showScaleControl: true, | ||
| 517 | - | ||
| 518 | -// // /// 是否使能缩放手势 | ||
| 519 | -// // zoomGesturesEnabled: true, | ||
| 520 | - | ||
| 521 | -// // /// 是否使能滚动手势 | ||
| 522 | -// // scrollGesturesEnabled: true, | ||
| 523 | - | ||
| 524 | -// // /// 是否使能旋转手势 | ||
| 525 | -// // rotateGestureEnabled: false, | ||
| 526 | -// // centerCoordinate: LatLng(latitude, longitude), | ||
| 527 | -// // maskDelay: Duration(milliseconds: 500), | ||
| 528 | -// // zoomLevel: 19, | ||
| 529 | -// // onMapCreated: (controller) async { | ||
| 530 | -// // _controller = controller; | ||
| 531 | -// // _controller! | ||
| 532 | -// // .setCenterCoordinate(LatLng(latitude, longitude)); | ||
| 533 | -// // // if (await requestPermission(PermissionGroup.location)) { | ||
| 534 | -// // // await controller.showMyLocation(true); | ||
| 535 | -// // // await controller?.showLocateControl(true); | ||
| 536 | -// // // final latLng = await _controller?.getLocation( | ||
| 537 | -// // // delay: Duration(seconds: 2)); | ||
| 538 | -// // // await enableFluttifyLog(false); // 关闭log | ||
| 539 | -// // // _loadData(latLng); | ||
| 540 | -// // // } else { | ||
| 541 | -// // // //无权限 | ||
| 542 | -// // // _showLocPemWidget(); | ||
| 543 | -// // // } | ||
| 544 | -// // }, | ||
| 545 | -// // // markers: [], | ||
| 546 | -// // onMapMoveEnd: (MapMove move) async { | ||
| 547 | -// // latitude = move.coordinate!.latitude; | ||
| 548 | -// // longitude = move.coordinate!.longitude; | ||
| 549 | -// // page = 1; | ||
| 550 | -// // _loadData(move.coordinate!); | ||
| 551 | -// // }, | ||
| 552 | -// // ), | ||
| 553 | -// Center( | ||
| 554 | -// child: Icon( | ||
| 555 | -// Icons.place, | ||
| 556 | -// size: w(32), | ||
| 557 | -// color: Color(0xFFFF0000), | ||
| 558 | -// ), | ||
| 559 | -// ), | ||
| 560 | -// Positioned( | ||
| 561 | -// right: w(10), | ||
| 562 | -// bottom: w(10), | ||
| 563 | -// child: InkWell( | ||
| 564 | -// onTap: () { | ||
| 565 | -// _mapController.moveCamera( | ||
| 566 | -// CameraUpdate.newLatLng( | ||
| 567 | -// LatLng(latitudeLocation, longitudeLocation)), | ||
| 568 | -// animated: true, | ||
| 569 | -// ); | ||
| 570 | -// }, | ||
| 571 | -// child: Container( | ||
| 572 | -// decoration: BoxDecoration( | ||
| 573 | -// color: MyColours.color_ffffff, | ||
| 574 | -// borderRadius: BorderRadius.circular(r(5))), | ||
| 575 | -// padding: EdgeInsets.all(w(5)), | ||
| 576 | -// child: Image.asset( | ||
| 577 | -// Utils.getImgPath('location_map'), | ||
| 578 | -// width: w(25), | ||
| 579 | -// ), | ||
| 580 | -// )), | ||
| 581 | -// ) | ||
| 582 | -// ], | ||
| 583 | -// ), | ||
| 584 | -// ), | ||
| 585 | -// Positioned( | ||
| 586 | -// top: w(10), | ||
| 587 | -// left: w(20), | ||
| 588 | -// right: w(20), | ||
| 589 | -// child: Container( | ||
| 590 | -// // height: w(45), | ||
| 591 | -// padding: EdgeInsets.symmetric(vertical: w(10)), | ||
| 592 | -// decoration: BoxDecoration( | ||
| 593 | -// color: Colors.white, | ||
| 594 | -// borderRadius: BorderRadius.circular(r(10))), | ||
| 595 | -// child: TextField( | ||
| 596 | -// textAlignVertical: TextAlignVertical.center, | ||
| 597 | -// style: TextStyle( | ||
| 598 | -// color: MyColours.color_515151, | ||
| 599 | -// fontSize: font(15), | ||
| 600 | -// ), | ||
| 601 | -// controller: | ||
| 602 | -// TextEditingController.fromValue(TextEditingValue( | ||
| 603 | -// // 设置内容 | ||
| 604 | -// text: keyword, | ||
| 605 | -// selection: TextSelection.fromPosition(TextPosition( | ||
| 606 | -// affinity: TextAffinity.downstream, | ||
| 607 | -// offset: keyword.length)), | ||
| 608 | -// // 保持光标在最后 | ||
| 609 | -// )), | ||
| 610 | -// decoration: InputDecoration( | ||
| 611 | -// // border: b, | ||
| 612 | -// // border: OutlineInputBorder( | ||
| 613 | -// // borderRadius: BorderRadius.all(Radius.circular(40)), | ||
| 614 | -// // ), | ||
| 615 | -// border: OutlineInputBorder(borderSide: BorderSide.none), | ||
| 616 | -// hintText: '输入关键字', | ||
| 617 | -// isCollapsed: true, | ||
| 618 | - | ||
| 619 | -// hintStyle: TextStyle( | ||
| 620 | -// color: MyColours.color_999999, fontSize: font(15)), | ||
| 621 | -// // contentPadding: const EdgeInsets.symmetric( | ||
| 622 | -// // vertical: 8, horizontal: 1), | ||
| 623 | -// prefixIconConstraints: BoxConstraints(maxWidth: w(40)), | ||
| 624 | -// prefixIcon: Padding( | ||
| 625 | -// padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 626 | -// child: SizedBox( | ||
| 627 | -// width: w(30), | ||
| 628 | -// child: Image.asset( | ||
| 629 | -// Utils.getImgPath('search_black'), | ||
| 630 | -// ))), | ||
| 631 | -// suffixIconConstraints: BoxConstraints(maxWidth: w(32)), | ||
| 632 | -// suffixIcon: InkWell( | ||
| 633 | -// child: Padding( | ||
| 634 | -// padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 635 | -// child: SizedBox( | ||
| 636 | -// width: w(22), | ||
| 637 | -// child: Image.asset( | ||
| 638 | -// Utils.getImgPath('delete_black'), | ||
| 639 | -// ))), | ||
| 640 | -// onTap: () { | ||
| 641 | -// keyword = ""; | ||
| 642 | -// setState(() {}); | ||
| 643 | -// }, | ||
| 644 | -// ), | ||
| 645 | -// fillColor: Colors.white, | ||
| 646 | -// filled: true, | ||
| 647 | -// ), | ||
| 648 | - | ||
| 649 | -// inputFormatters: [], | ||
| 650 | -// //内容改变的回调 | ||
| 651 | -// onChanged: (text) { | ||
| 652 | -// print('change $text'); | ||
| 653 | -// keyword = text; | ||
| 654 | - | ||
| 655 | -// //搜索 | ||
| 656 | - | ||
| 657 | -// if (text != null && text.trim().length > 0) { | ||
| 658 | -// JhCommonUtils.debounce( | ||
| 659 | -// () => _fetchInputTips(text.toString())); | ||
| 660 | -// } | ||
| 661 | -// }, | ||
| 662 | -// //内容提交(按回车)的回调 | ||
| 663 | -// onSubmitted: (text) { | ||
| 664 | -// print('submit $text'); | ||
| 665 | -// // 触发关闭弹出来的键盘。 | ||
| 666 | -// keyword = text; | ||
| 667 | -// FocusScope.of(context).requestFocus(FocusNode()); | ||
| 668 | -// setState(() { | ||
| 669 | -// // isloading = true; | ||
| 670 | -// }); | ||
| 671 | - | ||
| 672 | -// // _fetchInputTips(text.toString()); | ||
| 673 | - | ||
| 674 | -// // searchAroundAddress(text.toString()); | ||
| 675 | -// }, | ||
| 676 | -// //按回车时调用 | ||
| 677 | -// onEditingComplete: () { | ||
| 678 | -// print('onEditingComplete'); | ||
| 679 | -// }, | ||
| 680 | -// ), | ||
| 681 | -// ), | ||
| 682 | -// ) | ||
| 683 | -// ], | ||
| 684 | -// ), | ||
| 685 | - | ||
| 686 | -// Expanded( | ||
| 687 | -// flex: 1, | ||
| 688 | -// child: Visibility( | ||
| 689 | -// visible: !isloading, | ||
| 690 | -// maintainSize: false, | ||
| 691 | -// maintainSemantics: false, | ||
| 692 | -// maintainInteractivity: false, | ||
| 693 | -// replacement: Center( | ||
| 694 | -// child: CupertinoActivityIndicator(), | ||
| 695 | -// ), | ||
| 696 | -// child: EasyRefresh.custom( | ||
| 697 | -// controller: refreshController, | ||
| 698 | -// slivers: [ | ||
| 699 | -// SliverList( | ||
| 700 | -// delegate: SliverChildBuilderDelegate( | ||
| 701 | -// (BuildContext context, int position) { | ||
| 702 | -// print("itemBuilder" + list.length.toString()); | ||
| 703 | -// PoiModel item = list[position]!; | ||
| 704 | -// return InkWell( | ||
| 705 | -// child: Column( | ||
| 706 | -// children: <Widget>[ | ||
| 707 | -// Container( | ||
| 708 | -// margin: EdgeInsets.only( | ||
| 709 | -// top: 8, bottom: 5, left: 10), | ||
| 710 | -// child: Row( | ||
| 711 | -// children: <Widget>[ | ||
| 712 | -// Icon( | ||
| 713 | -// Icons.place, | ||
| 714 | -// size: 20.0, | ||
| 715 | -// color: position == 0 | ||
| 716 | -// ? Colors.green | ||
| 717 | -// : Colors.grey, | ||
| 718 | -// ), | ||
| 719 | -// Expanded( | ||
| 720 | -// child: Text(item.title, | ||
| 721 | -// style: TextStyle( | ||
| 722 | -// fontSize: 16, | ||
| 723 | -// color: position == 0 | ||
| 724 | -// ? Colors.green | ||
| 725 | -// : Color(0xFF787878)))) | ||
| 726 | -// ], | ||
| 727 | -// ), | ||
| 728 | -// ), | ||
| 729 | -// Container( | ||
| 730 | -// margin: EdgeInsets.only( | ||
| 731 | -// top: 5, bottom: 5, left: 18), | ||
| 732 | -// alignment: Alignment.centerLeft, | ||
| 733 | -// child: Text( | ||
| 734 | -// item.address!, | ||
| 735 | -// style: TextStyle( | ||
| 736 | -// fontSize: 14, | ||
| 737 | -// color: Color(0xFF646464), | ||
| 738 | -// ), | ||
| 739 | -// ), | ||
| 740 | -// ), | ||
| 741 | -// Divider( | ||
| 742 | -// height: 1, | ||
| 743 | -// ) | ||
| 744 | -// ], | ||
| 745 | -// ), | ||
| 746 | -// onTap: () async { | ||
| 747 | -// // await _controller.setCenterCoordinate( | ||
| 748 | -// // LatLng(item.latLng.latitude, item.latLng.longitude), | ||
| 749 | -// // zoomLevel: 16); | ||
| 750 | -// if (Navigator.canPop(context)) { | ||
| 751 | -// Navigator.pop(context, { | ||
| 752 | -// 'address': item.address, | ||
| 753 | -// 'lat': item.latLng!.latitude.toString(), | ||
| 754 | -// 'lng': item.latLng!.longitude.toString() | ||
| 755 | -// }); | ||
| 756 | -// } | ||
| 757 | -// }, | ||
| 758 | -// ); | ||
| 759 | -// }, | ||
| 760 | -// childCount: list.length, | ||
| 761 | -// ), | ||
| 762 | -// ) | ||
| 763 | -// ], | ||
| 764 | -// onRefresh: () async { | ||
| 765 | -// if (flag) { | ||
| 766 | -// page = 1; | ||
| 767 | -// _loadData(LatLng(latitude, longitude)); | ||
| 768 | -// } | ||
| 769 | -// }, | ||
| 770 | -// onLoad: () async { | ||
| 771 | -// if (flag) { | ||
| 772 | -// page++; | ||
| 773 | -// _loadData(LatLng(latitude, longitude), | ||
| 774 | -// showloading: false); | ||
| 775 | -// } | ||
| 776 | -// }, | ||
| 777 | -// )), | ||
| 778 | -// ), | ||
| 779 | -// ], | ||
| 780 | -// ), | ||
| 781 | -// ); | ||
| 782 | -// } | ||
| 783 | - | ||
| 784 | -// _fetchInputTips(String text) async { | ||
| 785 | -// flag = false; | ||
| 786 | -// page = 1; | ||
| 787 | -// // setState(() { | ||
| 788 | -// // isloading = true; | ||
| 789 | -// // }); | ||
| 790 | - | ||
| 791 | -// /// 逆地理编码(坐标转地址) | ||
| 792 | -// /// | ||
| 793 | -// /// | ||
| 794 | -// // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 795 | -// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 796 | - | ||
| 797 | -// LatLng latLng = LatLng(latitude, longitude); | ||
| 798 | - | ||
| 799 | -// address = await _locationPlugin | ||
| 800 | -// .onGeocodeSearch(true, [latLng.longitude, latLng.latitude]); | ||
| 801 | - | ||
| 802 | -// // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 803 | -// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 804 | - | ||
| 805 | -// List<dynamic> temp = await _locationPlugin.doInputtipsRequest( | ||
| 806 | -// text, | ||
| 807 | -// city: "", | ||
| 808 | -// ); | ||
| 809 | - | ||
| 810 | -// inputTipDatas = []; | ||
| 811 | - | ||
| 812 | -// temp.forEach((element) { | ||
| 813 | -// inputTipDatas.add(MapInputsModel.fromJson(element)); | ||
| 814 | -// }); | ||
| 815 | - | ||
| 816 | -// print(inputTipDatas); | ||
| 817 | -// poiModel = new PoiModel("当前位置", address, latLng); | ||
| 818 | -// list.clear(); | ||
| 819 | -// list.add(poiModel); | ||
| 820 | -// for (var inputTip in inputTipDatas) { | ||
| 821 | -// String? title = await inputTip.name ?? ''; | ||
| 822 | -// String? cityStr = (inputTip.district ?? '') + (inputTip.city ?? ''); | ||
| 823 | - | ||
| 824 | -// // LatLng? latLng = await inputTip.point; | ||
| 825 | - | ||
| 826 | -// list.add(new PoiModel(title.toString(), cityStr, latLng)); | ||
| 827 | -// } | ||
| 828 | - | ||
| 829 | -// print(list); | ||
| 830 | - | ||
| 831 | -// setState(() { | ||
| 832 | -// // isloading = false; | ||
| 833 | -// }); | ||
| 834 | -// } | ||
| 835 | - | ||
| 836 | -// void _loadData(LatLng latLng, {showloading = true}) async { | ||
| 837 | -// flag = true; | ||
| 838 | -// setState(() { | ||
| 839 | -// if (showloading) { | ||
| 840 | -// isloading = true; | ||
| 841 | -// } | ||
| 842 | -// }); | ||
| 843 | - | ||
| 844 | -// /// 逆地理编码(坐标转地址) | ||
| 845 | -// /// | ||
| 846 | -// /// | ||
| 847 | -// /// | ||
| 848 | - | ||
| 849 | -// // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 850 | -// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 851 | -// if (page == 1) { | ||
| 852 | -// address = await _locationPlugin | ||
| 853 | -// .onGeocodeSearch(true, [latLng.longitude, latLng.latitude]); | ||
| 854 | -// poiModel = new PoiModel("当前位置", address, latLng); | ||
| 855 | -// list.clear(); | ||
| 856 | -// list.add(poiModel); | ||
| 857 | -// } | ||
| 858 | -// // final poiList | ||
| 859 | -// List<dynamic> temp = await _locationPlugin.poiSearchAround( | ||
| 860 | -// keyword, latLng.longitude, latLng.latitude); | ||
| 861 | - | ||
| 862 | -// List<MapRoundSearchModel> searchData = []; | ||
| 863 | - | ||
| 864 | -// temp.forEach((element) { | ||
| 865 | -// searchData.add(MapRoundSearchModel.fromJson(element)); | ||
| 866 | -// }); | ||
| 867 | - | ||
| 868 | -// print(searchData); | ||
| 869 | - | ||
| 870 | -// for (var poi in searchData) { | ||
| 871 | -// String? title = await poi.title; | ||
| 872 | -// String? cityName = await poi.cityName; | ||
| 873 | -// String? provinceName = await poi.provinceName; | ||
| 874 | -// String? snippet = await poi.snippet; | ||
| 875 | -// String? adName = await poi.adName; | ||
| 876 | -// LatLng? latLng = LatLng(poi.latitude ?? 0, poi.longitude ?? 0); | ||
| 877 | -// String? bussniss = poi.businessArea; | ||
| 878 | - | ||
| 879 | -// list.add(new PoiModel( | ||
| 880 | -// title.toString(), | ||
| 881 | -// provinceName.toString() + | ||
| 882 | -// cityName.toString() + | ||
| 883 | -// adName.toString() + | ||
| 884 | -// // address.toString() + | ||
| 885 | -// bussniss.toString() + | ||
| 886 | -// snippet.toString(), | ||
| 887 | -// latLng)); | ||
| 888 | -// } | ||
| 889 | - | ||
| 890 | -// setState(() { | ||
| 891 | -// if (showloading) { | ||
| 892 | -// isloading = false; | ||
| 893 | -// } | ||
| 894 | -// }); | ||
| 895 | -// } | ||
| 896 | - | ||
| 897 | -// // void searchPoiId(String text) async { | ||
| 898 | -// // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 899 | -// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 900 | -// // Poi? poi = await AmapSearch.instance.searchPoiId( | ||
| 901 | -// // text, | ||
| 902 | -// // ); | ||
| 903 | -// // print(poi); | ||
| 904 | -// // } | ||
| 905 | - | ||
| 906 | -// // void searchAroundAddress(String text) async { | ||
| 907 | -// // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 908 | -// // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 909 | -// // final poiList = await AmapSearch.instance.searchKeyword( | ||
| 910 | -// // text, | ||
| 911 | -// // city: "", | ||
| 912 | -// // ); | ||
| 913 | -// // // final poiList = await AmapSearch.instance.searchAround( | ||
| 914 | -// // // LatLng(latitude, longitude), | ||
| 915 | -// // // city: "", | ||
| 916 | -// // // radius: 100000000000000 | ||
| 917 | - | ||
| 918 | -// // // ); | ||
| 919 | - | ||
| 920 | -// // list.clear(); | ||
| 921 | -// // list.add(poiModel); | ||
| 922 | -// // for (var poi in poiList) { | ||
| 923 | -// // String? title = await poi.title; | ||
| 924 | -// // LatLng? latLng = await poi.latLng; | ||
| 925 | -// // String? cityName = await poi.cityName; | ||
| 926 | -// // String? provinceName = await poi.provinceName; | ||
| 927 | -// // String? address = await poi.address; | ||
| 928 | -// // list.add(new PoiModel( | ||
| 929 | -// // title.toString(), | ||
| 930 | -// // provinceName.toString() + cityName.toString() + address.toString(), | ||
| 931 | -// // latLng)); | ||
| 932 | -// // } | ||
| 933 | -// // setState(() { | ||
| 934 | -// // isloading = false; | ||
| 935 | -// // FocusScope.of(context).requestFocus(FocusNode()); | ||
| 936 | -// // }); | ||
| 937 | -// // } | ||
| 938 | -// } | ||
| 939 | - | ||
| 940 | -// class PoiModel { | ||
| 941 | -// LatLng? latLng; | ||
| 942 | -// String title; | ||
| 943 | -// String? address; | ||
| 944 | - | ||
| 945 | -// PoiModel(this.title, this.address, this.latLng); | ||
| 946 | -// } | 15 | +import 'package:flutter_easyrefresh/easy_refresh.dart'; |
| 16 | + | ||
| 17 | +import 'package:one_key/pages/create_store/const_config.dart'; | ||
| 18 | +import 'package:one_key/pages/create_store/map_inputs_model.dart'; | ||
| 19 | + | ||
| 20 | +import 'package:one_key/res/colors.dart'; | ||
| 21 | +import 'package:one_key/utils/common_utils.dart'; | ||
| 22 | + | ||
| 23 | +import 'package:one_key/utils/misc.dart'; | ||
| 24 | + | ||
| 25 | +import 'package:one_key/utils/screen_util.dart'; | ||
| 26 | +import 'package:one_key/utils/utils.dart'; | ||
| 27 | + | ||
| 28 | +import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 29 | +import 'package:permission_handler/permission_handler.dart'; | ||
| 30 | + | ||
| 31 | +// import '../../utils/common_utils.dart'; | ||
| 32 | +// import 'package:demo/resources/custom_text_style.dart'; | ||
| 33 | +// import 'package:demo/utils/misc.dart'; | ||
| 34 | + | ||
| 35 | +// import 'package:demo/widgets/network_state/page_loading.dart'; | ||
| 36 | + | ||
| 37 | +class MapChoicePointPage extends StatefulWidget { | ||
| 38 | + final String? long; | ||
| 39 | + final String? lat; | ||
| 40 | + MapChoicePointPage({Key? key, this.long, this.lat}) : super(key: key); | ||
| 41 | + | ||
| 42 | + @override | ||
| 43 | + _MapChoicePointPageState createState() => _MapChoicePointPageState(); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +class _MapChoicePointPageState extends State<MapChoicePointPage> { | ||
| 47 | + late AMapController _mapController; | ||
| 48 | + final double _minZoom = 3; | ||
| 49 | + final double _maxZoom = 20; | ||
| 50 | + String? _currentZoom; | ||
| 51 | + // List<Poi>? poiList; | ||
| 52 | + static List<PoiModel?> list = []; | ||
| 53 | + static List<PoiModel> searchlist = []; | ||
| 54 | + PoiModel? poiModel; | ||
| 55 | + String keyword = ""; | ||
| 56 | + String? address = ""; | ||
| 57 | + bool isloading = true; | ||
| 58 | + | ||
| 59 | + double latitude = 39.684670899; | ||
| 60 | + double longitude = 118.17630045; | ||
| 61 | + | ||
| 62 | + double latitudeLocation = 39.684670899; | ||
| 63 | + double longitudeLocation = 118.17630045; | ||
| 64 | + | ||
| 65 | + List<MapInputsModel> inputTipDatas = []; | ||
| 66 | + int page = 1; | ||
| 67 | + EasyRefreshController refreshController = EasyRefreshController(); | ||
| 68 | + bool flag = true; | ||
| 69 | + | ||
| 70 | + /// 存储定位结果 | ||
| 71 | + Map<String, Object>? _locationResult; | ||
| 72 | + | ||
| 73 | + /// 定位结果监听器 | ||
| 74 | + StreamSubscription<Map<String, Object>>? _locationListener; | ||
| 75 | + | ||
| 76 | + /// 地理位置解析结果监听器 | ||
| 77 | + StreamSubscription<Map<String, Object>>? _geocodeSearchListener; | ||
| 78 | + | ||
| 79 | + /// 高德定位插件实例 | ||
| 80 | + final AMapFlutterLocation _locationPlugin = new AMapFlutterLocation(); | ||
| 81 | + | ||
| 82 | + @override | ||
| 83 | + void initState() { | ||
| 84 | + super.initState(); | ||
| 85 | + | ||
| 86 | + if (widget.long != null && widget.long != '' && widget.long != 'null') { | ||
| 87 | + longitude = double.parse(widget.long!); | ||
| 88 | + } | ||
| 89 | + if (widget.lat != null && widget.lat != '' && widget.lat != 'null') { | ||
| 90 | + latitude = double.parse(widget.lat!); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + WidgetsBinding.instance.addPostFrameCallback((_) async { | ||
| 94 | + AMapInitializer.init(context, apiKey: ConstConfig.amapApiKeys); | ||
| 95 | + AMapInitializer.updatePrivacyAgree(ConstConfig.amapPrivacyStatement); | ||
| 96 | + | ||
| 97 | + AMapFlutterLocation.setApiKey("1dbf56e2e8a4d0e4cdc2df9efd36bc71", | ||
| 98 | + "dfb64c0463cb53927914364b5c09aba0", | ||
| 99 | + ohosKey: "7c2081e92ec65bfffa2df0a5464f0c7b"); | ||
| 100 | + | ||
| 101 | + /// 设置是否已经包含高德隐私政策并弹窗展示显示用户查看,如果未包含或者没有弹窗展示,高德定位SDK将不会工作 | ||
| 102 | + /// | ||
| 103 | + /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy | ||
| 104 | + /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b> | ||
| 105 | + /// | ||
| 106 | + /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy | ||
| 107 | + /// | ||
| 108 | + /// [hasContains] 隐私声明中是否包含高德隐私政策说明 | ||
| 109 | + /// | ||
| 110 | + /// [hasShow] 隐私权政策是否弹窗展示告知用户 | ||
| 111 | + AMapFlutterLocation.updatePrivacyShow(true, true); | ||
| 112 | + | ||
| 113 | + /// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作 | ||
| 114 | + /// | ||
| 115 | + /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy | ||
| 116 | + /// | ||
| 117 | + /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b> | ||
| 118 | + /// | ||
| 119 | + /// [hasAgree] 隐私权政策是否已经取得用户同意 | ||
| 120 | + AMapFlutterLocation.updatePrivacyAgree(true); | ||
| 121 | + _requestLocationPermission(); | ||
| 122 | + | ||
| 123 | + // ama | ||
| 124 | + // let marker = new AMap.Marker({//添加标记点 | ||
| 125 | + // position: this.position, | ||
| 126 | + // map: map | ||
| 127 | + }); | ||
| 128 | + | ||
| 129 | + _geocodeSearchListener = _locationPlugin | ||
| 130 | + .onGeocodeSearchChange() | ||
| 131 | + .listen((Map<String, Object> result) { | ||
| 132 | + // setState(() { | ||
| 133 | + | ||
| 134 | + if (result.containsKey('errorCode')) { | ||
| 135 | + Utils.showToast(result['errorInfo'].toString()); | ||
| 136 | + } else { | ||
| 137 | + _locationResult = result; | ||
| 138 | + | ||
| 139 | + print(_locationResult); | ||
| 140 | + } | ||
| 141 | + }); | ||
| 142 | + | ||
| 143 | + /// 注册定位结果监听 | ||
| 144 | + /// 通过监听器接收定位结果并更新UI | ||
| 145 | + _locationListener = _locationPlugin | ||
| 146 | + .onLocationChanged() | ||
| 147 | + .listen((Map<String, Object> result) { | ||
| 148 | + // setState(() { | ||
| 149 | + | ||
| 150 | + if (result.containsKey('errorCode')) { | ||
| 151 | + Utils.showToast(result['errorInfo'].toString()); | ||
| 152 | + } else { | ||
| 153 | + _locationResult = result; | ||
| 154 | + | ||
| 155 | + print(_locationResult); | ||
| 156 | + | ||
| 157 | + if (result['latitude'] == null || result['latitude'] == '') //网络不好,定位失败 | ||
| 158 | + { | ||
| 159 | + // App.sp.setString("lat", "39.684670899"); | ||
| 160 | + // App.sp.setString("lng", "118.17630045"); | ||
| 161 | + } else { | ||
| 162 | + if (widget.long == null || | ||
| 163 | + widget.long == '' || | ||
| 164 | + widget.long == 'null') { | ||
| 165 | + latitude = double.parse(result['latitude'].toString()); | ||
| 166 | + longitude = double.parse(result['longitude'].toString()); | ||
| 167 | + // if (_mapController != null) { | ||
| 168 | + _mapController.moveCamera( | ||
| 169 | + CameraUpdate.newLatLng(LatLng(latitude, longitude))); | ||
| 170 | + | ||
| 171 | + // } | ||
| 172 | + page = 1; | ||
| 173 | + | ||
| 174 | + // _loadData(LatLng(latitude, longitude)); | ||
| 175 | + | ||
| 176 | + // setState(() {}); | ||
| 177 | + } | ||
| 178 | + latitudeLocation = latitude; | ||
| 179 | + longitudeLocation = longitude; | ||
| 180 | + _mapController.moveCamera( | ||
| 181 | + CameraUpdate.newLatLng(LatLng(latitudeLocation, longitudeLocation)), | ||
| 182 | + animated: true, | ||
| 183 | + ); | ||
| 184 | + _loadData(LatLng(latitude, longitude)); | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + }); | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + @override | ||
| 191 | + void dispose() { | ||
| 192 | + super.dispose(); | ||
| 193 | + | ||
| 194 | + /// 移除定位监听 | ||
| 195 | + /// 防止内存泄漏 | ||
| 196 | + if (null != _locationListener) { | ||
| 197 | + _locationListener?.cancel(); | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + if (null != _geocodeSearchListener) { | ||
| 201 | + _geocodeSearchListener?.cancel(); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + /// 销毁定位 | ||
| 205 | + /// 释放定位资源 | ||
| 206 | + _locationPlugin.destroy(); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + // Future<bool> checkLocationPermission() async { | ||
| 210 | + // PermissionStatus permissionStatus = await Permission.location.status; | ||
| 211 | + // if (permissionStatus == PermissionStatus.granted) { | ||
| 212 | + // return true; | ||
| 213 | + // } else { | ||
| 214 | + // return false; | ||
| 215 | + // } | ||
| 216 | + // } | ||
| 217 | + | ||
| 218 | + /// 检查权限并定 | ||
| 219 | + // _getLocationPermission() async { | ||
| 220 | + // if (!(await checkPermission(Permission.location))) { | ||
| 221 | + // //没有定位权限 | ||
| 222 | + | ||
| 223 | + // //申请定位权限 | ||
| 224 | + // _requestLocationPermission(); | ||
| 225 | + // } else { | ||
| 226 | + // //去定位 | ||
| 227 | + // _requestLocationPermission(); | ||
| 228 | + // } | ||
| 229 | + // } | ||
| 230 | + | ||
| 231 | + /// 设置定位参数 | ||
| 232 | + /// 配置定位选项,如精度、频率等 | ||
| 233 | + void _setLocationOption() { | ||
| 234 | + AMapLocationOption locationOption = new AMapLocationOption(); | ||
| 235 | + | ||
| 236 | + /// 是否单次定位 | ||
| 237 | + /// false表示连续定位 | ||
| 238 | + locationOption.onceLocation = true; | ||
| 239 | + | ||
| 240 | + /// 是否需要返回逆地理信息 | ||
| 241 | + /// true表示需要返回地址信息 | ||
| 242 | + locationOption.needAddress = true; | ||
| 243 | + | ||
| 244 | + /// 是否需要返回逆地理编码信息 | ||
| 245 | + locationOption.locatingWithReGeocode = true; | ||
| 246 | + | ||
| 247 | + /// 逆地理信息的语言类型 | ||
| 248 | + /// 默认为自动适配当前系统语言 | ||
| 249 | + locationOption.geoLanguage = GeoLanguage.DEFAULT; | ||
| 250 | + | ||
| 251 | + /// iOS 14定位精度权限设置 | ||
| 252 | + /// 设置为模糊定位精度 | ||
| 253 | + locationOption.desiredLocationAccuracyAuthorizationMode = | ||
| 254 | + AMapLocationAccuracyAuthorizationMode.ReduceAccuracy; | ||
| 255 | + | ||
| 256 | + /// iOS 14精确定位目的key | ||
| 257 | + /// 需要与info.plist中配置一致 | ||
| 258 | + locationOption.fullAccuracyPurposeKey = "AMapLocationScene"; | ||
| 259 | + | ||
| 260 | + /// 设置Android端连续定位的定位间隔 | ||
| 261 | + /// 单位:毫秒 | ||
| 262 | + locationOption.locationInterval = 2000; | ||
| 263 | + | ||
| 264 | + /// 设置Android端的定位模式 | ||
| 265 | + /// 可选值: | ||
| 266 | + /// [AMapLocationMode.Battery_Saving] 低功耗模式 | ||
| 267 | + /// [AMapLocationMode.Device_Sensors] 仅设备模式 | ||
| 268 | + /// [AMapLocationMode.Hight_Accuracy] 高精度模式 | ||
| 269 | + locationOption.locationMode = AMapLocationMode.Hight_Accuracy; | ||
| 270 | + | ||
| 271 | + /// 设置iOS端的定位最小更新距离 | ||
| 272 | + /// -1表示不限制距离 | ||
| 273 | + locationOption.distanceFilter = -1; | ||
| 274 | + | ||
| 275 | + /// 设置iOS端期望的定位精度 | ||
| 276 | + /// 可选值: | ||
| 277 | + /// [DesiredAccuracy.Best] 最高精度 | ||
| 278 | + /// [DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 | ||
| 279 | + /// [DesiredAccuracy.NearestTenMeters] 10米 | ||
| 280 | + /// [DesiredAccuracy.Kilometer] 1000米 | ||
| 281 | + /// [DesiredAccuracy.ThreeKilometers] 3000米 | ||
| 282 | + locationOption.desiredAccuracy = DesiredAccuracy.Best; | ||
| 283 | + | ||
| 284 | + /// 设置iOS端是否允许系统暂停定位 | ||
| 285 | + /// false表示不允许系统暂停定位 | ||
| 286 | + locationOption.pausesLocationUpdatesAutomatically = false; | ||
| 287 | + | ||
| 288 | + /// 将定位参数设置给定位插件 | ||
| 289 | + _locationPlugin.setLocationOption(locationOption); | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + /// 获取定位权限 | ||
| 293 | + _requestLocationPermission() async { | ||
| 294 | + /// [hasShow] 隐私权政策是否弹窗展示告知用户 | ||
| 295 | + AMapFlutterLocation.updatePrivacyShow(true, true); | ||
| 296 | + | ||
| 297 | + /// [hasAgree] 隐私权政策是否已经取得用户同意 | ||
| 298 | + AMapFlutterLocation.updatePrivacyAgree(true); | ||
| 299 | + // await AMapFlutterLocation.instance.updatePrivacyShow(true); | ||
| 300 | + // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 301 | + bool canLocation = false; | ||
| 302 | + | ||
| 303 | + if (!(await checkPermission(Permission.location))) { | ||
| 304 | + //没有定位权限 | ||
| 305 | + | ||
| 306 | + //申请定位权限 | ||
| 307 | + canLocation = await requestPermission(Permission.location); | ||
| 308 | + } else { | ||
| 309 | + canLocation = true; | ||
| 310 | + } | ||
| 311 | + // bool canLocation = await requestPermission(Permission.location); | ||
| 312 | + // 单次定位 | ||
| 313 | + if (canLocation) { | ||
| 314 | + Future.delayed(Duration(milliseconds: 200), () async { | ||
| 315 | + /// [hasShow] 隐私权政策是否弹窗展示告知用户 | ||
| 316 | + AMapFlutterLocation.updatePrivacyShow(true, true); | ||
| 317 | + | ||
| 318 | + /// [hasAgree] 隐私权政策是否已经取得用户同意 | ||
| 319 | + AMapFlutterLocation.updatePrivacyAgree(true); | ||
| 320 | + _startLocation(); | ||
| 321 | + // final location = await AmapLocation.instance.fetchLocation( | ||
| 322 | + // // needAddress: true, | ||
| 323 | + // // mode: LocationAccuracy.High, | ||
| 324 | + // // timeout: Duration(seconds: 10) | ||
| 325 | + // ); | ||
| 326 | + | ||
| 327 | + // if (location.city == null || location.city == '') //网络不好,定位失败 | ||
| 328 | + // { | ||
| 329 | + // // App.sp.setString("lat", "39.684670899"); | ||
| 330 | + // // App.sp.setString("lng", "118.17630045"); | ||
| 331 | + // } else { | ||
| 332 | + // if (widget.long == null || | ||
| 333 | + // widget.long == '' || | ||
| 334 | + // widget.long == 'null') { | ||
| 335 | + // latitude = location.latLng!.latitude; | ||
| 336 | + // longitude = location.latLng!.longitude; | ||
| 337 | + // if (_controller != null) { | ||
| 338 | + // _controller!.setCenterCoordinate(LatLng( | ||
| 339 | + // location.latLng!.latitude, location.latLng!.longitude)); | ||
| 340 | + // } | ||
| 341 | + | ||
| 342 | + // page = 1; | ||
| 343 | + | ||
| 344 | + // _loadData( | ||
| 345 | + // LatLng(location.latLng!.latitude, location.latLng!.longitude)); | ||
| 346 | + | ||
| 347 | + // setState(() {}); | ||
| 348 | + // } | ||
| 349 | + // latitudeLocation = location.latLng!.latitude; | ||
| 350 | + // longitudeLocation = location.latLng!.longitude; | ||
| 351 | + // } | ||
| 352 | + }); | ||
| 353 | + } else { | ||
| 354 | + //无权限 | ||
| 355 | + } | ||
| 356 | + } | ||
| 357 | + | ||
| 358 | + // 开始定位 | ||
| 359 | + /// 设置定位参数并启动定位 | ||
| 360 | + void _startLocation() { | ||
| 361 | + /// 开始定位之前设置定位参数 | ||
| 362 | + _setLocationOption(); | ||
| 363 | + _locationPlugin.startLocation(); | ||
| 364 | + } | ||
| 365 | + | ||
| 366 | + /// 停止定位 | ||
| 367 | + /// 停止定位服务 | ||
| 368 | + void _stopLocation() { | ||
| 369 | + _locationPlugin.stopLocation(); | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + void onMapCreated(AMapController controller) { | ||
| 373 | + // setState(() { | ||
| 374 | + _mapController = controller; | ||
| 375 | + // _mapController.moveCamera( | ||
| 376 | + // CameraUpdate.newLatLng(LatLng(latitudeLocation, longitudeLocation)), | ||
| 377 | + // animated: true, | ||
| 378 | + // ); | ||
| 379 | + // getApprovalNumber(); | ||
| 380 | + // }); | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + /// 获取审图号 | ||
| 384 | + // void getApprovalNumber() async { | ||
| 385 | + // //普通地图审图号 | ||
| 386 | + // String mapContentApprovalNumber = | ||
| 387 | + // (await _mapController.getMapContentApprovalNumber()); | ||
| 388 | + // //卫星地图审图号 | ||
| 389 | + // String satelliteImageApprovalNumber = | ||
| 390 | + // (await _mapController.getSatelliteImageApprovalNumber()); | ||
| 391 | + | ||
| 392 | + // print('地图审图号(普通地图): $mapContentApprovalNumber'); | ||
| 393 | + // print('地图审图号(卫星地图): $satelliteImageApprovalNumber'); | ||
| 394 | + // } | ||
| 395 | + | ||
| 396 | + //移动视野 | ||
| 397 | + // void _onCameraMove(CameraPosition cameraPosition) { | ||
| 398 | + // latitude = cameraPosition.target.latitude; | ||
| 399 | + // longitude = cameraPosition.target.longitude; | ||
| 400 | + // page = 1; | ||
| 401 | + // _loadData(cameraPosition.target); | ||
| 402 | + // } | ||
| 403 | + | ||
| 404 | + //移动地图结束 | ||
| 405 | + void _onCameraMoveEnd(CameraPosition cameraPosition) { | ||
| 406 | + setState(() { | ||
| 407 | + _currentZoom = '当前缩放级别:${cameraPosition.zoom}'; | ||
| 408 | + }); | ||
| 409 | + | ||
| 410 | + _mapController.moveCamera( | ||
| 411 | + CameraUpdate.zoomTo(cameraPosition.zoom), | ||
| 412 | + animated: true, | ||
| 413 | + ); | ||
| 414 | + latitude = cameraPosition.target.latitude; | ||
| 415 | + longitude = cameraPosition.target.longitude; | ||
| 416 | + page = 1; | ||
| 417 | + _loadData(cameraPosition.target); | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + @override | ||
| 421 | + Widget build(BuildContext context) { | ||
| 422 | + final AMapWidget amap = AMapWidget( | ||
| 423 | + initialCameraPosition: | ||
| 424 | + CameraPosition(target: LatLng(latitude, longitude), zoom: 16), | ||
| 425 | + onMapCreated: onMapCreated, | ||
| 426 | + // onCameraMove: _onCameraMove, | ||
| 427 | + onCameraMoveEnd: _onCameraMoveEnd, | ||
| 428 | + minMaxZoomPreference: MinMaxZoomPreference(_minZoom, _maxZoom), | ||
| 429 | + scaleEnabled: true, | ||
| 430 | + ); | ||
| 431 | + | ||
| 432 | + return Scaffold( | ||
| 433 | + resizeToAvoidBottomInset: false, //防止底部布局被顶起 | ||
| 434 | + appBar: SystemAppBar( | ||
| 435 | + '选择位置信息', | ||
| 436 | + onTap: () { | ||
| 437 | + if (Navigator.canPop(context)) { | ||
| 438 | + Navigator.pop(context); | ||
| 439 | + } | ||
| 440 | + }, | ||
| 441 | + ), | ||
| 442 | + | ||
| 443 | + body: Column( | ||
| 444 | + children: <Widget>[ | ||
| 445 | + // Theme( | ||
| 446 | + // data: new | ||
| 447 | + // ThemeData( | ||
| 448 | + // // primaryColor: MyColours.color_438E93, | ||
| 449 | + // // hintColor: MyColours.color_438E93), | ||
| 450 | + // child: | ||
| 451 | + // Container( | ||
| 452 | + // color: MyColours.color_438E93, | ||
| 453 | + // decoration: BoxDecoration( | ||
| 454 | + // color: MyColours.color_438E93, | ||
| 455 | + // boxShadow: [ | ||
| 456 | + // BoxShadow(color: Colors.white, spreadRadius: 1), | ||
| 457 | + // ], | ||
| 458 | + // ), | ||
| 459 | + | ||
| 460 | + // padding: EdgeInsets.all(5), | ||
| 461 | + // child: | ||
| 462 | + | ||
| 463 | + // ), | ||
| 464 | + // ), | ||
| 465 | + // ListView.builder( | ||
| 466 | + // shrinkWrap: true, | ||
| 467 | + // itemCount: inputTipDatas.length, | ||
| 468 | + // itemBuilder: (context, index) { | ||
| 469 | + // InputTip inputTip = inputTipDatas[index]; | ||
| 470 | + // return InkWell( | ||
| 471 | + // onTap: () { | ||
| 472 | + // // searchAroundAddress(inputTip.name ?? ''); | ||
| 473 | + // // searchPoiId(inputTip.poiId ?? ''); | ||
| 474 | + // // _loadData(inputTip.coordinate ?? | ||
| 475 | + // // LatLng(latitude, longitude)); | ||
| 476 | + // }, | ||
| 477 | + // child: Container( | ||
| 478 | + // child: Row( | ||
| 479 | + // children: [ | ||
| 480 | + // Text( | ||
| 481 | + // inputTip.name ?? '', | ||
| 482 | + // style: TextStyle( | ||
| 483 | + // fontSize: font(15), | ||
| 484 | + // color: MyColours.color_515151), | ||
| 485 | + // ), | ||
| 486 | + // HEmptyView(10), | ||
| 487 | + // Expanded( | ||
| 488 | + // child: Text( | ||
| 489 | + // (inputTip.district ?? '') + | ||
| 490 | + // (inputTip.address ?? ''), | ||
| 491 | + // style: TextStyle( | ||
| 492 | + // fontSize: font(13), | ||
| 493 | + // color: MyColours.color_999999), | ||
| 494 | + // ), | ||
| 495 | + // ), | ||
| 496 | + // ], | ||
| 497 | + // ))); | ||
| 498 | + // }) | ||
| 499 | + // ], | ||
| 500 | + // ), | ||
| 501 | + | ||
| 502 | + Stack( | ||
| 503 | + children: [ | ||
| 504 | + Container( | ||
| 505 | + height: w(300), | ||
| 506 | + child: Stack( | ||
| 507 | + children: <Widget>[ | ||
| 508 | + amap, | ||
| 509 | + // AmapView( | ||
| 510 | + // showZoomControl: false, | ||
| 511 | + | ||
| 512 | + // /// 是否显示指南针控件 | ||
| 513 | + // showCompass: true, | ||
| 514 | + | ||
| 515 | + // /// 是否显示比例尺控件 | ||
| 516 | + // showScaleControl: true, | ||
| 517 | + | ||
| 518 | + // /// 是否使能缩放手势 | ||
| 519 | + // zoomGesturesEnabled: true, | ||
| 520 | + | ||
| 521 | + // /// 是否使能滚动手势 | ||
| 522 | + // scrollGesturesEnabled: true, | ||
| 523 | + | ||
| 524 | + // /// 是否使能旋转手势 | ||
| 525 | + // rotateGestureEnabled: false, | ||
| 526 | + // centerCoordinate: LatLng(latitude, longitude), | ||
| 527 | + // maskDelay: Duration(milliseconds: 500), | ||
| 528 | + // zoomLevel: 19, | ||
| 529 | + // onMapCreated: (controller) async { | ||
| 530 | + // _controller = controller; | ||
| 531 | + // _controller! | ||
| 532 | + // .setCenterCoordinate(LatLng(latitude, longitude)); | ||
| 533 | + // // if (await requestPermission(PermissionGroup.location)) { | ||
| 534 | + // // await controller.showMyLocation(true); | ||
| 535 | + // // await controller?.showLocateControl(true); | ||
| 536 | + // // final latLng = await _controller?.getLocation( | ||
| 537 | + // // delay: Duration(seconds: 2)); | ||
| 538 | + // // await enableFluttifyLog(false); // 关闭log | ||
| 539 | + // // _loadData(latLng); | ||
| 540 | + // // } else { | ||
| 541 | + // // //无权限 | ||
| 542 | + // // _showLocPemWidget(); | ||
| 543 | + // // } | ||
| 544 | + // }, | ||
| 545 | + // // markers: [], | ||
| 546 | + // onMapMoveEnd: (MapMove move) async { | ||
| 547 | + // latitude = move.coordinate!.latitude; | ||
| 548 | + // longitude = move.coordinate!.longitude; | ||
| 549 | + // page = 1; | ||
| 550 | + // _loadData(move.coordinate!); | ||
| 551 | + // }, | ||
| 552 | + // ), | ||
| 553 | + Center( | ||
| 554 | + child: Icon( | ||
| 555 | + Icons.place, | ||
| 556 | + size: w(32), | ||
| 557 | + color: Color(0xFFFF0000), | ||
| 558 | + ), | ||
| 559 | + ), | ||
| 560 | + Positioned( | ||
| 561 | + right: w(10), | ||
| 562 | + bottom: w(10), | ||
| 563 | + child: InkWell( | ||
| 564 | + onTap: () { | ||
| 565 | + _mapController.moveCamera( | ||
| 566 | + CameraUpdate.newLatLng( | ||
| 567 | + LatLng(latitudeLocation, longitudeLocation)), | ||
| 568 | + animated: true, | ||
| 569 | + ); | ||
| 570 | + }, | ||
| 571 | + child: Container( | ||
| 572 | + decoration: BoxDecoration( | ||
| 573 | + color: MyColours.color_ffffff, | ||
| 574 | + borderRadius: BorderRadius.circular(r(5))), | ||
| 575 | + padding: EdgeInsets.all(w(5)), | ||
| 576 | + child: Image.asset( | ||
| 577 | + Utils.getImgPath('location_map'), | ||
| 578 | + width: w(25), | ||
| 579 | + ), | ||
| 580 | + )), | ||
| 581 | + ) | ||
| 582 | + ], | ||
| 583 | + ), | ||
| 584 | + ), | ||
| 585 | + Positioned( | ||
| 586 | + top: w(10), | ||
| 587 | + left: w(20), | ||
| 588 | + right: w(20), | ||
| 589 | + child: Container( | ||
| 590 | + // height: w(45), | ||
| 591 | + padding: EdgeInsets.symmetric(vertical: w(10)), | ||
| 592 | + decoration: BoxDecoration( | ||
| 593 | + color: Colors.white, | ||
| 594 | + borderRadius: BorderRadius.circular(r(10))), | ||
| 595 | + child: TextField( | ||
| 596 | + textAlignVertical: TextAlignVertical.center, | ||
| 597 | + style: TextStyle( | ||
| 598 | + color: MyColours.color_515151, | ||
| 599 | + fontSize: font(15), | ||
| 600 | + ), | ||
| 601 | + controller: | ||
| 602 | + TextEditingController.fromValue(TextEditingValue( | ||
| 603 | + // 设置内容 | ||
| 604 | + text: keyword, | ||
| 605 | + selection: TextSelection.fromPosition(TextPosition( | ||
| 606 | + affinity: TextAffinity.downstream, | ||
| 607 | + offset: keyword.length)), | ||
| 608 | + // 保持光标在最后 | ||
| 609 | + )), | ||
| 610 | + decoration: InputDecoration( | ||
| 611 | + // border: b, | ||
| 612 | + // border: OutlineInputBorder( | ||
| 613 | + // borderRadius: BorderRadius.all(Radius.circular(40)), | ||
| 614 | + // ), | ||
| 615 | + border: OutlineInputBorder(borderSide: BorderSide.none), | ||
| 616 | + hintText: '输入关键字', | ||
| 617 | + isCollapsed: true, | ||
| 618 | + | ||
| 619 | + hintStyle: TextStyle( | ||
| 620 | + color: MyColours.color_999999, fontSize: font(15)), | ||
| 621 | + // contentPadding: const EdgeInsets.symmetric( | ||
| 622 | + // vertical: 8, horizontal: 1), | ||
| 623 | + prefixIconConstraints: BoxConstraints(maxWidth: w(40)), | ||
| 624 | + prefixIcon: Padding( | ||
| 625 | + padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 626 | + child: SizedBox( | ||
| 627 | + width: w(30), | ||
| 628 | + child: Image.asset( | ||
| 629 | + Utils.getImgPath('search_black'), | ||
| 630 | + ))), | ||
| 631 | + suffixIconConstraints: BoxConstraints(maxWidth: w(32)), | ||
| 632 | + suffixIcon: InkWell( | ||
| 633 | + child: Padding( | ||
| 634 | + padding: EdgeInsets.only(left: w(10), right: w(10)), | ||
| 635 | + child: SizedBox( | ||
| 636 | + width: w(22), | ||
| 637 | + child: Image.asset( | ||
| 638 | + Utils.getImgPath('delete_black'), | ||
| 639 | + ))), | ||
| 640 | + onTap: () { | ||
| 641 | + keyword = ""; | ||
| 642 | + setState(() {}); | ||
| 643 | + }, | ||
| 644 | + ), | ||
| 645 | + fillColor: Colors.white, | ||
| 646 | + filled: true, | ||
| 647 | + ), | ||
| 648 | + | ||
| 649 | + inputFormatters: [], | ||
| 650 | + //内容改变的回调 | ||
| 651 | + onChanged: (text) { | ||
| 652 | + print('change $text'); | ||
| 653 | + keyword = text; | ||
| 654 | + | ||
| 655 | + //搜索 | ||
| 656 | + | ||
| 657 | + if (text != null && text.trim().length > 0) { | ||
| 658 | + JhCommonUtils.debounce( | ||
| 659 | + () => _fetchInputTips(text.toString())); | ||
| 660 | + } | ||
| 661 | + }, | ||
| 662 | + //内容提交(按回车)的回调 | ||
| 663 | + onSubmitted: (text) { | ||
| 664 | + print('submit $text'); | ||
| 665 | + // 触发关闭弹出来的键盘。 | ||
| 666 | + keyword = text; | ||
| 667 | + FocusScope.of(context).requestFocus(FocusNode()); | ||
| 668 | + setState(() { | ||
| 669 | + // isloading = true; | ||
| 670 | + }); | ||
| 671 | + | ||
| 672 | + // _fetchInputTips(text.toString()); | ||
| 673 | + | ||
| 674 | + // searchAroundAddress(text.toString()); | ||
| 675 | + }, | ||
| 676 | + //按回车时调用 | ||
| 677 | + onEditingComplete: () { | ||
| 678 | + print('onEditingComplete'); | ||
| 679 | + }, | ||
| 680 | + ), | ||
| 681 | + ), | ||
| 682 | + ) | ||
| 683 | + ], | ||
| 684 | + ), | ||
| 685 | + | ||
| 686 | + Expanded( | ||
| 687 | + flex: 1, | ||
| 688 | + child: Visibility( | ||
| 689 | + visible: !isloading, | ||
| 690 | + maintainSize: false, | ||
| 691 | + maintainSemantics: false, | ||
| 692 | + maintainInteractivity: false, | ||
| 693 | + replacement: Center( | ||
| 694 | + child: CupertinoActivityIndicator(), | ||
| 695 | + ), | ||
| 696 | + child: EasyRefresh.custom( | ||
| 697 | + controller: refreshController, | ||
| 698 | + slivers: [ | ||
| 699 | + SliverList( | ||
| 700 | + delegate: SliverChildBuilderDelegate( | ||
| 701 | + (BuildContext context, int position) { | ||
| 702 | + print("itemBuilder" + list.length.toString()); | ||
| 703 | + PoiModel item = list[position]!; | ||
| 704 | + return InkWell( | ||
| 705 | + child: Column( | ||
| 706 | + children: <Widget>[ | ||
| 707 | + Container( | ||
| 708 | + margin: EdgeInsets.only( | ||
| 709 | + top: 8, bottom: 5, left: 10), | ||
| 710 | + child: Row( | ||
| 711 | + children: <Widget>[ | ||
| 712 | + Icon( | ||
| 713 | + Icons.place, | ||
| 714 | + size: 20.0, | ||
| 715 | + color: position == 0 | ||
| 716 | + ? Colors.green | ||
| 717 | + : Colors.grey, | ||
| 718 | + ), | ||
| 719 | + Expanded( | ||
| 720 | + child: Text(item.title, | ||
| 721 | + style: TextStyle( | ||
| 722 | + fontSize: 16, | ||
| 723 | + color: position == 0 | ||
| 724 | + ? Colors.green | ||
| 725 | + : Color(0xFF787878)))) | ||
| 726 | + ], | ||
| 727 | + ), | ||
| 728 | + ), | ||
| 729 | + Container( | ||
| 730 | + margin: EdgeInsets.only( | ||
| 731 | + top: 5, bottom: 5, left: 18), | ||
| 732 | + alignment: Alignment.centerLeft, | ||
| 733 | + child: Text( | ||
| 734 | + item.address!, | ||
| 735 | + style: TextStyle( | ||
| 736 | + fontSize: 14, | ||
| 737 | + color: Color(0xFF646464), | ||
| 738 | + ), | ||
| 739 | + ), | ||
| 740 | + ), | ||
| 741 | + Divider( | ||
| 742 | + height: 1, | ||
| 743 | + ) | ||
| 744 | + ], | ||
| 745 | + ), | ||
| 746 | + onTap: () async { | ||
| 747 | + // await _controller.setCenterCoordinate( | ||
| 748 | + // LatLng(item.latLng.latitude, item.latLng.longitude), | ||
| 749 | + // zoomLevel: 16); | ||
| 750 | + if (Navigator.canPop(context)) { | ||
| 751 | + Navigator.pop(context, { | ||
| 752 | + 'address': item.address, | ||
| 753 | + 'lat': item.latLng!.latitude.toString(), | ||
| 754 | + 'lng': item.latLng!.longitude.toString() | ||
| 755 | + }); | ||
| 756 | + } | ||
| 757 | + }, | ||
| 758 | + ); | ||
| 759 | + }, | ||
| 760 | + childCount: list.length, | ||
| 761 | + ), | ||
| 762 | + ) | ||
| 763 | + ], | ||
| 764 | + onRefresh: () async { | ||
| 765 | + if (flag) { | ||
| 766 | + page = 1; | ||
| 767 | + _loadData(LatLng(latitude, longitude)); | ||
| 768 | + } | ||
| 769 | + }, | ||
| 770 | + onLoad: () async { | ||
| 771 | + if (flag) { | ||
| 772 | + page++; | ||
| 773 | + _loadData(LatLng(latitude, longitude), | ||
| 774 | + showloading: false); | ||
| 775 | + } | ||
| 776 | + }, | ||
| 777 | + )), | ||
| 778 | + ), | ||
| 779 | + ], | ||
| 780 | + ), | ||
| 781 | + ); | ||
| 782 | + } | ||
| 783 | + | ||
| 784 | + _fetchInputTips(String text) async { | ||
| 785 | + flag = false; | ||
| 786 | + page = 1; | ||
| 787 | + // setState(() { | ||
| 788 | + // isloading = true; | ||
| 789 | + // }); | ||
| 790 | + | ||
| 791 | + /// 逆地理编码(坐标转地址) | ||
| 792 | + /// | ||
| 793 | + /// | ||
| 794 | + // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 795 | + // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 796 | + | ||
| 797 | + LatLng latLng = LatLng(latitude, longitude); | ||
| 798 | + | ||
| 799 | + address = await _locationPlugin | ||
| 800 | + .onGeocodeSearch(true, [latLng.longitude, latLng.latitude]); | ||
| 801 | + | ||
| 802 | + // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 803 | + // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 804 | + | ||
| 805 | + List<dynamic> temp = await _locationPlugin.doInputtipsRequest( | ||
| 806 | + text, | ||
| 807 | + city: "", | ||
| 808 | + ); | ||
| 809 | + | ||
| 810 | + inputTipDatas = []; | ||
| 811 | + | ||
| 812 | + temp.forEach((element) { | ||
| 813 | + inputTipDatas.add(MapInputsModel.fromJson(element)); | ||
| 814 | + }); | ||
| 815 | + | ||
| 816 | + print(inputTipDatas); | ||
| 817 | + poiModel = new PoiModel("当前位置", address, latLng); | ||
| 818 | + list.clear(); | ||
| 819 | + list.add(poiModel); | ||
| 820 | + for (var inputTip in inputTipDatas) { | ||
| 821 | + String? title = await inputTip.name ?? ''; | ||
| 822 | + String? cityStr = (inputTip.district ?? '') + (inputTip.city ?? ''); | ||
| 823 | + | ||
| 824 | + // LatLng? latLng = await inputTip.point; | ||
| 825 | + | ||
| 826 | + list.add(new PoiModel(title.toString(), cityStr, latLng)); | ||
| 827 | + } | ||
| 828 | + | ||
| 829 | + print(list); | ||
| 830 | + | ||
| 831 | + setState(() { | ||
| 832 | + // isloading = false; | ||
| 833 | + }); | ||
| 834 | + } | ||
| 835 | + | ||
| 836 | + void _loadData(LatLng latLng, {showloading = true}) async { | ||
| 837 | + flag = true; | ||
| 838 | + setState(() { | ||
| 839 | + if (showloading) { | ||
| 840 | + isloading = true; | ||
| 841 | + } | ||
| 842 | + }); | ||
| 843 | + | ||
| 844 | + /// 逆地理编码(坐标转地址) | ||
| 845 | + /// | ||
| 846 | + /// | ||
| 847 | + /// | ||
| 848 | + | ||
| 849 | + // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 850 | + // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 851 | + if (page == 1) { | ||
| 852 | + address = await _locationPlugin | ||
| 853 | + .onGeocodeSearch(true, [latLng.longitude, latLng.latitude]); | ||
| 854 | + poiModel = new PoiModel("当前位置", address, latLng); | ||
| 855 | + list.clear(); | ||
| 856 | + list.add(poiModel); | ||
| 857 | + } | ||
| 858 | + // final poiList | ||
| 859 | + List<dynamic> temp = await _locationPlugin.poiSearchAround( | ||
| 860 | + keyword, latLng.longitude, latLng.latitude); | ||
| 861 | + | ||
| 862 | + List<MapRoundSearchModel> searchData = []; | ||
| 863 | + | ||
| 864 | + temp.forEach((element) { | ||
| 865 | + searchData.add(MapRoundSearchModel.fromJson(element)); | ||
| 866 | + }); | ||
| 867 | + | ||
| 868 | + print(searchData); | ||
| 869 | + | ||
| 870 | + for (var poi in searchData) { | ||
| 871 | + String? title = await poi.title; | ||
| 872 | + String? cityName = await poi.cityName; | ||
| 873 | + String? provinceName = await poi.provinceName; | ||
| 874 | + String? snippet = await poi.snippet; | ||
| 875 | + String? adName = await poi.adName; | ||
| 876 | + LatLng? latLng = LatLng(poi.latitude ?? 0, poi.longitude ?? 0); | ||
| 877 | + String? bussniss = poi.businessArea; | ||
| 878 | + | ||
| 879 | + list.add(new PoiModel( | ||
| 880 | + title.toString(), | ||
| 881 | + provinceName.toString() + | ||
| 882 | + cityName.toString() + | ||
| 883 | + adName.toString() + | ||
| 884 | + // address.toString() + | ||
| 885 | + bussniss.toString() + | ||
| 886 | + snippet.toString(), | ||
| 887 | + latLng)); | ||
| 888 | + } | ||
| 889 | + | ||
| 890 | + setState(() { | ||
| 891 | + if (showloading) { | ||
| 892 | + isloading = false; | ||
| 893 | + } | ||
| 894 | + }); | ||
| 895 | + } | ||
| 896 | + | ||
| 897 | + // void searchPoiId(String text) async { | ||
| 898 | + // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 899 | + // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 900 | + // Poi? poi = await AmapSearch.instance.searchPoiId( | ||
| 901 | + // text, | ||
| 902 | + // ); | ||
| 903 | + // print(poi); | ||
| 904 | + // } | ||
| 905 | + | ||
| 906 | + // void searchAroundAddress(String text) async { | ||
| 907 | + // await AmapLocation.instance.updatePrivacyShow(true); | ||
| 908 | + // await AmapLocation.instance.updatePrivacyAgree(true); | ||
| 909 | + // final poiList = await AmapSearch.instance.searchKeyword( | ||
| 910 | + // text, | ||
| 911 | + // city: "", | ||
| 912 | + // ); | ||
| 913 | + // // final poiList = await AmapSearch.instance.searchAround( | ||
| 914 | + // // LatLng(latitude, longitude), | ||
| 915 | + // // city: "", | ||
| 916 | + // // radius: 100000000000000 | ||
| 917 | + | ||
| 918 | + // // ); | ||
| 919 | + | ||
| 920 | + // list.clear(); | ||
| 921 | + // list.add(poiModel); | ||
| 922 | + // for (var poi in poiList) { | ||
| 923 | + // String? title = await poi.title; | ||
| 924 | + // LatLng? latLng = await poi.latLng; | ||
| 925 | + // String? cityName = await poi.cityName; | ||
| 926 | + // String? provinceName = await poi.provinceName; | ||
| 927 | + // String? address = await poi.address; | ||
| 928 | + // list.add(new PoiModel( | ||
| 929 | + // title.toString(), | ||
| 930 | + // provinceName.toString() + cityName.toString() + address.toString(), | ||
| 931 | + // latLng)); | ||
| 932 | + // } | ||
| 933 | + // setState(() { | ||
| 934 | + // isloading = false; | ||
| 935 | + // FocusScope.of(context).requestFocus(FocusNode()); | ||
| 936 | + // }); | ||
| 937 | + // } | ||
| 938 | +} | ||
| 939 | + | ||
| 940 | +class PoiModel { | ||
| 941 | + LatLng? latLng; | ||
| 942 | + String title; | ||
| 943 | + String? address; | ||
| 944 | + | ||
| 945 | + PoiModel(this.title, this.address, this.latLng); | ||
| 946 | +} |
| 1 | 1 | ||
| 2 | -// import 'package:device_info/device_info.dart'; | ||
| 3 | -// import 'package:device_info_plus/device_info_plus.dart'; | ||
| 4 | -import 'package:flutter/material.dart'; | ||
| 5 | -import 'package:flutter_inappwebview/flutter_inappwebview.dart'; | ||
| 6 | -import 'package:one_key/net/dio_util.dart'; | ||
| 7 | -import 'package:one_key/res/colors.dart'; | ||
| 8 | -import 'package:one_key/utils/utils.dart'; | ||
| 9 | -import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 10 | -import 'package:path_provider/path_provider.dart'; | ||
| 11 | -// import 'package:permission_handler/permission_handler.dart'; | ||
| 12 | -// import 'package:webview_flutter/webview_flutter.dart'; | ||
| 13 | - | ||
| 14 | -import 'dart:io'; | ||
| 15 | - | ||
| 16 | -// import 'package:webview_flutter/webview_flutter.dart'; | ||
| 17 | - | 2 | +// // import 'package:device_info/device_info.dart'; |
| 3 | +// // import 'package:device_info_plus/device_info_plus.dart'; | ||
| 4 | +// import 'package:flutter/material.dart'; | ||
| 18 | // import 'package:flutter_inappwebview/flutter_inappwebview.dart'; | 5 | // import 'package:flutter_inappwebview/flutter_inappwebview.dart'; |
| 19 | -import 'package:url_launcher/url_launcher.dart'; | ||
| 20 | -import 'dart:collection'; | ||
| 21 | -// import 'package:open_file/open_file.dart'; | ||
| 22 | -// import 'package:flutter_downloader/flutter_downloader.dart'; | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | - * 我的-----帮助与反馈页面 ----- 目前已经功能已经屏蔽 | ||
| 26 | - */ | 6 | +// import 'package:one_key/net/dio_util.dart'; |
| 7 | +// import 'package:one_key/res/colors.dart'; | ||
| 8 | +// import 'package:one_key/utils/utils.dart'; | ||
| 9 | +// import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 10 | +// import 'package:path_provider/path_provider.dart'; | ||
| 11 | +// // import 'package:permission_handler/permission_handler.dart'; | ||
| 12 | +// // import 'package:webview_flutter/webview_flutter.dart'; | ||
| 27 | 13 | ||
| 28 | -class WebPage extends StatefulWidget { | ||
| 29 | - final String? title; | ||
| 30 | - final String? url; | ||
| 31 | - final bool need; | 14 | +// import 'dart:io'; |
| 32 | 15 | ||
| 33 | - const WebPage({Key? key, this.title, this.url, this.need = false}) | ||
| 34 | - : super(key: key); | ||
| 35 | - @override | ||
| 36 | - _WebPageState createState() => _WebPageState(); | ||
| 37 | -} | 16 | +// // import 'package:webview_flutter/webview_flutter.dart'; |
| 38 | 17 | ||
| 39 | -class _WebPageState extends State<WebPage> { | ||
| 40 | - final GlobalKey webViewKey = GlobalKey(); | 18 | +// // import 'package:flutter_inappwebview/flutter_inappwebview.dart'; |
| 19 | +// import 'package:url_launcher/url_launcher.dart'; | ||
| 20 | +// import 'dart:collection'; | ||
| 21 | +// // import 'package:open_file/open_file.dart'; | ||
| 22 | +// // import 'package:flutter_downloader/flutter_downloader.dart'; | ||
| 41 | 23 | ||
| 42 | - InAppWebViewController? webViewController; | ||
| 43 | - InAppWebViewGroupOptions options = InAppWebViewGroupOptions( | ||
| 44 | - crossPlatform: InAppWebViewOptions( | ||
| 45 | - useShouldOverrideUrlLoading: true, | ||
| 46 | - useOnDownloadStart: true, | ||
| 47 | - mediaPlaybackRequiresUserGesture: false, | ||
| 48 | - ), | ||
| 49 | - android: AndroidInAppWebViewOptions( | ||
| 50 | - useHybridComposition: true, | ||
| 51 | - ), | ||
| 52 | - ios: IOSInAppWebViewOptions( | ||
| 53 | - allowsInlineMediaPlayback: true, | ||
| 54 | - )); | 24 | +// /** |
| 25 | +// * 我的-----帮助与反馈页面 ----- 目前已经功能已经屏蔽 | ||
| 26 | +// */ | ||
| 55 | 27 | ||
| 56 | - PullToRefreshController? pullToRefreshController; | ||
| 57 | - ContextMenu? contextMenu; | ||
| 58 | - String url = ""; | ||
| 59 | - double progress = 0; | ||
| 60 | - final urlController = TextEditingController(); | ||
| 61 | - // Future<void> openFile(filePath) async { | ||
| 62 | - // final _result = await OpenFile.open(filePath); | ||
| 63 | - // print(_result.message); | ||
| 64 | - | ||
| 65 | - // // setState(() { | ||
| 66 | - // // _openResult = "type=${_result.type} message=${_result.message}"; | ||
| 67 | - // // }); | ||
| 68 | - // } | ||
| 69 | - | ||
| 70 | - @override | ||
| 71 | - void initState() { | ||
| 72 | - super.initState(); | 28 | +// class WebPage extends StatefulWidget { |
| 29 | +// final String? title; | ||
| 30 | +// final String? url; | ||
| 31 | +// final bool need; | ||
| 73 | 32 | ||
| 74 | - // Enable hybrid composition. | ||
| 75 | - _init(); | ||
| 76 | - } | 33 | +// const WebPage({Key? key, this.title, this.url, this.need = false}) |
| 34 | +// : super(key: key); | ||
| 35 | +// @override | ||
| 36 | +// _WebPageState createState() => _WebPageState(); | ||
| 37 | +// } | ||
| 77 | 38 | ||
| 78 | - @override | ||
| 79 | - void dispose() { | ||
| 80 | - if (widget.need) { | ||
| 81 | - Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 82 | - } | 39 | +// class _WebPageState extends State<WebPage> { |
| 40 | +// final GlobalKey webViewKey = GlobalKey(); | ||
| 83 | 41 | ||
| 84 | - super.dispose(); | ||
| 85 | - } | 42 | +// InAppWebViewController? webViewController; |
| 43 | +// InAppWebViewGroupOptions options = InAppWebViewGroupOptions( | ||
| 44 | +// crossPlatform: InAppWebViewOptions( | ||
| 45 | +// useShouldOverrideUrlLoading: true, | ||
| 46 | +// useOnDownloadStart: true, | ||
| 47 | +// mediaPlaybackRequiresUserGesture: false, | ||
| 48 | +// ), | ||
| 49 | +// android: AndroidInAppWebViewOptions( | ||
| 50 | +// useHybridComposition: true, | ||
| 51 | +// ), | ||
| 52 | +// ios: IOSInAppWebViewOptions( | ||
| 53 | +// allowsInlineMediaPlayback: true, | ||
| 54 | +// )); | ||
| 86 | 55 | ||
| 87 | - // Future<bool> _checkPermission() async { | ||
| 88 | - // DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); | ||
| 89 | - // AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; | ||
| 90 | - // if (Platform.isAndroid && androidInfo.version.sdkInt <= 28) { | ||
| 91 | - // final status = await Permission.storage.status; | ||
| 92 | - // if (status != PermissionStatus.granted) { | ||
| 93 | - // final result = await Permission.storage.request(); | ||
| 94 | - // if (result == PermissionStatus.granted) { | ||
| 95 | - // return true; | ||
| 96 | - // } | ||
| 97 | - // } else { | ||
| 98 | - // return true; | ||
| 99 | - // } | ||
| 100 | - // } else { | ||
| 101 | - // return true; | ||
| 102 | - // } | ||
| 103 | - // return false; | ||
| 104 | - // } | 56 | +// PullToRefreshController? pullToRefreshController; |
| 57 | +// ContextMenu? contextMenu; | ||
| 58 | +// String url = ""; | ||
| 59 | +// double progress = 0; | ||
| 60 | +// final urlController = TextEditingController(); | ||
| 61 | +// // Future<void> openFile(filePath) async { | ||
| 62 | +// // final _result = await OpenFile.open(filePath); | ||
| 63 | +// // print(_result.message); | ||
| 105 | 64 | ||
| 106 | - // Future<bool> checkPermissionStorage() async { | ||
| 107 | - // var status = await Permission.storage.status; | ||
| 108 | - // if (!status.isGranted) { | ||
| 109 | - // status = await Permission.storage.request(); | ||
| 110 | - // if (status.isGranted) { | ||
| 111 | - // return true; | ||
| 112 | - // } | ||
| 113 | - // } else { | ||
| 114 | - // return true; | ||
| 115 | - // } | ||
| 116 | - // return false; | ||
| 117 | - // } | 65 | +// // // setState(() { |
| 66 | +// // // _openResult = "type=${_result.type} message=${_result.message}"; | ||
| 67 | +// // // }); | ||
| 68 | +// // } | ||
| 118 | 69 | ||
| 119 | - _init() async { | ||
| 120 | - // WidgetsFlutterBinding.ensureInitialized(); | ||
| 121 | - // await FlutterDownloader.initialize(debug: true); | ||
| 122 | - if (Platform.isAndroid) { | ||
| 123 | - await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true); | 70 | +// @override |
| 71 | +// void initState() { | ||
| 72 | +// super.initState(); | ||
| 124 | 73 | ||
| 125 | - var swAvailable = await AndroidWebViewFeature.isFeatureSupported( | ||
| 126 | - AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE); | ||
| 127 | - var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported( | ||
| 128 | - AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST); | 74 | +// // Enable hybrid composition. |
| 75 | +// _init(); | ||
| 76 | +// } | ||
| 129 | 77 | ||
| 130 | - if (swAvailable && swInterceptAvailable) { | ||
| 131 | - AndroidServiceWorkerController serviceWorkerController = | ||
| 132 | - AndroidServiceWorkerController.instance(); | 78 | +// @override |
| 79 | +// void dispose() { | ||
| 80 | +// if (widget.need) { | ||
| 81 | +// Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 82 | +// } | ||
| 133 | 83 | ||
| 134 | - serviceWorkerController.serviceWorkerClient = | ||
| 135 | - AndroidServiceWorkerClient( | ||
| 136 | - shouldInterceptRequest: (request) async { | ||
| 137 | - print(request); | ||
| 138 | - return null; | ||
| 139 | - }, | ||
| 140 | - ); | ||
| 141 | - } | ||
| 142 | - } | ||
| 143 | - // await FlutterDownloader.initialize( | ||
| 144 | - // debug: true // optional: set false to disable printing logs to console | ||
| 145 | - // ); | ||
| 146 | - // await Permission.storage.request(); | ||
| 147 | - } | 84 | +// super.dispose(); |
| 85 | +// } | ||
| 148 | 86 | ||
| 149 | - @override | ||
| 150 | - Widget build(BuildContext context) { | ||
| 151 | - return Scaffold( | ||
| 152 | - // We're using a Builder here so we have a context that is below the Scaffold | ||
| 153 | - // to allow calling Scaffold.of(context) so we can show a snackbar. | ||
| 154 | - appBar: SystemAppBar( | ||
| 155 | - widget.title, | ||
| 156 | - ), | ||
| 157 | - body: Column( | ||
| 158 | - children: [ | ||
| 159 | - Expanded( | ||
| 160 | - child: InAppWebView( | ||
| 161 | - key: webViewKey, | ||
| 162 | - // contextMenu: contextMenu, | ||
| 163 | - initialUrlRequest: URLRequest( | ||
| 164 | - url: Uri.parse("http://colorcun.com/privacy1.html")), | ||
| 165 | - // url: WebUri("http://colorcun.com/privacy2.html")), | ||
| 166 | - //华为下载功能闪退,去掉下载功能*********http://colorcun.com/privacy2.html | ||
| 167 | - // initialFile: "assets/index.html", | ||
| 168 | - initialUserScripts: UnmodifiableListView<UserScript>([]), | ||
| 169 | - initialOptions: options, | ||
| 170 | - pullToRefreshController: pullToRefreshController, | ||
| 171 | - onWebViewCreated: (controller) { | ||
| 172 | - webViewController = controller; | ||
| 173 | - }, | ||
| 174 | - onLoadStart: (controller, url) { | ||
| 175 | - setState(() { | ||
| 176 | - this.url = url.toString(); | ||
| 177 | - urlController.text = this.url; | ||
| 178 | - }); | ||
| 179 | - }, | ||
| 180 | - androidOnPermissionRequest: | ||
| 181 | - (controller, origin, resources) async { | ||
| 182 | - return PermissionRequestResponse( | ||
| 183 | - resources: resources, | ||
| 184 | - action: PermissionRequestResponseAction.GRANT); | ||
| 185 | - }, | ||
| 186 | - shouldOverrideUrlLoading: (controller, navigationAction) async { | ||
| 187 | - var uri = navigationAction.request.url!; | 87 | +// // Future<bool> _checkPermission() async { |
| 88 | +// // DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); | ||
| 89 | +// // AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; | ||
| 90 | +// // if (Platform.isAndroid && androidInfo.version.sdkInt <= 28) { | ||
| 91 | +// // final status = await Permission.storage.status; | ||
| 92 | +// // if (status != PermissionStatus.granted) { | ||
| 93 | +// // final result = await Permission.storage.request(); | ||
| 94 | +// // if (result == PermissionStatus.granted) { | ||
| 95 | +// // return true; | ||
| 96 | +// // } | ||
| 97 | +// // } else { | ||
| 98 | +// // return true; | ||
| 99 | +// // } | ||
| 100 | +// // } else { | ||
| 101 | +// // return true; | ||
| 102 | +// // } | ||
| 103 | +// // return false; | ||
| 104 | +// // } | ||
| 188 | 105 | ||
| 189 | - if (![ | ||
| 190 | - "http", | ||
| 191 | - "https", | ||
| 192 | - "file", | ||
| 193 | - "chrome", | ||
| 194 | - "data", | ||
| 195 | - "javascript", | ||
| 196 | - "about" | ||
| 197 | - ].contains(uri.scheme)) { | ||
| 198 | - if (await canLaunch(url)) { | ||
| 199 | - // Launch the App | ||
| 200 | - await launch( | ||
| 201 | - url, | ||
| 202 | - ); | ||
| 203 | - // and cancel the request | ||
| 204 | - return NavigationActionPolicy.CANCEL; | ||
| 205 | - } | ||
| 206 | - } | 106 | +// // Future<bool> checkPermissionStorage() async { |
| 107 | +// // var status = await Permission.storage.status; | ||
| 108 | +// // if (!status.isGranted) { | ||
| 109 | +// // status = await Permission.storage.request(); | ||
| 110 | +// // if (status.isGranted) { | ||
| 111 | +// // return true; | ||
| 112 | +// // } | ||
| 113 | +// // } else { | ||
| 114 | +// // return true; | ||
| 115 | +// // } | ||
| 116 | +// // return false; | ||
| 117 | +// // } | ||
| 207 | 118 | ||
| 208 | - return NavigationActionPolicy.ALLOW; | ||
| 209 | - }, | ||
| 210 | - onLoadStop: (controller, url) async { | ||
| 211 | - pullToRefreshController!.endRefreshing(); | ||
| 212 | - setState(() { | ||
| 213 | - this.url = url.toString(); | ||
| 214 | - urlController.text = this.url; | ||
| 215 | - }); | ||
| 216 | - }, | ||
| 217 | - onLoadError: (controller, url, code, message) { | ||
| 218 | - pullToRefreshController!.endRefreshing(); | ||
| 219 | - }, | ||
| 220 | - onProgressChanged: (controller, progress) { | ||
| 221 | - if (progress == 100) { | ||
| 222 | - pullToRefreshController!.endRefreshing(); | ||
| 223 | - } | ||
| 224 | - setState(() { | ||
| 225 | - this.progress = progress / 100; | ||
| 226 | - urlController.text = this.url; | ||
| 227 | - }); | ||
| 228 | - }, | ||
| 229 | - onUpdateVisitedHistory: (controller, url, androidIsReload) { | ||
| 230 | - setState(() { | ||
| 231 | - this.url = url.toString(); | ||
| 232 | - urlController.text = this.url; | ||
| 233 | - }); | ||
| 234 | - }, | ||
| 235 | - onConsoleMessage: (controller, consoleMessage) { | ||
| 236 | - print(consoleMessage); | ||
| 237 | - }, | ||
| 238 | - onDownloadStart: (controller, url) async { | ||
| 239 | - print("onDownloadStart $url"); | ||
| 240 | - Utils.showToast('开始下载...'); | ||
| 241 | - // final taskId = await FlutterDownloader.enqueue( | ||
| 242 | - // url: url.toString(), | ||
| 243 | - // savedDir: (await getExternalStorageDirectory()).path, | ||
| 244 | - // showNotification: | ||
| 245 | - // true, // show download progress in status bar (for Android) | ||
| 246 | - // openFileFromNotification: | ||
| 247 | - // true, // click on notification to open downloaded file (for Android) | ||
| 248 | - // ); | ||
| 249 | - final dir = (await getExternalStorageDirectory())!; | ||
| 250 | - String savePath = dir.path + "/one_key"; | 119 | +// _init() async { |
| 120 | +// // WidgetsFlutterBinding.ensureInitialized(); | ||
| 121 | +// // await FlutterDownloader.initialize(debug: true); | ||
| 122 | +// if (Platform.isAndroid) { | ||
| 123 | +// await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true); | ||
| 251 | 124 | ||
| 252 | - Directory directory = new Directory(savePath); | ||
| 253 | - if (directory.existsSync()) { | ||
| 254 | - //删除历史apk | ||
| 255 | - final List<FileSystemEntity> files = directory.listSync(); | ||
| 256 | - for (FileSystemEntity file in files) { | ||
| 257 | - file.deleteSync(); | ||
| 258 | - } | ||
| 259 | - } | ||
| 260 | - DioUtil().download(url.toString(), savePath, | ||
| 261 | - onProgress: (received, total) { | ||
| 262 | - // if (_progress != 100) { | ||
| 263 | - // int progress = ((received / total) * 100).round(); | ||
| 264 | - // _progress = progress; | ||
| 265 | - // _setState(() {}); | ||
| 266 | - // } | ||
| 267 | - if (received == total) { | ||
| 268 | - print('object'); | ||
| 269 | - Utils.showToast('文件已保存在${savePath}'); | ||
| 270 | - // openFile(savePath); | ||
| 271 | - //下载完成 | ||
| 272 | - // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 273 | - } | ||
| 274 | - }); | ||
| 275 | - // }, | ||
| 276 | - // DioUtil().download(url.toString(), | ||
| 277 | - // (await getExternalStorageDirectory()).path, | ||
| 278 | - // onProgress: (received, total) { | ||
| 279 | - // // if (_progress != 100) { | ||
| 280 | - // // int progress = ((received / total) * 100).round(); | ||
| 281 | - // // _progress = progress; | ||
| 282 | - // // _setState(() {}); | ||
| 283 | - // // } | ||
| 284 | - // if (received == total) { | ||
| 285 | - // //下载完成 | ||
| 286 | - // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 287 | - // } | ||
| 288 | - // }); | ||
| 289 | - }, | ||
| 290 | - )) | ||
| 291 | - ], | ||
| 292 | - ) | ||
| 293 | - // Builder(builder: (BuildContext context) { | ||
| 294 | - // return WebView( | ||
| 295 | - // initialUrl: "http://colorcun.com/privacy1.html", | ||
| 296 | - // javascriptMode: JavascriptMode.unrestricted, | ||
| 297 | - // onWebViewCreated: (WebViewController webViewController) { | ||
| 298 | - // _controller.complete(webViewController); | ||
| 299 | - // }, | ||
| 300 | - // // TODO(iskakaushik): Remove this when collection literals makes it to stable. | ||
| 301 | - // // ignore: prefer_collection_literals | ||
| 302 | - // javascriptChannels: <JavascriptChannel>[ | ||
| 303 | - // _toasterJavascriptChannel(context), | ||
| 304 | - // ].toSet(), | ||
| 305 | - // navigationDelegate: (NavigationRequest request) { | ||
| 306 | - // if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 307 | - // print('blocking navigation to $request}'); | ||
| 308 | - // return NavigationDecision.prevent; | ||
| 309 | - // } | ||
| 310 | - // print('allowing navigation to $request'); | ||
| 311 | - // return NavigationDecision.navigate; | ||
| 312 | - // }, | ||
| 313 | - // onPageStarted: (String url) { | ||
| 314 | - // print('Page started loading: $url'); | ||
| 315 | - // }, | ||
| 316 | - // onPageFinished: (String url) async { | ||
| 317 | - // print('Page finished loading: $url'); | ||
| 318 | - // // showDownloadProgress(context); | ||
| 319 | - // final dir = await getExternalStorageDirectory(); | ||
| 320 | - // String savePath = dir.path + "/one_key"; | ||
| 321 | - // DioUtil().download(url, savePath, | ||
| 322 | - // onProgress: (received, total) { | ||
| 323 | - // // if (_progress != 100) { | ||
| 324 | - // // int progress = ((received / total) * 100).round(); | ||
| 325 | - // // _progress = progress; | ||
| 326 | - // // _setState(() {}); | ||
| 327 | - // // } | ||
| 328 | - // if (received == total) { | ||
| 329 | - // print('object'); | ||
| 330 | - // //下载完成 | ||
| 331 | - // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 332 | - // } | ||
| 333 | - // }); | ||
| 334 | - // }, | ||
| 335 | - // gestureNavigationEnabled: true, | ||
| 336 | - // ); | ||
| 337 | - // }), | ||
| 338 | - ); | ||
| 339 | - } | 125 | +// var swAvailable = await AndroidWebViewFeature.isFeatureSupported( |
| 126 | +// AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE); | ||
| 127 | +// var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported( | ||
| 128 | +// AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST); | ||
| 340 | 129 | ||
| 341 | - // JavascriptChannel _toasterJavascriptChannel(BuildContext context) { | ||
| 342 | - // return JavascriptChannel( | ||
| 343 | - // name: 'Toaster', | ||
| 344 | - // onMessageReceived: (JavascriptMessage message) { | ||
| 345 | - // Scaffold.of(context).showSnackBar( | ||
| 346 | - // SnackBar(content: Text(message.message)), | ||
| 347 | - // ); | ||
| 348 | - // }); | ||
| 349 | - // } | ||
| 350 | -} | 130 | +// if (swAvailable && swInterceptAvailable) { |
| 131 | +// AndroidServiceWorkerController serviceWorkerController = | ||
| 132 | +// AndroidServiceWorkerController.instance(); | ||
| 351 | 133 | ||
| 352 | -// class WebPage extends StatelessWidget { | ||
| 353 | -// final String title; | ||
| 354 | -// final String url; | ||
| 355 | -// final bool need; | 134 | +// serviceWorkerController.serviceWorkerClient = |
| 135 | +// AndroidServiceWorkerClient( | ||
| 136 | +// shouldInterceptRequest: (request) async { | ||
| 137 | +// print(request); | ||
| 138 | +// return null; | ||
| 139 | +// }, | ||
| 140 | +// ); | ||
| 141 | +// } | ||
| 142 | +// } | ||
| 143 | +// // await FlutterDownloader.initialize( | ||
| 144 | +// // debug: true // optional: set false to disable printing logs to console | ||
| 145 | +// // ); | ||
| 146 | +// // await Permission.storage.request(); | ||
| 147 | +// } | ||
| 356 | 148 | ||
| 357 | -// const WebPage({Key key, this.title, this.url, this.need = false}) | ||
| 358 | -// : super(key: key); | ||
| 359 | // @override | 149 | // @override |
| 360 | // Widget build(BuildContext context) { | 150 | // Widget build(BuildContext context) { |
| 361 | -// final Completer<WebViewController> _controller = | ||
| 362 | -// Completer<WebViewController>(); | ||
| 363 | // return Scaffold( | 151 | // return Scaffold( |
| 364 | -// appBar: SystemAppBar(title, onTap: () { | ||
| 365 | -// if (need) { | ||
| 366 | -// Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 367 | -// } | ||
| 368 | -// Navigator.of(context).pop(); | ||
| 369 | -// }), | ||
| 370 | -// body: WillPopScope( | ||
| 371 | -// onWillPop: () async { | ||
| 372 | -// if (need) { | ||
| 373 | -// Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 374 | -// } | ||
| 375 | -// return true; | ||
| 376 | -// }, | ||
| 377 | -// child: WebView( | ||
| 378 | -// initialUrl: "http://colorcun.com/privacy1.html", | ||
| 379 | -// javascriptMode: JavascriptMode.unrestricted, | ||
| 380 | -// onWebViewCreated: (WebViewController webViewController) { | ||
| 381 | -// // Loading.showLoading(context); | ||
| 382 | -// _controller.complete(webViewController); | ||
| 383 | -// }, | ||
| 384 | -// javascriptChannels: <JavascriptChannel>[ | ||
| 385 | -// _toasterJavascriptChannel(context), | ||
| 386 | -// ].toSet(), | ||
| 387 | -// navigationDelegate: (NavigationRequest request) { | ||
| 388 | -// if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 389 | -// return NavigationDecision.prevent; | ||
| 390 | -// } | ||
| 391 | -// return NavigationDecision.navigate; | ||
| 392 | -// }, | ||
| 393 | -// onPageStarted: (String url) {}, | ||
| 394 | -// onPageFinished: (String url) { | ||
| 395 | -// // Loading.hideLoading(context); | ||
| 396 | -// }, | ||
| 397 | -// gestureNavigationEnabled: true, | ||
| 398 | -// )), | ||
| 399 | -// ); | ||
| 400 | -// } | 152 | +// // We're using a Builder here so we have a context that is below the Scaffold |
| 153 | +// // to allow calling Scaffold.of(context) so we can show a snackbar. | ||
| 154 | +// appBar: SystemAppBar( | ||
| 155 | +// widget.title, | ||
| 156 | +// ), | ||
| 157 | +// body: Column( | ||
| 158 | +// children: [ | ||
| 159 | +// Expanded( | ||
| 160 | +// child: InAppWebView( | ||
| 161 | +// key: webViewKey, | ||
| 162 | +// // contextMenu: contextMenu, | ||
| 163 | +// initialUrlRequest: URLRequest( | ||
| 164 | +// url: Uri.parse("http://colorcun.com/privacy1.html")), | ||
| 165 | +// // url: WebUri("http://colorcun.com/privacy2.html")), | ||
| 166 | +// //华为下载功能闪退,去掉下载功能*********http://colorcun.com/privacy2.html | ||
| 167 | +// // initialFile: "assets/index.html", | ||
| 168 | +// initialUserScripts: UnmodifiableListView<UserScript>([]), | ||
| 169 | +// initialOptions: options, | ||
| 170 | +// pullToRefreshController: pullToRefreshController, | ||
| 171 | +// onWebViewCreated: (controller) { | ||
| 172 | +// webViewController = controller; | ||
| 173 | +// }, | ||
| 174 | +// onLoadStart: (controller, url) { | ||
| 175 | +// setState(() { | ||
| 176 | +// this.url = url.toString(); | ||
| 177 | +// urlController.text = this.url; | ||
| 178 | +// }); | ||
| 179 | +// }, | ||
| 180 | +// androidOnPermissionRequest: | ||
| 181 | +// (controller, origin, resources) async { | ||
| 182 | +// return PermissionRequestResponse( | ||
| 183 | +// resources: resources, | ||
| 184 | +// action: PermissionRequestResponseAction.GRANT); | ||
| 185 | +// }, | ||
| 186 | +// shouldOverrideUrlLoading: (controller, navigationAction) async { | ||
| 187 | +// var uri = navigationAction.request.url!; | ||
| 401 | 188 | ||
| 402 | -// JavascriptChannel _toasterJavascriptChannel(BuildContext context) { | ||
| 403 | -// return JavascriptChannel( | ||
| 404 | -// name: 'Toaster', | ||
| 405 | -// onMessageReceived: (JavascriptMessage message) { | ||
| 406 | -// Scaffold.of(context).showSnackBar( | ||
| 407 | -// SnackBar(content: Text(message.message)), | ||
| 408 | -// ); | ||
| 409 | -// }); | 189 | +// if (![ |
| 190 | +// "http", | ||
| 191 | +// "https", | ||
| 192 | +// "file", | ||
| 193 | +// "chrome", | ||
| 194 | +// "data", | ||
| 195 | +// "javascript", | ||
| 196 | +// "about" | ||
| 197 | +// ].contains(uri.scheme)) { | ||
| 198 | +// if (await canLaunch(url)) { | ||
| 199 | +// // Launch the App | ||
| 200 | +// await launch( | ||
| 201 | +// url, | ||
| 202 | +// ); | ||
| 203 | +// // and cancel the request | ||
| 204 | +// return NavigationActionPolicy.CANCEL; | ||
| 205 | +// } | ||
| 206 | +// } | ||
| 207 | + | ||
| 208 | +// return NavigationActionPolicy.ALLOW; | ||
| 209 | +// }, | ||
| 210 | +// onLoadStop: (controller, url) async { | ||
| 211 | +// pullToRefreshController!.endRefreshing(); | ||
| 212 | +// setState(() { | ||
| 213 | +// this.url = url.toString(); | ||
| 214 | +// urlController.text = this.url; | ||
| 215 | +// }); | ||
| 216 | +// }, | ||
| 217 | +// onLoadError: (controller, url, code, message) { | ||
| 218 | +// pullToRefreshController!.endRefreshing(); | ||
| 219 | +// }, | ||
| 220 | +// onProgressChanged: (controller, progress) { | ||
| 221 | +// if (progress == 100) { | ||
| 222 | +// pullToRefreshController!.endRefreshing(); | ||
| 223 | +// } | ||
| 224 | +// setState(() { | ||
| 225 | +// this.progress = progress / 100; | ||
| 226 | +// urlController.text = this.url; | ||
| 227 | +// }); | ||
| 228 | +// }, | ||
| 229 | +// onUpdateVisitedHistory: (controller, url, androidIsReload) { | ||
| 230 | +// setState(() { | ||
| 231 | +// this.url = url.toString(); | ||
| 232 | +// urlController.text = this.url; | ||
| 233 | +// }); | ||
| 234 | +// }, | ||
| 235 | +// onConsoleMessage: (controller, consoleMessage) { | ||
| 236 | +// print(consoleMessage); | ||
| 237 | +// }, | ||
| 238 | +// onDownloadStart: (controller, url) async { | ||
| 239 | +// print("onDownloadStart $url"); | ||
| 240 | +// Utils.showToast('开始下载...'); | ||
| 241 | +// // final taskId = await FlutterDownloader.enqueue( | ||
| 242 | +// // url: url.toString(), | ||
| 243 | +// // savedDir: (await getExternalStorageDirectory()).path, | ||
| 244 | +// // showNotification: | ||
| 245 | +// // true, // show download progress in status bar (for Android) | ||
| 246 | +// // openFileFromNotification: | ||
| 247 | +// // true, // click on notification to open downloaded file (for Android) | ||
| 248 | +// // ); | ||
| 249 | +// final dir = (await getExternalStorageDirectory())!; | ||
| 250 | +// String savePath = dir.path + "/one_key"; | ||
| 251 | + | ||
| 252 | +// Directory directory = new Directory(savePath); | ||
| 253 | +// if (directory.existsSync()) { | ||
| 254 | +// //删除历史apk | ||
| 255 | +// final List<FileSystemEntity> files = directory.listSync(); | ||
| 256 | +// for (FileSystemEntity file in files) { | ||
| 257 | +// file.deleteSync(); | ||
| 258 | +// } | ||
| 259 | +// } | ||
| 260 | +// DioUtil().download(url.toString(), savePath, | ||
| 261 | +// onProgress: (received, total) { | ||
| 262 | +// // if (_progress != 100) { | ||
| 263 | +// // int progress = ((received / total) * 100).round(); | ||
| 264 | +// // _progress = progress; | ||
| 265 | +// // _setState(() {}); | ||
| 266 | +// // } | ||
| 267 | +// if (received == total) { | ||
| 268 | +// print('object'); | ||
| 269 | +// Utils.showToast('文件已保存在${savePath}'); | ||
| 270 | +// // openFile(savePath); | ||
| 271 | +// //下载完成 | ||
| 272 | +// // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 273 | +// } | ||
| 274 | +// }); | ||
| 275 | +// // }, | ||
| 276 | +// // DioUtil().download(url.toString(), | ||
| 277 | +// // (await getExternalStorageDirectory()).path, | ||
| 278 | +// // onProgress: (received, total) { | ||
| 279 | +// // // if (_progress != 100) { | ||
| 280 | +// // // int progress = ((received / total) * 100).round(); | ||
| 281 | +// // // _progress = progress; | ||
| 282 | +// // // _setState(() {}); | ||
| 283 | +// // // } | ||
| 284 | +// // if (received == total) { | ||
| 285 | +// // //下载完成 | ||
| 286 | +// // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 287 | +// // } | ||
| 288 | +// // }); | ||
| 289 | +// }, | ||
| 290 | +// )) | ||
| 291 | +// ], | ||
| 292 | +// ) | ||
| 293 | +// // Builder(builder: (BuildContext context) { | ||
| 294 | +// // return WebView( | ||
| 295 | +// // initialUrl: "http://colorcun.com/privacy1.html", | ||
| 296 | +// // javascriptMode: JavascriptMode.unrestricted, | ||
| 297 | +// // onWebViewCreated: (WebViewController webViewController) { | ||
| 298 | +// // _controller.complete(webViewController); | ||
| 299 | +// // }, | ||
| 300 | +// // // TODO(iskakaushik): Remove this when collection literals makes it to stable. | ||
| 301 | +// // // ignore: prefer_collection_literals | ||
| 302 | +// // javascriptChannels: <JavascriptChannel>[ | ||
| 303 | +// // _toasterJavascriptChannel(context), | ||
| 304 | +// // ].toSet(), | ||
| 305 | +// // navigationDelegate: (NavigationRequest request) { | ||
| 306 | +// // if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 307 | +// // print('blocking navigation to $request}'); | ||
| 308 | +// // return NavigationDecision.prevent; | ||
| 309 | +// // } | ||
| 310 | +// // print('allowing navigation to $request'); | ||
| 311 | +// // return NavigationDecision.navigate; | ||
| 312 | +// // }, | ||
| 313 | +// // onPageStarted: (String url) { | ||
| 314 | +// // print('Page started loading: $url'); | ||
| 315 | +// // }, | ||
| 316 | +// // onPageFinished: (String url) async { | ||
| 317 | +// // print('Page finished loading: $url'); | ||
| 318 | +// // // showDownloadProgress(context); | ||
| 319 | +// // final dir = await getExternalStorageDirectory(); | ||
| 320 | +// // String savePath = dir.path + "/one_key"; | ||
| 321 | +// // DioUtil().download(url, savePath, | ||
| 322 | +// // onProgress: (received, total) { | ||
| 323 | +// // // if (_progress != 100) { | ||
| 324 | +// // // int progress = ((received / total) * 100).round(); | ||
| 325 | +// // // _progress = progress; | ||
| 326 | +// // // _setState(() {}); | ||
| 327 | +// // // } | ||
| 328 | +// // if (received == total) { | ||
| 329 | +// // print('object'); | ||
| 330 | +// // //下载完成 | ||
| 331 | +// // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 332 | +// // } | ||
| 333 | +// // }); | ||
| 334 | +// // }, | ||
| 335 | +// // gestureNavigationEnabled: true, | ||
| 336 | +// // ); | ||
| 337 | +// // }), | ||
| 338 | +// ); | ||
| 410 | // } | 339 | // } |
| 340 | + | ||
| 341 | +// // JavascriptChannel _toasterJavascriptChannel(BuildContext context) { | ||
| 342 | +// // return JavascriptChannel( | ||
| 343 | +// // name: 'Toaster', | ||
| 344 | +// // onMessageReceived: (JavascriptMessage message) { | ||
| 345 | +// // Scaffold.of(context).showSnackBar( | ||
| 346 | +// // SnackBar(content: Text(message.message)), | ||
| 347 | +// // ); | ||
| 348 | +// // }); | ||
| 349 | +// // } | ||
| 411 | // } | 350 | // } |
| 351 | + | ||
| 352 | +// // class WebPage extends StatelessWidget { | ||
| 353 | +// // final String title; | ||
| 354 | +// // final String url; | ||
| 355 | +// // final bool need; | ||
| 356 | + | ||
| 357 | +// // const WebPage({Key key, this.title, this.url, this.need = false}) | ||
| 358 | +// // : super(key: key); | ||
| 359 | +// // @override | ||
| 360 | +// // Widget build(BuildContext context) { | ||
| 361 | +// // final Completer<WebViewController> _controller = | ||
| 362 | +// // Completer<WebViewController>(); | ||
| 363 | +// // return Scaffold( | ||
| 364 | +// // appBar: SystemAppBar(title, onTap: () { | ||
| 365 | +// // if (need) { | ||
| 366 | +// // Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 367 | +// // } | ||
| 368 | +// // Navigator.of(context).pop(); | ||
| 369 | +// // }), | ||
| 370 | +// // body: WillPopScope( | ||
| 371 | +// // onWillPop: () async { | ||
| 372 | +// // if (need) { | ||
| 373 | +// // Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 374 | +// // } | ||
| 375 | +// // return true; | ||
| 376 | +// // }, | ||
| 377 | +// // child: WebView( | ||
| 378 | +// // initialUrl: "http://colorcun.com/privacy1.html", | ||
| 379 | +// // javascriptMode: JavascriptMode.unrestricted, | ||
| 380 | +// // onWebViewCreated: (WebViewController webViewController) { | ||
| 381 | +// // // Loading.showLoading(context); | ||
| 382 | +// // _controller.complete(webViewController); | ||
| 383 | +// // }, | ||
| 384 | +// // javascriptChannels: <JavascriptChannel>[ | ||
| 385 | +// // _toasterJavascriptChannel(context), | ||
| 386 | +// // ].toSet(), | ||
| 387 | +// // navigationDelegate: (NavigationRequest request) { | ||
| 388 | +// // if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 389 | +// // return NavigationDecision.prevent; | ||
| 390 | +// // } | ||
| 391 | +// // return NavigationDecision.navigate; | ||
| 392 | +// // }, | ||
| 393 | +// // onPageStarted: (String url) {}, | ||
| 394 | +// // onPageFinished: (String url) { | ||
| 395 | +// // // Loading.hideLoading(context); | ||
| 396 | +// // }, | ||
| 397 | +// // gestureNavigationEnabled: true, | ||
| 398 | +// // )), | ||
| 399 | +// // ); | ||
| 400 | +// // } | ||
| 401 | + | ||
| 402 | +// // JavascriptChannel _toasterJavascriptChannel(BuildContext context) { | ||
| 403 | +// // return JavascriptChannel( | ||
| 404 | +// // name: 'Toaster', | ||
| 405 | +// // onMessageReceived: (JavascriptMessage message) { | ||
| 406 | +// // Scaffold.of(context).showSnackBar( | ||
| 407 | +// // SnackBar(content: Text(message.message)), | ||
| 408 | +// // ); | ||
| 409 | +// // }); | ||
| 410 | +// // } | ||
| 411 | +// // } |
| 1 | 1 | ||
| 2 | -// // import 'package:device_info/device_info.dart'; | ||
| 3 | -// // import 'package:device_info_plus/device_info_plus.dart'; | ||
| 4 | -// import 'package:flutter/material.dart'; | ||
| 5 | -// import 'package:flutter_inappwebview/flutter_inappwebview.dart'; | ||
| 6 | -// import 'package:one_key/net/dio_util.dart'; | ||
| 7 | -// import 'package:one_key/res/colors.dart'; | ||
| 8 | -// import 'package:one_key/utils/utils.dart'; | ||
| 9 | -// import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 10 | -// import 'package:path_provider/path_provider.dart'; | ||
| 11 | -// // import 'package:permission_handler/permission_handler.dart'; | ||
| 12 | -// // import 'package:webview_flutter/webview_flutter.dart'; | 2 | +// import 'package:device_info/device_info.dart'; |
| 3 | +// import 'package:device_info_plus/device_info_plus.dart'; | ||
| 4 | +import 'package:flutter/material.dart'; | ||
| 5 | +import 'package:flutter_inappwebview/flutter_inappwebview.dart'; | ||
| 6 | +import 'package:one_key/net/dio_util.dart'; | ||
| 7 | +import 'package:one_key/res/colors.dart'; | ||
| 8 | +import 'package:one_key/utils/utils.dart'; | ||
| 9 | +import 'package:one_key/widgets/system_app_bar.dart'; | ||
| 10 | +import 'package:path_provider/path_provider.dart'; | ||
| 11 | +// import 'package:permission_handler/permission_handler.dart'; | ||
| 12 | +// import 'package:webview_flutter/webview_flutter.dart'; | ||
| 13 | 13 | ||
| 14 | -// import 'dart:io'; | 14 | +import 'dart:io'; |
| 15 | 15 | ||
| 16 | -// // import 'package:webview_flutter/webview_flutter.dart'; | 16 | +// import 'package:webview_flutter/webview_flutter.dart'; |
| 17 | 17 | ||
| 18 | -// // import 'package:flutter_inappwebview/flutter_inappwebview.dart'; | ||
| 19 | -// import 'package:url_launcher/url_launcher.dart'; | ||
| 20 | -// import 'dart:collection'; | ||
| 21 | -// // import 'package:open_file/open_file.dart'; | ||
| 22 | -// // import 'package:flutter_downloader/flutter_downloader.dart'; | 18 | +// import 'package:flutter_inappwebview/flutter_inappwebview.dart'; |
| 19 | +import 'package:url_launcher/url_launcher.dart'; | ||
| 20 | +import 'dart:collection'; | ||
| 21 | +// import 'package:open_file/open_file.dart'; | ||
| 22 | +// import 'package:flutter_downloader/flutter_downloader.dart'; | ||
| 23 | 23 | ||
| 24 | -// /** | ||
| 25 | -// * 我的-----帮助与反馈页面 ----- 目前已经功能已经屏蔽 | ||
| 26 | -// */ | 24 | +/** |
| 25 | + * 我的-----帮助与反馈页面 ----- 目前已经功能已经屏蔽 | ||
| 26 | + */ | ||
| 27 | 27 | ||
| 28 | -// class WebPage extends StatefulWidget { | ||
| 29 | -// final String? title; | ||
| 30 | -// final String? url; | ||
| 31 | -// final bool need; | 28 | +class WebPage extends StatefulWidget { |
| 29 | + final String? title; | ||
| 30 | + final String? url; | ||
| 31 | + final bool need; | ||
| 32 | 32 | ||
| 33 | -// const WebPage({Key? key, this.title, this.url, this.need = false}) | ||
| 34 | -// : super(key: key); | ||
| 35 | -// @override | ||
| 36 | -// _WebPageState createState() => _WebPageState(); | ||
| 37 | -// } | 33 | + const WebPage({Key? key, this.title, this.url, this.need = false}) |
| 34 | + : super(key: key); | ||
| 35 | + @override | ||
| 36 | + _WebPageState createState() => _WebPageState(); | ||
| 37 | +} | ||
| 38 | 38 | ||
| 39 | -// class _WebPageState extends State<WebPage> { | ||
| 40 | -// final GlobalKey webViewKey = GlobalKey(); | 39 | +class _WebPageState extends State<WebPage> { |
| 40 | + final GlobalKey webViewKey = GlobalKey(); | ||
| 41 | 41 | ||
| 42 | -// InAppWebViewController? webViewController; | ||
| 43 | -// InAppWebViewGroupOptions options = InAppWebViewGroupOptions( | ||
| 44 | -// crossPlatform: InAppWebViewOptions( | ||
| 45 | -// useShouldOverrideUrlLoading: true, | ||
| 46 | -// useOnDownloadStart: true, | ||
| 47 | -// mediaPlaybackRequiresUserGesture: false, | ||
| 48 | -// ), | ||
| 49 | -// android: AndroidInAppWebViewOptions( | ||
| 50 | -// useHybridComposition: true, | ||
| 51 | -// ), | ||
| 52 | -// ios: IOSInAppWebViewOptions( | ||
| 53 | -// allowsInlineMediaPlayback: true, | ||
| 54 | -// )); | 42 | + InAppWebViewController? webViewController; |
| 43 | + InAppWebViewGroupOptions options = InAppWebViewGroupOptions( | ||
| 44 | + crossPlatform: InAppWebViewOptions( | ||
| 45 | + useShouldOverrideUrlLoading: true, | ||
| 46 | + useOnDownloadStart: true, | ||
| 47 | + mediaPlaybackRequiresUserGesture: false, | ||
| 48 | + ), | ||
| 49 | + android: AndroidInAppWebViewOptions( | ||
| 50 | + useHybridComposition: true, | ||
| 51 | + ), | ||
| 52 | + ios: IOSInAppWebViewOptions( | ||
| 53 | + allowsInlineMediaPlayback: true, | ||
| 54 | + )); | ||
| 55 | 55 | ||
| 56 | -// PullToRefreshController? pullToRefreshController; | ||
| 57 | -// ContextMenu? contextMenu; | ||
| 58 | -// String url = ""; | ||
| 59 | -// double progress = 0; | ||
| 60 | -// final urlController = TextEditingController(); | ||
| 61 | -// // Future<void> openFile(filePath) async { | ||
| 62 | -// // final _result = await OpenFile.open(filePath); | ||
| 63 | -// // print(_result.message); | 56 | + PullToRefreshController? pullToRefreshController; |
| 57 | + ContextMenu? contextMenu; | ||
| 58 | + String url = ""; | ||
| 59 | + double progress = 0; | ||
| 60 | + final urlController = TextEditingController(); | ||
| 61 | + // Future<void> openFile(filePath) async { | ||
| 62 | + // final _result = await OpenFile.open(filePath); | ||
| 63 | + // print(_result.message); | ||
| 64 | 64 | ||
| 65 | -// // // setState(() { | ||
| 66 | -// // // _openResult = "type=${_result.type} message=${_result.message}"; | ||
| 67 | -// // // }); | ||
| 68 | -// // } | 65 | + // // setState(() { |
| 66 | + // // _openResult = "type=${_result.type} message=${_result.message}"; | ||
| 67 | + // // }); | ||
| 68 | + // } | ||
| 69 | 69 | ||
| 70 | -// @override | ||
| 71 | -// void initState() { | ||
| 72 | -// super.initState(); | 70 | + @override |
| 71 | + void initState() { | ||
| 72 | + super.initState(); | ||
| 73 | 73 | ||
| 74 | -// // Enable hybrid composition. | ||
| 75 | -// _init(); | ||
| 76 | -// } | 74 | + // Enable hybrid composition. |
| 75 | + _init(); | ||
| 76 | + } | ||
| 77 | 77 | ||
| 78 | -// @override | ||
| 79 | -// void dispose() { | ||
| 80 | -// if (widget.need) { | ||
| 81 | -// Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 82 | -// } | 78 | + @override |
| 79 | + void dispose() { | ||
| 80 | + if (widget.need) { | ||
| 81 | + Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 82 | + } | ||
| 83 | 83 | ||
| 84 | -// super.dispose(); | ||
| 85 | -// } | 84 | + super.dispose(); |
| 85 | + } | ||
| 86 | 86 | ||
| 87 | -// // Future<bool> _checkPermission() async { | ||
| 88 | -// // DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); | ||
| 89 | -// // AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; | ||
| 90 | -// // if (Platform.isAndroid && androidInfo.version.sdkInt <= 28) { | ||
| 91 | -// // final status = await Permission.storage.status; | ||
| 92 | -// // if (status != PermissionStatus.granted) { | ||
| 93 | -// // final result = await Permission.storage.request(); | ||
| 94 | -// // if (result == PermissionStatus.granted) { | ||
| 95 | -// // return true; | ||
| 96 | -// // } | ||
| 97 | -// // } else { | ||
| 98 | -// // return true; | ||
| 99 | -// // } | ||
| 100 | -// // } else { | ||
| 101 | -// // return true; | ||
| 102 | -// // } | ||
| 103 | -// // return false; | ||
| 104 | -// // } | 87 | + // Future<bool> _checkPermission() async { |
| 88 | + // DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); | ||
| 89 | + // AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; | ||
| 90 | + // if (Platform.isAndroid && androidInfo.version.sdkInt <= 28) { | ||
| 91 | + // final status = await Permission.storage.status; | ||
| 92 | + // if (status != PermissionStatus.granted) { | ||
| 93 | + // final result = await Permission.storage.request(); | ||
| 94 | + // if (result == PermissionStatus.granted) { | ||
| 95 | + // return true; | ||
| 96 | + // } | ||
| 97 | + // } else { | ||
| 98 | + // return true; | ||
| 99 | + // } | ||
| 100 | + // } else { | ||
| 101 | + // return true; | ||
| 102 | + // } | ||
| 103 | + // return false; | ||
| 104 | + // } | ||
| 105 | 105 | ||
| 106 | -// // Future<bool> checkPermissionStorage() async { | ||
| 107 | -// // var status = await Permission.storage.status; | ||
| 108 | -// // if (!status.isGranted) { | ||
| 109 | -// // status = await Permission.storage.request(); | ||
| 110 | -// // if (status.isGranted) { | ||
| 111 | -// // return true; | ||
| 112 | -// // } | ||
| 113 | -// // } else { | ||
| 114 | -// // return true; | ||
| 115 | -// // } | ||
| 116 | -// // return false; | ||
| 117 | -// // } | 106 | + // Future<bool> checkPermissionStorage() async { |
| 107 | + // var status = await Permission.storage.status; | ||
| 108 | + // if (!status.isGranted) { | ||
| 109 | + // status = await Permission.storage.request(); | ||
| 110 | + // if (status.isGranted) { | ||
| 111 | + // return true; | ||
| 112 | + // } | ||
| 113 | + // } else { | ||
| 114 | + // return true; | ||
| 115 | + // } | ||
| 116 | + // return false; | ||
| 117 | + // } | ||
| 118 | 118 | ||
| 119 | -// _init() async { | ||
| 120 | -// // WidgetsFlutterBinding.ensureInitialized(); | ||
| 121 | -// // await FlutterDownloader.initialize(debug: true); | ||
| 122 | -// if (Platform.isAndroid) { | ||
| 123 | -// await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true); | 119 | + _init() async { |
| 120 | + // WidgetsFlutterBinding.ensureInitialized(); | ||
| 121 | + // await FlutterDownloader.initialize(debug: true); | ||
| 122 | + if (Platform.isAndroid) { | ||
| 123 | + await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true); | ||
| 124 | 124 | ||
| 125 | -// var swAvailable = await AndroidWebViewFeature.isFeatureSupported( | ||
| 126 | -// AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE); | ||
| 127 | -// var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported( | ||
| 128 | -// AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST); | 125 | + var swAvailable = await AndroidWebViewFeature.isFeatureSupported( |
| 126 | + AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE); | ||
| 127 | + var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported( | ||
| 128 | + AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST); | ||
| 129 | 129 | ||
| 130 | -// if (swAvailable && swInterceptAvailable) { | ||
| 131 | -// AndroidServiceWorkerController serviceWorkerController = | ||
| 132 | -// AndroidServiceWorkerController.instance(); | 130 | + if (swAvailable && swInterceptAvailable) { |
| 131 | + AndroidServiceWorkerController serviceWorkerController = | ||
| 132 | + AndroidServiceWorkerController.instance(); | ||
| 133 | 133 | ||
| 134 | -// serviceWorkerController.serviceWorkerClient = | ||
| 135 | -// AndroidServiceWorkerClient( | ||
| 136 | -// shouldInterceptRequest: (request) async { | ||
| 137 | -// print(request); | ||
| 138 | -// return null; | ||
| 139 | -// }, | ||
| 140 | -// ); | ||
| 141 | -// } | ||
| 142 | -// } | ||
| 143 | -// // await FlutterDownloader.initialize( | ||
| 144 | -// // debug: true // optional: set false to disable printing logs to console | ||
| 145 | -// // ); | ||
| 146 | -// // await Permission.storage.request(); | ||
| 147 | -// } | 134 | + serviceWorkerController.serviceWorkerClient = |
| 135 | + AndroidServiceWorkerClient( | ||
| 136 | + shouldInterceptRequest: (request) async { | ||
| 137 | + print(request); | ||
| 138 | + return null; | ||
| 139 | + }, | ||
| 140 | + ); | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + // await FlutterDownloader.initialize( | ||
| 144 | + // debug: true // optional: set false to disable printing logs to console | ||
| 145 | + // ); | ||
| 146 | + // await Permission.storage.request(); | ||
| 147 | + } | ||
| 148 | 148 | ||
| 149 | -// @override | ||
| 150 | -// Widget build(BuildContext context) { | ||
| 151 | -// return Scaffold( | ||
| 152 | -// // We're using a Builder here so we have a context that is below the Scaffold | ||
| 153 | -// // to allow calling Scaffold.of(context) so we can show a snackbar. | ||
| 154 | -// appBar: SystemAppBar( | ||
| 155 | -// widget.title, | ||
| 156 | -// ), | ||
| 157 | -// body: Column( | ||
| 158 | -// children: [ | ||
| 159 | -// Expanded( | ||
| 160 | -// child: InAppWebView( | ||
| 161 | -// key: webViewKey, | ||
| 162 | -// // contextMenu: contextMenu, | ||
| 163 | -// initialUrlRequest: URLRequest( | ||
| 164 | -// // url: Uri.parse("http://colorcun.com/privacy1.html")), | ||
| 165 | -// url: WebUri("http://colorcun.com/privacy2.html")), | ||
| 166 | -// //华为下载功能闪退,去掉下载功能*********http://colorcun.com/privacy2.html | ||
| 167 | -// // initialFile: "assets/index.html", | ||
| 168 | -// initialUserScripts: UnmodifiableListView<UserScript>([]), | ||
| 169 | -// initialOptions: options, | ||
| 170 | -// pullToRefreshController: pullToRefreshController, | ||
| 171 | -// onWebViewCreated: (controller) { | ||
| 172 | -// webViewController = controller; | ||
| 173 | -// }, | ||
| 174 | -// onLoadStart: (controller, url) { | ||
| 175 | -// setState(() { | ||
| 176 | -// this.url = url.toString(); | ||
| 177 | -// urlController.text = this.url; | ||
| 178 | -// }); | ||
| 179 | -// }, | ||
| 180 | -// androidOnPermissionRequest: | ||
| 181 | -// (controller, origin, resources) async { | ||
| 182 | -// return PermissionRequestResponse( | ||
| 183 | -// resources: resources, | ||
| 184 | -// action: PermissionRequestResponseAction.GRANT); | ||
| 185 | -// }, | ||
| 186 | -// shouldOverrideUrlLoading: (controller, navigationAction) async { | ||
| 187 | -// var uri = navigationAction.request.url!; | 149 | + @override |
| 150 | + Widget build(BuildContext context) { | ||
| 151 | + return Scaffold( | ||
| 152 | + // We're using a Builder here so we have a context that is below the Scaffold | ||
| 153 | + // to allow calling Scaffold.of(context) so we can show a snackbar. | ||
| 154 | + appBar: SystemAppBar( | ||
| 155 | + widget.title, | ||
| 156 | + ), | ||
| 157 | + body: Column( | ||
| 158 | + children: [ | ||
| 159 | + Expanded( | ||
| 160 | + child: InAppWebView( | ||
| 161 | + key: webViewKey, | ||
| 162 | + // contextMenu: contextMenu, | ||
| 163 | + initialUrlRequest: URLRequest( | ||
| 164 | + // url: Uri.parse("http://colorcun.com/privacy1.html")), | ||
| 165 | + url: WebUri("http://colorcun.com/privacy2.html") | ||
| 166 | + ), | ||
| 167 | + //华为下载功能闪退,去掉下载功能*********http://colorcun.com/privacy2.html | ||
| 168 | + // initialFile: "assets/index.html", | ||
| 169 | + initialUserScripts: UnmodifiableListView<UserScript>([]), | ||
| 170 | + initialOptions: options, | ||
| 171 | + pullToRefreshController: pullToRefreshController, | ||
| 172 | + onWebViewCreated: (controller) { | ||
| 173 | + webViewController = controller; | ||
| 174 | + }, | ||
| 175 | + onLoadStart: (controller, url) { | ||
| 176 | + setState(() { | ||
| 177 | + this.url = url.toString(); | ||
| 178 | + urlController.text = this.url; | ||
| 179 | + }); | ||
| 180 | + }, | ||
| 181 | + androidOnPermissionRequest: | ||
| 182 | + (controller, origin, resources) async { | ||
| 183 | + return PermissionRequestResponse( | ||
| 184 | + resources: resources, | ||
| 185 | + action: PermissionRequestResponseAction.GRANT); | ||
| 186 | + }, | ||
| 187 | + shouldOverrideUrlLoading: (controller, navigationAction) async { | ||
| 188 | + var uri = navigationAction.request.url!; | ||
| 188 | 189 | ||
| 189 | -// if (![ | ||
| 190 | -// "http", | ||
| 191 | -// "https", | ||
| 192 | -// "file", | ||
| 193 | -// "chrome", | ||
| 194 | -// "data", | ||
| 195 | -// "javascript", | ||
| 196 | -// "about" | ||
| 197 | -// ].contains(uri.scheme)) { | ||
| 198 | -// if (await canLaunch(url)) { | ||
| 199 | -// // Launch the App | ||
| 200 | -// await launch( | ||
| 201 | -// url, | ||
| 202 | -// ); | ||
| 203 | -// // and cancel the request | ||
| 204 | -// return NavigationActionPolicy.CANCEL; | ||
| 205 | -// } | ||
| 206 | -// } | 190 | + if (![ |
| 191 | + "http", | ||
| 192 | + "https", | ||
| 193 | + "file", | ||
| 194 | + "chrome", | ||
| 195 | + "data", | ||
| 196 | + "javascript", | ||
| 197 | + "about" | ||
| 198 | + ].contains(uri.scheme)) { | ||
| 199 | + if (await canLaunch(url)) { | ||
| 200 | + // Launch the App | ||
| 201 | + await launch( | ||
| 202 | + url, | ||
| 203 | + ); | ||
| 204 | + // and cancel the request | ||
| 205 | + return NavigationActionPolicy.CANCEL; | ||
| 206 | + } | ||
| 207 | + } | ||
| 207 | 208 | ||
| 208 | -// return NavigationActionPolicy.ALLOW; | ||
| 209 | -// }, | ||
| 210 | -// onLoadStop: (controller, url) async { | ||
| 211 | -// pullToRefreshController!.endRefreshing(); | ||
| 212 | -// setState(() { | ||
| 213 | -// this.url = url.toString(); | ||
| 214 | -// urlController.text = this.url; | ||
| 215 | -// }); | ||
| 216 | -// }, | ||
| 217 | -// onLoadError: (controller, url, code, message) { | ||
| 218 | -// pullToRefreshController!.endRefreshing(); | ||
| 219 | -// }, | ||
| 220 | -// onProgressChanged: (controller, progress) { | ||
| 221 | -// if (progress == 100) { | ||
| 222 | -// pullToRefreshController!.endRefreshing(); | ||
| 223 | -// } | ||
| 224 | -// setState(() { | ||
| 225 | -// this.progress = progress / 100; | ||
| 226 | -// urlController.text = this.url; | ||
| 227 | -// }); | ||
| 228 | -// }, | ||
| 229 | -// onUpdateVisitedHistory: (controller, url, androidIsReload) { | ||
| 230 | -// setState(() { | ||
| 231 | -// this.url = url.toString(); | ||
| 232 | -// urlController.text = this.url; | ||
| 233 | -// }); | ||
| 234 | -// }, | ||
| 235 | -// onConsoleMessage: (controller, consoleMessage) { | ||
| 236 | -// print(consoleMessage); | ||
| 237 | -// }, | ||
| 238 | -// onDownloadStart: (controller, url) async { | ||
| 239 | -// print("onDownloadStart $url"); | ||
| 240 | -// Utils.showToast('开始下载...'); | ||
| 241 | -// // final taskId = await FlutterDownloader.enqueue( | ||
| 242 | -// // url: url.toString(), | ||
| 243 | -// // savedDir: (await getExternalStorageDirectory()).path, | ||
| 244 | -// // showNotification: | ||
| 245 | -// // true, // show download progress in status bar (for Android) | ||
| 246 | -// // openFileFromNotification: | ||
| 247 | -// // true, // click on notification to open downloaded file (for Android) | ||
| 248 | -// // ); | ||
| 249 | -// final dir = (await getExternalStorageDirectory())!; | ||
| 250 | -// String savePath = dir.path + "/one_key"; | 209 | + return NavigationActionPolicy.ALLOW; |
| 210 | + }, | ||
| 211 | + onLoadStop: (controller, url) async { | ||
| 212 | + pullToRefreshController!.endRefreshing(); | ||
| 213 | + setState(() { | ||
| 214 | + this.url = url.toString(); | ||
| 215 | + urlController.text = this.url; | ||
| 216 | + }); | ||
| 217 | + }, | ||
| 218 | + onLoadError: (controller, url, code, message) { | ||
| 219 | + pullToRefreshController!.endRefreshing(); | ||
| 220 | + }, | ||
| 221 | + onProgressChanged: (controller, progress) { | ||
| 222 | + if (progress == 100) { | ||
| 223 | + pullToRefreshController!.endRefreshing(); | ||
| 224 | + } | ||
| 225 | + setState(() { | ||
| 226 | + this.progress = progress / 100; | ||
| 227 | + urlController.text = this.url; | ||
| 228 | + }); | ||
| 229 | + }, | ||
| 230 | + onUpdateVisitedHistory: (controller, url, androidIsReload) { | ||
| 231 | + setState(() { | ||
| 232 | + this.url = url.toString(); | ||
| 233 | + urlController.text = this.url; | ||
| 234 | + }); | ||
| 235 | + }, | ||
| 236 | + onConsoleMessage: (controller, consoleMessage) { | ||
| 237 | + print(consoleMessage); | ||
| 238 | + }, | ||
| 239 | + onDownloadStart: (controller, url) async { | ||
| 240 | + print("onDownloadStart $url"); | ||
| 241 | + Utils.showToast('开始下载...'); | ||
| 242 | + // final taskId = await FlutterDownloader.enqueue( | ||
| 243 | + // url: url.toString(), | ||
| 244 | + // savedDir: (await getExternalStorageDirectory()).path, | ||
| 245 | + // showNotification: | ||
| 246 | + // true, // show download progress in status bar (for Android) | ||
| 247 | + // openFileFromNotification: | ||
| 248 | + // true, // click on notification to open downloaded file (for Android) | ||
| 249 | + // ); | ||
| 250 | + final dir = (await getExternalStorageDirectory())!; | ||
| 251 | + String savePath = dir.path + "/one_key"; | ||
| 251 | 252 | ||
| 252 | -// Directory directory = new Directory(savePath); | ||
| 253 | -// if (directory.existsSync()) { | ||
| 254 | -// //删除历史apk | ||
| 255 | -// final List<FileSystemEntity> files = directory.listSync(); | ||
| 256 | -// for (FileSystemEntity file in files) { | ||
| 257 | -// file.deleteSync(); | ||
| 258 | -// } | ||
| 259 | -// } | ||
| 260 | -// DioUtil().download(url.toString(), savePath, | ||
| 261 | -// onProgress: (received, total) { | ||
| 262 | -// // if (_progress != 100) { | ||
| 263 | -// // int progress = ((received / total) * 100).round(); | ||
| 264 | -// // _progress = progress; | ||
| 265 | -// // _setState(() {}); | ||
| 266 | -// // } | ||
| 267 | -// if (received == total) { | ||
| 268 | -// print('object'); | ||
| 269 | -// Utils.showToast('文件已保存在${savePath}'); | ||
| 270 | -// // openFile(savePath); | ||
| 271 | -// //下载完成 | ||
| 272 | -// // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 273 | -// } | ||
| 274 | -// }); | ||
| 275 | -// // }, | ||
| 276 | -// // DioUtil().download(url.toString(), | ||
| 277 | -// // (await getExternalStorageDirectory()).path, | ||
| 278 | -// // onProgress: (received, total) { | ||
| 279 | -// // // if (_progress != 100) { | ||
| 280 | -// // // int progress = ((received / total) * 100).round(); | ||
| 281 | -// // // _progress = progress; | ||
| 282 | -// // // _setState(() {}); | ||
| 283 | -// // // } | ||
| 284 | -// // if (received == total) { | ||
| 285 | -// // //下载完成 | ||
| 286 | -// // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 287 | -// // } | ||
| 288 | -// // }); | ||
| 289 | -// }, | ||
| 290 | -// )) | ||
| 291 | -// ], | ||
| 292 | -// ) | ||
| 293 | -// // Builder(builder: (BuildContext context) { | ||
| 294 | -// // return WebView( | ||
| 295 | -// // initialUrl: "http://colorcun.com/privacy1.html", | ||
| 296 | -// // javascriptMode: JavascriptMode.unrestricted, | ||
| 297 | -// // onWebViewCreated: (WebViewController webViewController) { | ||
| 298 | -// // _controller.complete(webViewController); | ||
| 299 | -// // }, | ||
| 300 | -// // // TODO(iskakaushik): Remove this when collection literals makes it to stable. | ||
| 301 | -// // // ignore: prefer_collection_literals | ||
| 302 | -// // javascriptChannels: <JavascriptChannel>[ | ||
| 303 | -// // _toasterJavascriptChannel(context), | ||
| 304 | -// // ].toSet(), | ||
| 305 | -// // navigationDelegate: (NavigationRequest request) { | ||
| 306 | -// // if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 307 | -// // print('blocking navigation to $request}'); | ||
| 308 | -// // return NavigationDecision.prevent; | ||
| 309 | -// // } | ||
| 310 | -// // print('allowing navigation to $request'); | ||
| 311 | -// // return NavigationDecision.navigate; | ||
| 312 | -// // }, | ||
| 313 | -// // onPageStarted: (String url) { | ||
| 314 | -// // print('Page started loading: $url'); | ||
| 315 | -// // }, | ||
| 316 | -// // onPageFinished: (String url) async { | ||
| 317 | -// // print('Page finished loading: $url'); | ||
| 318 | -// // // showDownloadProgress(context); | ||
| 319 | -// // final dir = await getExternalStorageDirectory(); | ||
| 320 | -// // String savePath = dir.path + "/one_key"; | ||
| 321 | -// // DioUtil().download(url, savePath, | ||
| 322 | -// // onProgress: (received, total) { | ||
| 323 | -// // // if (_progress != 100) { | ||
| 324 | -// // // int progress = ((received / total) * 100).round(); | ||
| 325 | -// // // _progress = progress; | ||
| 326 | -// // // _setState(() {}); | ||
| 327 | -// // // } | ||
| 328 | -// // if (received == total) { | ||
| 329 | -// // print('object'); | ||
| 330 | -// // //下载完成 | ||
| 331 | -// // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 332 | -// // } | ||
| 333 | -// // }); | ||
| 334 | -// // }, | ||
| 335 | -// // gestureNavigationEnabled: true, | ||
| 336 | -// // ); | ||
| 337 | -// // }), | ||
| 338 | -// ); | ||
| 339 | -// } | 253 | + Directory directory = new Directory(savePath); |
| 254 | + if (directory.existsSync()) { | ||
| 255 | + //删除历史apk | ||
| 256 | + final List<FileSystemEntity> files = directory.listSync(); | ||
| 257 | + for (FileSystemEntity file in files) { | ||
| 258 | + file.deleteSync(); | ||
| 259 | + } | ||
| 260 | + } | ||
| 261 | + DioUtil().download(url.toString(), savePath, | ||
| 262 | + onProgress: (received, total) { | ||
| 263 | + // if (_progress != 100) { | ||
| 264 | + // int progress = ((received / total) * 100).round(); | ||
| 265 | + // _progress = progress; | ||
| 266 | + // _setState(() {}); | ||
| 267 | + // } | ||
| 268 | + if (received == total) { | ||
| 269 | + print('object'); | ||
| 270 | + Utils.showToast('文件已保存在${savePath}'); | ||
| 271 | + // openFile(savePath); | ||
| 272 | + //下载完成 | ||
| 273 | + // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 274 | + } | ||
| 275 | + }); | ||
| 276 | + // }, | ||
| 277 | + // DioUtil().download(url.toString(), | ||
| 278 | + // (await getExternalStorageDirectory()).path, | ||
| 279 | + // onProgress: (received, total) { | ||
| 280 | + // // if (_progress != 100) { | ||
| 281 | + // // int progress = ((received / total) * 100).round(); | ||
| 282 | + // // _progress = progress; | ||
| 283 | + // // _setState(() {}); | ||
| 284 | + // // } | ||
| 285 | + // if (received == total) { | ||
| 286 | + // //下载完成 | ||
| 287 | + // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 288 | + // } | ||
| 289 | + // }); | ||
| 290 | + }, | ||
| 291 | + )) | ||
| 292 | + ], | ||
| 293 | + ) | ||
| 294 | + // Builder(builder: (BuildContext context) { | ||
| 295 | + // return WebView( | ||
| 296 | + // initialUrl: "http://colorcun.com/privacy1.html", | ||
| 297 | + // javascriptMode: JavascriptMode.unrestricted, | ||
| 298 | + // onWebViewCreated: (WebViewController webViewController) { | ||
| 299 | + // _controller.complete(webViewController); | ||
| 300 | + // }, | ||
| 301 | + // // TODO(iskakaushik): Remove this when collection literals makes it to stable. | ||
| 302 | + // // ignore: prefer_collection_literals | ||
| 303 | + // javascriptChannels: <JavascriptChannel>[ | ||
| 304 | + // _toasterJavascriptChannel(context), | ||
| 305 | + // ].toSet(), | ||
| 306 | + // navigationDelegate: (NavigationRequest request) { | ||
| 307 | + // if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 308 | + // print('blocking navigation to $request}'); | ||
| 309 | + // return NavigationDecision.prevent; | ||
| 310 | + // } | ||
| 311 | + // print('allowing navigation to $request'); | ||
| 312 | + // return NavigationDecision.navigate; | ||
| 313 | + // }, | ||
| 314 | + // onPageStarted: (String url) { | ||
| 315 | + // print('Page started loading: $url'); | ||
| 316 | + // }, | ||
| 317 | + // onPageFinished: (String url) async { | ||
| 318 | + // print('Page finished loading: $url'); | ||
| 319 | + // // showDownloadProgress(context); | ||
| 320 | + // final dir = await getExternalStorageDirectory(); | ||
| 321 | + // String savePath = dir.path + "/one_key"; | ||
| 322 | + // DioUtil().download(url, savePath, | ||
| 323 | + // onProgress: (received, total) { | ||
| 324 | + // // if (_progress != 100) { | ||
| 325 | + // // int progress = ((received / total) * 100).round(); | ||
| 326 | + // // _progress = progress; | ||
| 327 | + // // _setState(() {}); | ||
| 328 | + // // } | ||
| 329 | + // if (received == total) { | ||
| 330 | + // print('object'); | ||
| 331 | + // //下载完成 | ||
| 332 | + // // InstallPlugin.installApk(savePath, "com.naji.one_key"); | ||
| 333 | + // } | ||
| 334 | + // }); | ||
| 335 | + // }, | ||
| 336 | + // gestureNavigationEnabled: true, | ||
| 337 | + // ); | ||
| 338 | + // }), | ||
| 339 | + ); | ||
| 340 | + } | ||
| 340 | 341 | ||
| 341 | -// // JavascriptChannel _toasterJavascriptChannel(BuildContext context) { | ||
| 342 | -// // return JavascriptChannel( | ||
| 343 | -// // name: 'Toaster', | ||
| 344 | -// // onMessageReceived: (JavascriptMessage message) { | ||
| 345 | -// // Scaffold.of(context).showSnackBar( | ||
| 346 | -// // SnackBar(content: Text(message.message)), | ||
| 347 | -// // ); | ||
| 348 | -// // }); | ||
| 349 | -// // } | ||
| 350 | -// } | 342 | + // JavascriptChannel _toasterJavascriptChannel(BuildContext context) { |
| 343 | + // return JavascriptChannel( | ||
| 344 | + // name: 'Toaster', | ||
| 345 | + // onMessageReceived: (JavascriptMessage message) { | ||
| 346 | + // Scaffold.of(context).showSnackBar( | ||
| 347 | + // SnackBar(content: Text(message.message)), | ||
| 348 | + // ); | ||
| 349 | + // }); | ||
| 350 | + // } | ||
| 351 | +} | ||
| 351 | 352 | ||
| 352 | -// // class WebPage extends StatelessWidget { | ||
| 353 | -// // final String title; | ||
| 354 | -// // final String url; | ||
| 355 | -// // final bool need; | 353 | +// class WebPage extends StatelessWidget { |
| 354 | +// final String title; | ||
| 355 | +// final String url; | ||
| 356 | +// final bool need; | ||
| 356 | 357 | ||
| 357 | -// // const WebPage({Key key, this.title, this.url, this.need = false}) | ||
| 358 | -// // : super(key: key); | ||
| 359 | -// // @override | ||
| 360 | -// // Widget build(BuildContext context) { | ||
| 361 | -// // final Completer<WebViewController> _controller = | ||
| 362 | -// // Completer<WebViewController>(); | ||
| 363 | -// // return Scaffold( | ||
| 364 | -// // appBar: SystemAppBar(title, onTap: () { | ||
| 365 | -// // if (need) { | ||
| 366 | -// // Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 367 | -// // } | ||
| 368 | -// // Navigator.of(context).pop(); | ||
| 369 | -// // }), | ||
| 370 | -// // body: WillPopScope( | ||
| 371 | -// // onWillPop: () async { | ||
| 372 | -// // if (need) { | ||
| 373 | -// // Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 374 | -// // } | ||
| 375 | -// // return true; | ||
| 376 | -// // }, | ||
| 377 | -// // child: WebView( | ||
| 378 | -// // initialUrl: "http://colorcun.com/privacy1.html", | ||
| 379 | -// // javascriptMode: JavascriptMode.unrestricted, | ||
| 380 | -// // onWebViewCreated: (WebViewController webViewController) { | ||
| 381 | -// // // Loading.showLoading(context); | ||
| 382 | -// // _controller.complete(webViewController); | ||
| 383 | -// // }, | ||
| 384 | -// // javascriptChannels: <JavascriptChannel>[ | ||
| 385 | -// // _toasterJavascriptChannel(context), | ||
| 386 | -// // ].toSet(), | ||
| 387 | -// // navigationDelegate: (NavigationRequest request) { | ||
| 388 | -// // if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 389 | -// // return NavigationDecision.prevent; | ||
| 390 | -// // } | ||
| 391 | -// // return NavigationDecision.navigate; | ||
| 392 | -// // }, | ||
| 393 | -// // onPageStarted: (String url) {}, | ||
| 394 | -// // onPageFinished: (String url) { | ||
| 395 | -// // // Loading.hideLoading(context); | ||
| 396 | -// // }, | ||
| 397 | -// // gestureNavigationEnabled: true, | ||
| 398 | -// // )), | ||
| 399 | -// // ); | ||
| 400 | -// // } | 358 | +// const WebPage({Key key, this.title, this.url, this.need = false}) |
| 359 | +// : super(key: key); | ||
| 360 | +// @override | ||
| 361 | +// Widget build(BuildContext context) { | ||
| 362 | +// final Completer<WebViewController> _controller = | ||
| 363 | +// Completer<WebViewController>(); | ||
| 364 | +// return Scaffold( | ||
| 365 | +// appBar: SystemAppBar(title, onTap: () { | ||
| 366 | +// if (need) { | ||
| 367 | +// Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 368 | +// } | ||
| 369 | +// Navigator.of(context).pop(); | ||
| 370 | +// }), | ||
| 371 | +// body: WillPopScope( | ||
| 372 | +// onWillPop: () async { | ||
| 373 | +// if (need) { | ||
| 374 | +// Utils.changeStatusColor(color: MyColours.color_199095); | ||
| 375 | +// } | ||
| 376 | +// return true; | ||
| 377 | +// }, | ||
| 378 | +// child: WebView( | ||
| 379 | +// initialUrl: "http://colorcun.com/privacy1.html", | ||
| 380 | +// javascriptMode: JavascriptMode.unrestricted, | ||
| 381 | +// onWebViewCreated: (WebViewController webViewController) { | ||
| 382 | +// // Loading.showLoading(context); | ||
| 383 | +// _controller.complete(webViewController); | ||
| 384 | +// }, | ||
| 385 | +// javascriptChannels: <JavascriptChannel>[ | ||
| 386 | +// _toasterJavascriptChannel(context), | ||
| 387 | +// ].toSet(), | ||
| 388 | +// navigationDelegate: (NavigationRequest request) { | ||
| 389 | +// if (request.url.startsWith('https://www.youtube.com/')) { | ||
| 390 | +// return NavigationDecision.prevent; | ||
| 391 | +// } | ||
| 392 | +// return NavigationDecision.navigate; | ||
| 393 | +// }, | ||
| 394 | +// onPageStarted: (String url) {}, | ||
| 395 | +// onPageFinished: (String url) { | ||
| 396 | +// // Loading.hideLoading(context); | ||
| 397 | +// }, | ||
| 398 | +// gestureNavigationEnabled: true, | ||
| 399 | +// )), | ||
| 400 | +// ); | ||
| 401 | +// } | ||
| 401 | 402 | ||
| 402 | -// // JavascriptChannel _toasterJavascriptChannel(BuildContext context) { | ||
| 403 | -// // return JavascriptChannel( | ||
| 404 | -// // name: 'Toaster', | ||
| 405 | -// // onMessageReceived: (JavascriptMessage message) { | ||
| 406 | -// // Scaffold.of(context).showSnackBar( | ||
| 407 | -// // SnackBar(content: Text(message.message)), | ||
| 408 | -// // ); | ||
| 409 | -// // }); | ||
| 410 | -// // } | ||
| 411 | -// // } | 403 | +// JavascriptChannel _toasterJavascriptChannel(BuildContext context) { |
| 404 | +// return JavascriptChannel( | ||
| 405 | +// name: 'Toaster', | ||
| 406 | +// onMessageReceived: (JavascriptMessage message) { | ||
| 407 | +// Scaffold.of(context).showSnackBar( | ||
| 408 | +// SnackBar(content: Text(message.message)), | ||
| 409 | +// ); | ||
| 410 | +// }); | ||
| 411 | +// } | ||
| 412 | +// } |
-
Please register or login to post a comment