我正在开发一个 Flutter 应用程序,其中使用了 shared_preferences: ^2.0.13 包。
Flutter 版本:2.10.1(最新)
gradle版本:6.7
Android Gradle 插件版本:4.1.3
kotlin 版本:1.6.10
flutterEmbedding 2(在 android 菜单中)
MissingPluginException(在 channel plugins.flutter.io/shared_preferences上找不到方法getAll的实现)。
在后台接收 FCM 消息时。
main.dart
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print('Got a message onBackgroundMessageHandler_');
print("Handling a background message: ${message.messageId}");
print('Shared pref process starts');
SharedPreferences sf = await SharedPreferences.getInstance();
sf.setString("key", "Value");
print('${sf.getKeys()}');
print('Shared pref process ends');
}
void main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(const MyApp());
}
MainActivity.kt
class MainActivity: FlutterActivity() {
}
最佳答案
请引用我的post
您需要注册share_preference才能进行后台访问
io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
关于android - 在后台获取 FCM 时 MissingPluginException(在 channel plugins.flutter.io/shared_preferences 上找不到方法 getAll 的实现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71124545/