我正在使用我正在处理的基本应用程序模板上设置AccountKit。我使用的例子是AccountKit Plugin for Flutter提供的例子。
现在,这个工作到现在为止。
我所做的是,我在登录屏幕上使用OnTap,以便将用户带到插件的示例实现(我的文件上的account-kit.dart)。
onTap: () {
Navigator.of(context).push(
// MaterialPageRoute(builder: (context) => MessagesScreen()),
MaterialPageRoute(builder: (context) => AccountKit()),
);
},
然后,在account-kit.dart页面内,生成一个小部件 - 其中包含一个必须单击的按钮才能执行Future<void> login() async{...}
方法。
这就产生了问题,我的用户现在看到从登录到颤动之间的不必要的屏幕。就像这样:
这有点笨拙,所以我期待完全摆脱第2步和第4步。
所以这意味着我将点击login
上的LoginScreen()
按钮。然后被带到accountkit.dart的login()方法,这将执行,它将直接带我到MessagesScreen()
。
但是,如果我没有在Widget build(BuildContext context) {}
上返回任何内容并且只在其中执行login()
,那么我将面临错误。
那么,在这个屏幕上摆脱这些不必要元素的最佳方法是什么?
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Center(
child: RaisedButton(
padding: EdgeInsets.all(0.0),
color: _state == 2 ? Colors.green : Colors.blue,
elevation: 2.0,
splashColor: Colors.blueGrey,
child: buildButtonChild(),
onPressed: _isInitialized ? this.login : null,
),
),
),
);
}
Widget buildButtonChild() {
if (_state == 0) {
return Text(
'Login',
style: TextStyle(color: Colors.white, fontSize: 16.0),
);
} else if (_state == 1) {
return SizedBox(
height: 24.0,
width: 24.0,
child: CircularProgressIndicator(
value: null,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
));
} else {
return Icon(Icons.check, color: Colors.white);
}
}
您可以在THIS GIT GIST找到相关三页的完整代码。
下图显示了正在加载的不必要的屏幕。我只想要那些没有出现(第二和第三个屏幕带有额外的登录按钮)。
这是启动accountkit的功能
Future<void> initAccountkit() async {
print('Init account kit called');
bool initialized = false;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
final theme = AccountKitTheme(
headerBackgroundColor: Colors.green,
buttonBackgroundColor: Colors.yellow,
buttonBorderColor: Colors.yellow,
buttonTextColor: Colors.black87);
await akt.configure(Config()
..facebookNotificationsEnabled = true
..receiveSMS = true
..readPhoneStateEnabled = true
..theme = theme
);
initialized = true;
} on PlatformException {
print('Failed to initialize account kit');
}
现在在你的按下登录按钮调用此功能
Future loginNow() async {
//here you can call the function and handle the output(return value) as result
initAccountkit().then((result) {
// print(result);
//call login function of accountKit below
});
}
Future<void> login() async {
if (_state == 1) {
return;
}
setState(() {
_state = 1;
});
final result = await akt.logInWithPhone();
if (result.status == LoginStatus.cancelledByUser) {
print('Login cancelled by user');
setState(() {
_state = 0;
});
} else if (result.status == LoginStatus.error) {
print('Login error');
setState(() {
_state = 0;
});
} else {
print('Login success');
setState(() {
_state = 2;
});
}
}