我在切换屏幕时遇到问题。我不知道为什么Navigaotr.push命令不起作用。 除此之外,其他一切都可以正常工作,例如获取long,alt等。 除此之外,其他一切都可以正常工作,例如获取long,alt等。
实用程序类:
import 'package:flutter/material.dart';
import 'package:clima/screens/loading_screen.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: LoadingScreen(),
);
}
}
loading_Screen类:
import 'package:clima/screens/location_screen.dart';
import 'package:clima/services/networking.dart';
import 'package:flutter/material.dart';
import 'package:clima/services/location.dart';
import 'location_screen.dart';
const apiKey = '65c8f19a8cd46bb90e565af0a07cbd61';
class LoadingScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _LoadingScreenState();
}
}
class _LoadingScreenState extends State<LoadingScreen> {
double latitude;
double longitude;
@override
void iniState() {
super.initState();
getLocationData();
}
void getLocationData() async {
Location location = new Location();
await location.getCurrentLocation();
latitude = location.latitude;
longitude = location.longitude;
print('got here');
NetworkHelper networkHelper = NetworkHelper(
'https://samples.openweathermap.org/data/2.5/weather?lat=$latitude&$longitude=139&appid=$apiKey');
var weatherData = await networkHelper.getData();
Navigator.push(context, MaterialPageRoute(builder: (context) {
return LocationScreen();
}));
}
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
等待后更改打印位置后
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
Syncing files to device Android SDK built for x86...
D/EGL_emulation(11532): eglMakeCurrent: 0x9e4051e0: ver 2 0 (tinfo 0x9e403400)
info: Method doesn't override an inherited method. (override_on_non_overriding_method at [clima] lib\screens\loading_screen.dart:21)
info: The value of the local variable 'weatherData' isn't used. (unused_local_variable at [clima] lib\screens\loading_screen.dart:36)
info: Avoid empty statements. (empty_statements at [clima] lib\services\networking.dart:16)
info: Dead code. (dead_code at [clima] lib\services\networking.dart:16)
答案 0 :(得分:0)
收到错误的原因:
info:方法不会覆盖继承的方法。 (位于[clima] lib \ screens \ loading_screen.dart:21处的override_on_non_overriding_method)
是您创建了一个iniState()函数而不是initState()函数。