From 135caf5adc5b15b8e127e90aa89fd6c1bbbe3368 Mon Sep 17 00:00:00 2001 From: zhuce <821293938@qq.com> Date: Tue, 12 Mar 2024 20:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Podfile.lock | 20 +++- lib/api/login_api.dart | 22 +++- lib/config/getui_constant.dart | 5 + lib/main.dart | 172 +++++++++++++++++++++++++++++++- lib/pages/home/home_page.dart | 62 +++++++----- lib/pages/login/login_page.dart | 9 +- 6 files changed, 254 insertions(+), 36 deletions(-) create mode 100644 lib/config/getui_constant.dart diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 9984e41..10268b3 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -13,15 +13,24 @@ PODS: - device_info_plus (0.0.1): - Flutter - Flutter (1.0.0) + - getuiflut (0.0.1): + - Flutter + - GTSDK + - GTCommonSDK (3.1.1.0): + - ZXSDK + - GTSDK (3.0.5.0): + - GTCommonSDK (> 3.0.9.0) - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS + - ZXSDK (3.2.5) DEPENDENCIES: - amap_flutter_location (from `.symlinks/plugins/amap_flutter_location/ios`) - amap_flutter_map (from `.symlinks/plugins/amap_flutter_map/ios`) - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - Flutter (from `Flutter`) + - getuiflut (from `.symlinks/plugins/getuiflut/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) SPEC REPOS: @@ -29,6 +38,9 @@ SPEC REPOS: - AMap3DMap - AMapFoundation - AMapLocation + - GTCommonSDK + - GTSDK + - ZXSDK EXTERNAL SOURCES: amap_flutter_location: @@ -39,6 +51,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/device_info_plus/ios" Flutter: :path: Flutter + getuiflut: + :path: ".symlinks/plugins/getuiflut/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" @@ -49,8 +63,12 @@ SPEC CHECKSUMS: AMapFoundation: 9885c48fc3a78fdfb84a0299a2293e56ea3c9fec AMapLocation: 5248aec2455ebb5d104b367813c946430a2ee033 device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6 - Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + getuiflut: 8628ba2b64a738a847a07d2b67e0ac305778e2ee + GTCommonSDK: 2be8c2d5b094929f81b64dba8767bf110bae78de + GTSDK: cc04d169c5c6cb8f8884849153eaac9e6ccfdd7c shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695 + ZXSDK: 414bed508b670437a9bdf7c75d49816b8cb7b2d4 PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796 diff --git a/lib/api/login_api.dart b/lib/api/login_api.dart index b06e241..91ee81e 100644 --- a/lib/api/login_api.dart +++ b/lib/api/login_api.dart @@ -1,9 +1,15 @@ +import 'dart:convert'; + +import 'package:autosos_flutter/pages/home/home_page.dart'; +import 'package:autosos_flutter/util/sp_util.dart'; import 'package:autosos_flutter/util/xhttp.dart'; +import 'package:flutter/material.dart'; class LoginApi { static XHttp xHttp = XHttp.getInstance(); + static SPUtil spUtil = SPUtil(); - static void login(int type, String username, String password, String code, + static void login(BuildContext context,int type, String username, String password, String code, String cid, String openid, String unionid) async { var data = { "type": type, @@ -15,7 +21,17 @@ class LoginApi { "wx_unionid": unionid }; var headers = {'Content-Type': 'application/x-www-form-urlencoded'}; - var post = await xHttp.post("/v2/auth/get-access-token", data, headers); - // print(post); + Result response = await xHttp.post("/v2/auth/get-access-token", data, headers); + var resData = response.data; + var resCode = resData['code']; + if(resCode==1){ + var accessToken = resData['data']['access_token']; + spUtil.setString("accessToken", accessToken); + if(!context.mounted) return; + Navigator.of(context).push(MaterialPageRoute(builder: (context)=> const HomePage())); + }else{ + var msg = resData['message']; + Toast.show(msg); + } } } diff --git a/lib/config/getui_constant.dart b/lib/config/getui_constant.dart new file mode 100644 index 0000000..1bec6e6 --- /dev/null +++ b/lib/config/getui_constant.dart @@ -0,0 +1,5 @@ +class GetuiConstant{ + static const String appId = "D3cqMVd0aA6nYsVx9Gdgo9"; + static const String appKey = "OtBVS1PjCy5aLWNVM3aQY1"; + static const String appSecret = "juiYAn4XXc6BPVAI6DQlh8"; +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index e6b8729..302912e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,18 +1,30 @@ + +import 'dart:io'; + import 'package:autosos_flutter/config/theme_colors.dart'; -import 'package:autosos_flutter/pages/home/home_page.dart'; import 'package:autosos_flutter/pages/login/login_page.dart'; +import 'package:autosos_flutter/util/sp_util.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:getuiflut/getuiflut.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'config/getui_constant.dart'; + void main() { SharedPreferences.setMockInitialValues({}); runApp(const MyApp()); } -class MyApp extends StatelessWidget { +class MyApp extends StatefulWidget { const MyApp({super.key}); + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -26,4 +38,160 @@ class MyApp extends StatelessWidget { builder: EasyLoading.init(), ); } + + String _platformVersion = 'Unknown'; + String _payloadInfo = 'Null'; + String _userMsg = ""; + String _notificationState = ""; + String _getClientId = ""; + String _getDeviceToken = ""; + String _onReceivePayload = ""; + String _onReceiveNotificationResponse = ""; + String _onAppLinkPayLoad = ""; + + SPUtil spUtil = SPUtil(); + + @override + void initState() { + super.initState(); + initPlatformState(); + } + + // Platform messages are asynchronous, so we initialize in an async method. + Future initPlatformState() async { + String platformVersion; + String payloadInfo = "default"; + String notificationState = "default"; + // Platform messages may fail, so we use a try/catch PlatformException. + + if (Platform.isIOS) { + getSdkVersion(); + Getuiflut().startSdk( + appId: GetuiConstant.appId, + appKey: GetuiConstant.appKey, + appSecret: GetuiConstant.appSecret); + } + + try { + platformVersion = await Getuiflut.platformVersion; + + print('platformVersion' + platformVersion); + } on PlatformException { + platformVersion = 'Failed to get platform version.'; + } + + // If the widget was removed from the tree while the asynchronous platform + // message was in flight, we want to discard the reply rather than calling + // setState to update our non-existent appearance. + if (!mounted) return; + + setState(() { + _platformVersion = platformVersion; + _payloadInfo = payloadInfo; + _notificationState = notificationState; + }); + + Getuiflut().addEventHandler(onReceiveClientId: (String message) async { + print("flutter onReceiveClientId: $message"); + spUtil.setString("clientId", message); + setState(() { + _getClientId = "ClientId: $message"; + }); + }, onReceiveMessageData: (Map msg) async { + print("flutter onReceiveMessageData: $msg"); + setState(() { + _payloadInfo = msg['payload']; + }); + }, onNotificationMessageArrived: (Map msg) async { + print("flutter onNotificationMessageArrived: $msg"); + setState(() { + _notificationState = 'Arrived'; + }); + }, onNotificationMessageClicked: (Map msg) async { + print("flutter onNotificationMessageClicked: $msg"); + setState(() { + _notificationState = 'Clicked'; + }); + }, onTransmitUserMessageReceive: (Map msg) async { + print("flutter onTransmitUserMessageReceive:$msg"); + setState(() { + _userMsg = msg["msg"]; + }); + }, onRegisterDeviceToken: (String message) async { + print("flutter onRegisterDeviceToken: $message"); + setState(() { + _getDeviceToken = "$message"; + }); + }, onReceivePayload: (Map message) async { + print("flutter onReceivePayload: $message"); + setState(() { + _onReceivePayload = "$message"; + }); + }, onReceiveNotificationResponse: (Map message) async { + print("flutter onReceiveNotificationResponse: $message"); + setState(() { + _onReceiveNotificationResponse = "$message"; + }); + }, onAppLinkPayload: (String message) async { + print("flutter onAppLinkPayload: $message"); + setState(() { + _onAppLinkPayLoad = "$message"; + }); + }, onPushModeResult: (Map message) async { + print("flutter onPushModeResult: $message"); + }, onSetTagResult: (Map message) async { + print("flutter onSetTagResult: $message"); + }, onAliasResult: (Map message) async { + print("flutter onAliasResult: $message"); + }, onQueryTagResult: (Map message) async { + print("flutter onQueryTagResult: $message"); + }, onWillPresentNotification: (Map message) async { + print("flutter onWillPresentNotification: $message"); + }, onOpenSettingsForNotification: (Map message) async { + print("flutter onOpenSettingsForNotification: $message"); + }, onGrantAuthorization: (String granted) async { + print("flutter onGrantAuthorization: $granted"); + }, onLiveActivityResult: (Map message) async { + print("flutter onLiveActivityResult: $message"); + }); + } + + Future initGetuiSdk() async { + try { + Getuiflut.initGetuiSdk; + } catch (e) { + e.toString(); + } + } + + Future getClientId() async { + String getClientId; + try { + getClientId = await Getuiflut.getClientId; + print(getClientId); + } catch (e) { + print(e.toString()); + } + } + + Future getSdkVersion() async { + String ver; + try { + ver = await Getuiflut.sdkVersion; + print(ver); + } catch (e) { + print(e.toString()); + } + } + + Future getLaunchNotification() async { + Map info; + try { + info = await Getuiflut.getLaunchNotification; + print(info); + } catch (e) { + print(e.toString()); + } + } + } diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 6b73e67..0d3a1a5 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -16,10 +16,12 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { bool enabled = false; late AMapController _mapController; + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( + automaticallyImplyLeading: false, title: const Text( "首页", style: TextStyle(color: Colors.white), @@ -34,14 +36,17 @@ class _HomePageState extends State { fit: BoxFit.cover)), )), backgroundColor: const Color(0xFFF3F3F3), - body: Padding( - padding: const EdgeInsets.all(10), - child: Column( - children: [ - buildTopWidget(), - buildMiddleWidget(), - buildBottomWidget() - ], + body: PopScope( + canPop: false, + child: Padding( + padding: const EdgeInsets.all(10), + child: Column( + children: [ + buildTopWidget(), + buildMiddleWidget(), + buildBottomWidget() + ], + ), ), )); } @@ -236,7 +241,7 @@ class _HomePageState extends State { circleStrokeColor: Colors.blue, circleStrokeWidth: 1, ), - onMapCreated: (AMapController controller){ + onMapCreated: (AMapController controller) { setState(() { _mapController = controller; getApprovalNumber(); @@ -244,33 +249,36 @@ class _HomePageState extends State { }, ); return Expanded( - child: Stack( - children: [ - Container( - margin: const EdgeInsets.only(top: 10,bottom: 10), - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(5))), - child: map, + child: Stack( + children: [ + Container( + margin: const EdgeInsets.only(top: 10, bottom: 10), + decoration: const BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(5))), + child: map, + ), + Positioned( + bottom: 20, + right: 20, + child: Image.asset( + "images/3.0x/current_location.png", + width: 30, + height: 30, ), - Positioned( - bottom: 20, - right: 20, - child: Image.asset("images/3.0x/current_location.png",width: 30,height: 30,), - ) - ], - ) - ); + ) + ], + )); } ///获取审图号 void getApprovalNumber() async { //普通地图审图号 String? mapContentApprovalNumber = - await _mapController.getMapContentApprovalNumber(); + await _mapController.getMapContentApprovalNumber(); //卫星地图审图号 String? satelliteImageApprovalNumber = - await _mapController.getSatelliteImageApprovalNumber(); + await _mapController.getSatelliteImageApprovalNumber(); print('地图审图号(普通地图): $mapContentApprovalNumber'); print('地图审图号(卫星地图): $satelliteImageApprovalNumber'); } diff --git a/lib/pages/login/login_page.dart b/lib/pages/login/login_page.dart index 08a9206..ac25726 100644 --- a/lib/pages/login/login_page.dart +++ b/lib/pages/login/login_page.dart @@ -1,4 +1,5 @@ import 'package:autosos_flutter/api/login_api.dart'; +import 'package:autosos_flutter/util/sp_util.dart'; import 'package:autosos_flutter/util/xhttp.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; @@ -15,6 +16,7 @@ class LoginPage extends StatefulWidget { class _LoginPageState extends State { final TextEditingController _unameController = TextEditingController(); final TextEditingController _pwdController = TextEditingController(); + SPUtil spUtil = SPUtil(); @override Widget build(BuildContext context) { return Scaffold( @@ -77,7 +79,7 @@ class _LoginPageState extends State { Padding( padding: const EdgeInsets.all(20), child: GestureDetector( - onTap:()=>_login(), + onTap:()=>_login(context), child: Container( padding: const EdgeInsets.all(12), margin: const EdgeInsets.only(top: 40), @@ -99,9 +101,10 @@ class _LoginPageState extends State { ); } - void _login() async{ + void _login(BuildContext context) async{ String username = _unameController.text; String password = _pwdController.text; - LoginApi.login(1, username, password, "", "", "", ""); + String cid = spUtil.get("clientId"); + LoginApi.login(context,1, username, password, "", cid, "", ""); } }