flutter - NosuchMethodError:在 null 上调用了方法“[]”。收件人:空
问题描述
当我在某些手机上安装我的应用程序时,我不断收到此错误,但它在我的设备上运行顺畅
NosuchMethodError:在 null 上调用了方法“[]”。收件人:空。尝试调用:
这是错误的屏幕截图
这是我的代码
double long;
Future<ReverseLocation> rLocation() async {
String request =
"http://**.***.**.**:****/traffic/location/reverse_geocode/?longitude=$long&latitude=$lat";
final response = await http.get(request);
print(request);
print(response.statusCode);
try{
return ReverseLocation.fromRawJson(response.body);
}
catch(e){
return ReverseLocation.fromRawJson(response.body);
}
这是我的观点
@override
_SearchLocationState createState() => _SearchLocationState();
}
class _SearchLocationState extends State<SearchLocation> {
Future<ReverseLocation> locationtwo;
@override
void initState() {
super.initState();
locationtwo = rLocation();
}
Widget build(BuildContext context) {
return SafeArea(
child: Container(
height: double.infinity,
width: double.infinity,
child: Scaffold(
body: SafeArea(
child: FutureBuilder(
// initialData: [],
future: locationtwo,
builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.none) {
return NetworkModal();
} else if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(snapshot
.data.entity.addressComponents[0].longName),
],
));
} else if (snapshot.hasError) {
return Center(child: Text("Error ${snapshot.error.toString()}"));
}
else if(snapshot.data == null) {
return Center(child: Text("Null ${snapshot.error}"));
}
} {
return Center(child: Text("Trying to get Address"));
}
}),
),
),
),
);
}
}
解决方案
推荐阅读
- php - 为什么PHP函数in_array和strpos中haystack和needle的顺序不一致?
- perl - perl: 组合多个一维数组的多维数组
- c# - 从 Unity android 打开另一个应用程序
- jquery - 按下返回时按下同一 TR 中的按钮
- c# - 如何在 C# 中实现用户输入功能
- javascript - 修改错误后获取Fabric.js对象的高度和宽度
- java - RxJava CombineLatest 调试
- java - 通过 Angular 保存已创建的 PDF 或 CSV 文件(不导出)
- swift - 如何编写处理 do catch 的模板函数
- php - Slim php框架,多维修改key