我收到了这个错误
无法使用静态访问访问实例成员
我找不到位置,因为我在另一个类中有与错误相关的数据.我刚开始学dart ,还在学习,所以这一切对我来说都没有多大意义.
我收到此错误的代码为.getLocationWeather()
:
void getLocationData() async {
var weatherData = await WeatherModel.getLocationWeather();
Navigator.push(context, MaterialPageRoute(builder: (context) {
return LocationScreen(
locationWeather: weatherData,
);
下面是getLlocationWeather()
所在的类的代码.
import 'location.dart';
import 'networking.dart';
const apiKey = 'e72ca729af228beabd5d20e3b7749713';
const openWeatherMapURL = 'https://api.openweathermap.org/data/2.5/weather';
class WeatherModel {
Future<dynamic> getCityWeather(String cityName) async {
NetworkHelper networkHelper = NetworkHelper(
'$openWeatherMapURL?q=$cityName&appid=$apiKey&units=metric');
var weatherData = await networkHelper.getData();
return weatherData;
}
Future<dynamic> getLocationWeather() async {
Location location = Location();
await location.getCurrentLocation();
NetworkHelper networkHelper = NetworkHelper(
'$openWeatherMapURL?lat=${location.latitude}&lon=${location.longitude}&appid=$apiKey&units=metric');
var weatherData = await networkHelper.getData();
return weatherData;
}