diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 3edaeaf1..224ba09f 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -139,12 +139,15 @@ class AppProvider extends ChangeNotifier { } } - Map? _location; - Map? get location => _location; + Map? _location; + Map? get location => _location; late AMapFlutterLocation _aMapFlutterLocation; startLocation() { - if (kIsWeb || Platform.isMacOS) return; + if (kIsWeb || Platform.isMacOS) { + getWeather(); + return; + } _aMapFlutterLocation = AMapFlutterLocation(); _aMapFlutterLocation.onLocationChanged().listen((event) { _location = event; @@ -164,11 +167,19 @@ class AppProvider extends ChangeNotifier { _aMapFlutterLocation.destroy(); } - // Location _location; - // Location get location => _location; getWeather() async { + late num longitude; + late num latitude; + if (kIsWeb || Platform.isMacOS) { + longitude = 116.46; + latitude = 39.92; + } else { + longitude = _location!['longitude']; + latitude = _location!['latitude']; + } + Response response = await Dio().get( - 'https://api.caiyunapp.com/v2.5/${AppConfig.caiYunAPI}/${_location!['longitude']},${_location!['latitude']}/realtime.json', + 'https://api.caiyunapp.com/v2.5/${AppConfig.caiYunAPI}/$longitude,$latitude/realtime.json', ); LoggerData.addData(response); _weatherModel = RealTimeWeatherModel.fromJson(response.data); diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index b6455839..6d8fb6e4 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -32,6 +32,7 @@ class UserProvider extends ChangeNotifier { } logout() { + JPush().deleteAlias(); final appProvider = Provider.of(Get.context!, listen: false); appProvider.setCurrentHouse(null); _isLogin = false; @@ -47,7 +48,9 @@ class UserProvider extends ChangeNotifier { Future updateProfile() async { _userInfoModel = await SignFunc.getUserInfo(); - await JPush().setAlias(_userInfoModel!.id.toString()); + if (_userInfoModel != null) { + await JPush().setAlias(_userInfoModel!.id.toString()); + } notifyListeners(); }