diff --git a/lib/address/address_map_page.dart b/lib/address/address_map_page.dart index e8d1d6d1..dca398f2 100644 --- a/lib/address/address_map_page.dart +++ b/lib/address/address_map_page.dart @@ -104,7 +104,7 @@ class _AddressMapPage extends State { Future.delayed(Duration(seconds: 6), () { EasyLoading.dismiss(); }); - } else if (await PH.Permission.location.isUndetermined) { + } else if (await PH.Permission.location.isDenied) { await PH.Permission.location.request(); } else { if (Platform.isIOS) { diff --git a/lib/home/help_farmers/help_farmers_page.dart b/lib/home/help_farmers/help_farmers_page.dart index acafdd31..f2be0a3d 100644 --- a/lib/home/help_farmers/help_farmers_page.dart +++ b/lib/home/help_farmers/help_farmers_page.dart @@ -11,6 +11,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/view_widget/my_footer.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:shimmer/shimmer.dart'; import '../../generated/l10n.dart'; import '../../retrofit/data/base_data.dart'; @@ -33,6 +34,8 @@ class _HelpFarmersPage extends State { final RefreshController refreshController = RefreshController(); List farmersList = []; int tabIndex = 0; + int networkStatus = 0; + String dataErrorText = ""; @override void initState() { @@ -42,7 +45,7 @@ class _HelpFarmersPage extends State { Dio(), context: context, token: value.getString('token'), - // showLoading: true + showLoading: true ), queryConfig(), }); @@ -63,14 +66,18 @@ class _HelpFarmersPage extends State { await apiService.getConfig().catchError((error) { SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type), alignment: Alignment.center); + networkStatus = -1; refreshController.refreshFailed(); }); if (baseData != null && baseData.isSuccess) { farmersList.clear(); farmersList.addAll(baseData.data); refreshController.refreshCompleted(); + networkStatus= 1; } else { refreshController.refreshFailed(); + dataErrorText = baseData.msg ?? ""; + networkStatus=2; } }finally{ setState(() {}); @@ -84,7 +91,17 @@ class _HelpFarmersPage extends State { Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.transparent, - body: NestedScrollView( + body: networkStatus == 0 ?recommendSm(): + (networkStatus == 2 ?Container( + color: Colors.white, + child: NoDataView( + src: "assets/image/xiao_fei.webp", + isShowBtn: false, + text: dataErrorText, + fontSize: 16.sp, + margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w), + ) + ):NestedScrollView( headerSliverBuilder: (context, inner) { return [ SliverAppBar( @@ -127,8 +144,8 @@ class _HelpFarmersPage extends State { alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.vertical( - top: Radius.circular(16), - ), + top: Radius.circular(16), + ), color: Color(0xFF32A060), ), padding: EdgeInsets.only(top:7.h,bottom: 7.h), @@ -170,7 +187,7 @@ class _HelpFarmersPage extends State { ]; }, body: recommend(), - ), + )), ); } @@ -302,4 +319,174 @@ class _HelpFarmersPage extends State { ), ); } + + Widget recommendSm() { + return Container( + width: double.infinity, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(6)), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(25), + offset: Offset(0, 1), + blurRadius: 12, + spreadRadius: 0, + ) + ]), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + color: Color(0XFFD8D8D8), + width: double.infinity, + height:289.h, + ), + ), + Row( + children: [ + Padding( + padding: EdgeInsets.only(left: 6.w, bottom: 5.h, top: 12.h), + child: Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(2), + ), + width:64.w, + height: 20.h, + ), + ), + ), + Padding( + padding: EdgeInsets.only(left: 12.w, bottom: 5.h, top: 12.h), + child: Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(2), + ), + width: 64.w, + height: 20.h, + ), + ), + ), + Padding( + padding: EdgeInsets.only(left: 12.w, bottom: 5.h, top: 12.h), + child: Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(2), + ), + width: 64.w, + height: 20.h, + ), + ), + ), + Padding( + padding: EdgeInsets.only(left: 12.w, bottom: 5.h, top: 12.h), + child: Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(2), + ), + width: 64.w, + height: 20.h, + ), + ), + ), + ], + ), + Expanded(child: ListView.builder( + itemCount: 10, + physics: BouncingScrollPhysics(), + shrinkWrap: true, + itemBuilder: (context, position) { + return GestureDetector( + onTap: () {}, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + margin:EdgeInsets.symmetric(horizontal:6.w), + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(2), + ), + height: 174.h, + ), + ), + Padding( + padding: EdgeInsets.only(top: 7.h, left: 10.w, bottom: 8.h), + child: Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(2), + ), + width:106.w, + height: 20.h, + ), + ), + ), + Padding( + padding: EdgeInsets.only(left: 10.w, bottom: 12.h), + child:Row( + children: [ + Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(2), + ), + width: 166.w, + height: 20.h, + ), + ), + Spacer(), + Shimmer.fromColors( + baseColor: Color(0XFFD8D8D8), + highlightColor: Color(0XFFD8D8D8), + child: Container( + margin: EdgeInsets.only(right: 10.w), + decoration: BoxDecoration( + color: Color(0XFFD8D8D8), + borderRadius: BorderRadius.circular(100), + ), + width: 86.w, + height: 25.h, + ), + ), + ], + ), + ), + ], + ), + ); + }, + )), + ], + ), + ); + } } diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index 37ffa091..73e9cdfb 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -2228,7 +2228,9 @@ class _ApiService implements ApiService { data: _data); final value = BaseData>.fromJson( _result.data, - (json) => (json as List) + (json) => (json ?? "") == "" + ? null + :(json as List) .map( (i) => FarmersList.fromJson(i as Map)) .toList()); diff --git a/lib/setting/permission_setting_page.dart b/lib/setting/permission_setting_page.dart index b0cbf557..a4ea4ff5 100644 --- a/lib/setting/permission_setting_page.dart +++ b/lib/setting/permission_setting_page.dart @@ -117,7 +117,7 @@ class _PermissionSettingPage extends State { } if (await permission.isPermanentlyDenied) { requestDialog(position); - } else if (await permission.isUndetermined) { + } else if (await permission.isDenied) { await permission.request(); queryPermission(); } else { diff --git a/lib/union/union_page.dart b/lib/union/union_page.dart index 3772695a..ee2adb2e 100644 --- a/lib/union/union_page.dart +++ b/lib/union/union_page.dart @@ -22,6 +22,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:visibility_detector/visibility_detector.dart'; +import '../utils/send_location_dialog.dart'; import '../view_widget/location_tips.dart'; import '../view_widget/no_data_view.dart'; @@ -115,6 +116,12 @@ class UnionPageState extends State } getLocation({bool showLoading = true}) async { + // await showDialog( + // context: context, + // useRootNavigator: false, + // builder: (c) => SendLocationDialog(), + // ); + // return; if(showLoading) EasyLoading.show( status: S.current.zhengzaijiazai, diff --git a/lib/utils/location.dart b/lib/utils/location.dart index feda0fec..b1bba7b1 100644 --- a/lib/utils/location.dart +++ b/lib/utils/location.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; diff --git a/lib/utils/send_location_dialog.dart b/lib/utils/send_location_dialog.dart new file mode 100644 index 00000000..0b5eaba4 --- /dev/null +++ b/lib/utils/send_location_dialog.dart @@ -0,0 +1,119 @@ +import 'dart:async'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'package:geolocator/geolocator.dart'; + +class SendLocationDialog extends StatefulWidget { + + const SendLocationDialog({ + Key key, + }) : super(key: key); + + @override + SendLocationDialogState createState() => SendLocationDialogState(); +} + +class SendLocationDialogState extends State { + bool disabled = false; + bool denied = false; + bool isSending = false; + Position position; + Object error; + + @override + void initState() { + super.initState(); + requestLocation(); + } + + Future requestLocation() async { + if (!(await Geolocator.isLocationServiceEnabled())) { + setState(() => disabled = true); + return; + } + var permission = await Geolocator.checkPermission(); + if (permission == LocationPermission.denied) { + permission = await Geolocator.requestPermission(); + if (permission == LocationPermission.denied) { + setState(() => denied = true); + return; + } + } + if (permission == LocationPermission.deniedForever) { + setState(() => denied = true); + return; + } + try { + Position position; + try { + position = await Geolocator.getCurrentPosition( + desiredAccuracy: LocationAccuracy.best, + timeLimit: const Duration(seconds: 30), + ); + } on TimeoutException { + position = await Geolocator.getCurrentPosition( + desiredAccuracy: LocationAccuracy.medium, + timeLimit: const Duration(seconds: 30), + ); + } + setState(() => this.position = position); + } catch (e) { + setState(() => error = e); + } + } + + void sendAction() async { + setState(() => isSending = true); + final body = + 'https://www.openstreetmap.org/?mlat=${position.latitude}&mlon=${position.longitude}#map=16/${position.latitude}/${position.longitude}'; + final uri = + 'geo:${position.latitude},${position.longitude};u=${position.accuracy}'; + Navigator.of(context, rootNavigator: false).pop(); + } + + @override + Widget build(BuildContext context) { + Widget contentWidget; + if (position != null) { + // contentWidget = MapBubble( + // latitude: position.latitude, + // longitude: position.longitude, + // ); + contentWidget = Text("MapBubble"); + } else if (disabled) { + contentWidget = Text("locationDisabledNotice"); + } else if (denied) { + contentWidget = Text("locationPermissionDeniedNotice"); + } else if (error != null) { + contentWidget = + Text(error.toString()); + } else { + contentWidget = Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const CupertinoActivityIndicator(), + const SizedBox(width: 12), + Text("obtainingLocation"), + ], + ); + } + return AlertDialog( + title: Text("shareLocation"), + content: contentWidget, + actions: [ + TextButton( + onPressed: Navigator.of(context, rootNavigator: false).pop, + child: Text("cancel"), + ), + if (position != null) + TextButton( + onPressed: isSending ? null : sendAction, + child: Text("send"), + ), + ], + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 60fcba17..6179415f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: args - sha256: b003c3098049a51720352d219b0bb5f219b60fbfb68e7a4748139a06a5676515 + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 url: "https://pub.flutter-io.cn" source: hosted - version: "2.3.1" + version: "2.4.2" asn1lib: dependency: transitive description: @@ -141,10 +141,10 @@ packages: dependency: transitive description: name: convert - sha256: "1be13198012c1d5bc042dc40ad1d7f16cbd522350984c0c1abf471d6d7e305c6" + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" url: "https://pub.flutter-io.cn" source: hosted - version: "3.1.0" + version: "3.1.1" crypto: dependency: transitive description: @@ -401,18 +401,50 @@ packages: dependency: "direct main" description: name: geolocator - sha256: "3018f6a37b1ec3c9dfb1adaa1ce406c0522c293a1a623ead94c32cd93a255fd3" + sha256: "5c23f3613f50586c0bbb2b8f970240ae66b3bd992088cf60dd5ee2e6f7dde3a8" + url: "https://pub.flutter-io.cn" + source: hosted + version: "9.0.2" + geolocator_android: + dependency: transitive + description: + name: geolocator_android + sha256: "06e37fa32392f69f133e166ef6b358a8b6afddbf4c418fc236988184cc115a49" + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.4.1" + geolocator_apple: + dependency: transitive + description: + name: geolocator_apple + sha256: bc2aca02423ad429cb0556121f56e60360a2b7d694c8570301d06ea0c00732fd url: "https://pub.flutter-io.cn" source: hosted - version: "6.1.12" + version: "2.3.7" geolocator_platform_interface: dependency: transitive description: name: geolocator_platform_interface - sha256: aa11c4cb9eb31f096ffc62cf54858f869bd437de327cba660577ddd594a8f3fa + sha256: b8cc1d3be0ca039a3f2174b0b026feab8af3610e220b8532e42cff8ec6658535 + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.1.0" + geolocator_web: + dependency: transitive + description: + name: geolocator_web + sha256: "102e7da05b48ca6bf0a5bda0010f886b171d1a08059f01bfe02addd0175ebece" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" + geolocator_windows: + dependency: transitive + description: + name: geolocator_windows + sha256: "4f4218f122a6978d0ad655fa3541eea74c67417440b09f0657238810d5af6bdc" url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.9" + version: "0.1.3" gradient_widgets: dependency: "direct main" description: @@ -553,10 +585,10 @@ packages: dependency: "direct main" description: name: mqtt_client - sha256: e8347f8996c33b80a6764a1881e94a8ef5392c2d6e724b9daad65eafa202b0c7 + sha256: ba10ec490ded55dc4e77bbc992529d823fb15d0d5ec68c2895f960312060c541 url: "https://pub.flutter-io.cn" source: hosted - version: "9.6.8" + version: "9.8.1" nested: dependency: transitive description: @@ -665,18 +697,18 @@ packages: dependency: "direct main" description: name: permission_handler - sha256: fb4666087528b1cbf91d98771cf50b14f36f4d8756ec7e7a8629dd3cb55442b7 + sha256: "7c008a350caabef1b372b5a2f5559dc178fc6f0745c4f6f5a0fd103b11d740d2" url: "https://pub.flutter-io.cn" source: hosted - version: "5.1.0+2" + version: "6.0.0" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface - sha256: f7e3c798f7c4dd215e4ca8843695b3a63a5b79c9aa04f296d316f13a15d518ba + sha256: "6760eb5ef34589224771010805bea6054ad28453906936f843a8cc4d3a55c4a4" url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.2" + version: "3.12.0" petitparser: dependency: transitive description: @@ -697,10 +729,10 @@ packages: dependency: "direct main" description: name: pin_input_text_field - sha256: "569861876d5c67994adc58ddd15e93bd0057c4f26d7e5599ccde880d05813463" + sha256: "8d6fc670aa673a4df5976086f0e8039972a5b2bcb783c8db8dd3b9b4b072ca90" url: "https://pub.flutter-io.cn" source: hosted - version: "4.4.1" + version: "4.5.1" platform: dependency: transitive description: @@ -709,14 +741,22 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.1.0" + platform_detect: + dependency: transitive + description: + name: platform_detect + sha256: aab1dd0e19af823c0bbfc2d0f364e33abc52bd13be27711fea98bade0fe35213 + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.4.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - sha256: c3ebbff365bfb1b5f7b690c9857d2dabea167f35b05eb7586186499b407efb37 + sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.3" + version: "2.1.6" pointycastle: dependency: transitive description: @@ -741,6 +781,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "6.0.5" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "3c51ec0aaeccb85cacfe824816c60e1e3c53da586c64e1166422a906a4f7251c" + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.4.4" pull_to_refresh: dependency: "direct main" description: @@ -898,6 +946,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.9.1" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.flutter-io.cn" + source: hosted + version: "7.0.0" stack_trace: dependency: transitive description: @@ -1015,26 +1071,18 @@ packages: dependency: "direct main" description: name: umeng_common_sdk - sha256: fce28065224b0839ffc16b5003d2295dae8aabee290bf639f978536b32ed601d + sha256: "60d7ac8093d42e236dbecb5fc8558b16644808a70d24514ad926be7ddf56d5e9" url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.6" + version: "1.2.7" url_launcher: dependency: "direct main" description: name: url_launcher - sha256: e1e0c46fcd777c0f0bd7f4541b747c28ad4e925f93344cebf667ef76c695533a - url: "https://pub.flutter-io.cn" - source: hosted - version: "5.7.10" - url_launcher_linux: - dependency: transitive - description: - name: url_launcher_linux - sha256: c489023cdd864a19c0be63bb3796bec21ea4bc16bfe09568953f1828e02151c9 + sha256: "0a1f90f605bbfa9832b3514cea3a74693c6e569b8a1999fabeba12d8216a85c9" url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+4" + version: "5.4.0" url_launcher_macos: dependency: transitive description: @@ -1047,26 +1095,26 @@ packages: dependency: transitive description: name: url_launcher_platform_interface - sha256: c6bd00f46e8c348703d0ae691850eb2052be8e1338dc3ae6f72af53b962da157 + sha256: "9b5396f49780ac4f3e6563ab0936d8218182b0f1498318b5a7d1528e0293704f" url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.9" + version: "1.0.1" url_launcher_web: dependency: transitive description: name: url_launcher_web - sha256: eaa6de8ac353681794533edcedd69dd8b39ed987bf2360d172185eff8283dbc2 + sha256: b7478fa6476d0971fd41508bea0b4a25c59ccd263daea09f22f8ca4114559043 url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.5+3" - url_launcher_windows: + version: "0.1.3" + uuid: dependency: transitive description: - name: url_launcher_windows - sha256: "034479b1dafd8f01de81267d8117eb5ae019e0dddcc23f4b14ed31253a2635d9" + name: uuid + sha256: b715b8d3858b6fa9f68f87d20d98830283628014750c2b09b6f516c1da4af2a7 url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+3" + version: "4.1.0" vector_math: dependency: transitive description: @@ -1204,5 +1252,5 @@ packages: source: hosted version: "5.4.1" sdks: - dart: ">=2.18.0 <3.0.0" - flutter: ">=3.0.0" + dart: ">=2.19.0 <3.0.0" + flutter: ">=3.7.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8accc489..f95c703d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,9 +39,9 @@ dependencies: number_precision: ^2.0.2+1 - permission_handler: ^5.0.1+1 + permission_handler: 6.0.0 - geolocator: ^6.1.12 + geolocator: ^9.0.0 # location: ^3.2.4 dio: ^3.0.10