flutter - 颤振代码返回按下注销按钮时,在null上调用了方法'onDisconnect'
问题描述
下面的代码没有任何错误,但是按下注销按钮时无法注销。这是个人资料标签页代码。
这是代码
class ProfileTabPage extends StatefulWidget {
@override
_ProfileTabPageState createState() => _ProfileTabPageState();
}
class _ProfileTabPageState extends State<ProfileTabPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black87,
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(driversInformation.name,
style: TextStyle(fontSize: 65.0,
color: Colors.white,
fontWeight: FontWeight.bold),),
Text(title + "driver", style: TextStyle(fontSize: 20.0,
color: Colors.blueGrey[200], letterSpacing: 2.5,
fontWeight: FontWeight.bold),),
SizedBox(height: 20.0, width: 200, child: Divider(color: Colors.white,),),
SizedBox(height: 40.0,),
InfoCard(
text: driversInformation.phone,
icon: Icons.phone,
onPressed: () async {
print("this is phone.");
},
),
InfoCard(
text: driversInformation.email,
icon: Icons.email,
onPressed: () async {
print("this is email.");
},),
InfoCard(
text: driversInformation.car_color + " " + driversInformation.car_model + " " + driversInformation.car_number,
icon: Icons.car_repair,
onPressed: () async {
print("this is car info.");},),
GestureDetector(
onTap: (){
makeDriverOfflineNow();
FirebaseAuth.instance.signOut();
Navigator.pushNamedAndRemoveUntil(context, LoginScreen.idScreen, (route) => false);
},
child: Card(
color: Colors.red,
margin: EdgeInsets.symmetric(vertical: 20.0, horizontal: 110.0),
child: ListTile(
trailing: Icon(
Icons.follow_the_signs_outlined,
color: Colors.white,
),
title: Text(getTranslated(context,"Sign out"),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
),
),
),
],
),
),
);
}
void makeDriverOfflineNow(){
Geofire.removeLocation(currentfirebaseUser.uid);
rideRequestRef.onDisconnect();
rideRequestRef.remove();
rideRequestRef= null;
}
}
class InfoCard extends StatelessWidget
{
final String text;
final IconData icon;
Function onPressed;
InfoCard({this.text, this.icon, this.onPressed});
@override
Widget build(BuildContext context)
{
return GestureDetector(
onTap: onPressed,
child: Card(
color: Colors.white,
margin:EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
child: ListTile(
leading: Icon(
icon,
color: Colors.black87,
),
title: Text(text, style: TextStyle(color: Colors.black87,
fontSize: 16.0),),
),
),
);
}
}
this is the error message when pressing the signout button
======== 手势捕获的异常 ======================================= ========================= 处理手势时抛出以下 NoSuchMethodError:方法 'onDisconnect' 在 null 上被调用。接收方:null 尝试调用:onDisconnect()
抛出异常时,这是堆栈:#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5) #1 _ProfileTabPageState.makeDriverOfflineNow (package:driver_app/tabsPages/profileTabPage.dart:103:20 ) #2 _ProfileTabPageState.build。(package:driver_app/tabsPages/profileTabPage.dart:62:19) #3 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) #4 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures /tap.dart:607:11) ... 处理程序:“onTap”识别器:TapGestureRecognizer#70f77 debugOwner:GestureDetector 状态:可能赢得竞技场 finalPosition:偏移(187.8,513.1) finalLocalPosition:偏移(187.8,43.6)按钮:1 发送轻按
解决方案
推荐阅读
- java - 警报对话框消失
- python - 如何将一个字符串添加到另一个字符串并删除重叠部分?
- emacs - 如何运行在苹果酒中定义的 attr 映射中定义的测试?
- servicestack - 设置 UserAuth 删除级联而不添加对 ServiceModel 的依赖
- r - 使用 httr 的 POST 请求后内容类型无效
- java - Java 错误 - 没有保存 txt 文件的权限
- spring-boot - 在 Spring boot 中,是否有一个主注解来指定用于扫描组件、存储库、实体等的 basePackages
- php - Codeigniter 一对多关系数据展示
- laravel - Laravel 5.7 - 未发送验证电子邮件
- typescript - 如何在 React Native 中使用 TypeScript 模拟 React Navigation 的导航道具以进行单元测试?