我试图在注销按钮的 onPressed 方法之后调用 _signOut 函数。但是它没有(识别函数或让我调用它)但是我可以调用widget.Onsignedout,回调它的父级,一切都按预期工作。除了我在 auth.signout 上注销用户并回电只是为了更新表单。如何从状态类访问 _signOut()?谢谢你
import 'package:flutter/material.dart';
import 'package:login_demo/auth.dart';
import 'package:login_demo/root_page.dart';
class HomePage extends StatefulWidget {
HomePage({this.auth, this.onSignedOut});
final BaseAuth auth;
//To call a function of a parent, you can use the callback pattern
final VoidCallback onSignedOut;
void _signOut() async {
try {
Text('Signing Out here');
await auth.signOut();
onSignedOut;
} catch (e) {
print(e);
}
}
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Homepage'),
actions: <Widget>[
FlatButton(
child: Text(
'Logout',
style: TextStyle(fontSize: 17.0, color: Colors.white)
),
onPressed: widget.onSignedOut,
),
],
),
body: Container(
child: Center(
child: Text(
'Welcome',
style: TextStyle(fontSize: 32.0),
),
),
),
);
}
}