我正在开发一个Flutter应用程序,它使用aad_oauth包来实现Microsoft多重身份验证。但是,我在登录过程中遇到 MissingPluginException 错误。错误信息如下:
I/flutter (18709): Login failed: MissingPluginException(No implementation found for method delete on channel plugins.it_nomads.com/flutter_secure_storage)
这是我配置和启动登录过程的代码的相关部分:
class _LoginScreenState extends State<LoginScreen> {
final TextEditingController _emailController = TextEditingController();
late final AadOAuth oauth;
@override
void initState() {
super.initState();
final config = Config(
tenant: '2f5964b2-44fc-420d-8974-xxxx',
clientId: 'ed4c80e3-847b-4b0a-85a9-xxxxx',
scope: 'openid profile email',
redirectUri: 'msauth://com.xxxxxx/auth',
navigatorKey: LoginScreen.navigatorKey,
);
oauth = AadOAuth(config);
}
void _login() async {
try {
await oauth.login();
final accessToken = await oauth.getAccessToken();
if (accessToken != null) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => SuccessScreen()),
);
}
} catch (e) {
print('Login failed: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(height: 20),
Text(
'Sign in',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
SizedBox(height: 20),
TextField(
controller: _emailController,
decoration: InputDecoration(
labelText: 'Email, phone, or Skype',
border: OutlineInputBorder(),
filled: true,
fillColor: Colors.white,
),
keyboardType: TextInputType.emailAddress,
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _login,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Text(
'Next',
style: TextStyle(fontSize: 16),
),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue[700],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
),
SizedBox(height: 16),
TextButton(
onPressed: () {},
child: Text('Can\'t access your account?'),
),
],
),
),
);
}
@override
void dispose() {
_emailController.dispose();
super.dispose();
}
}
在 Android 清单中添加
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="msauth"
android:host="com.xx.xx" />
</intent-filter>
如何解决此 MissingPluginException?有没有其他人遇到过 aad_oauth 包的这个问题,或者我在设置中可能缺少一个步骤?任何见解或解决方案将不胜感激。
这个包
aad_oauth
有一个依赖名称flutter_secure_storage
并且
flutter_secure_storage
有一个本机方法名称 delete
所以我猜当你使用
oauth.login()
或 oauth.getAccessToken()
时,将调用本机方法 delete
,但不知何故在本机代码中,此方法不存在,这就是你收到错误的原因
MissingPluginException(在通道plugins.it_nomads.com/flutter_secure_storage上找不到方法删除的实现)
那么我们来搜索关键字看看你的项目是否下载依赖成功
如果您的项目没有它们,您可以尝试清理 flutter 或 pub 缓存,然后重新同步依赖项。