适用于iOS的Flutter风格在运行时给出SharedPreference错误 [英] Flutter flavor for iOS gives SharedPreference error on run
问题描述
尝试使用构建模式运行iOS风格时遇到问题
Issue faced while trying to run flavors for iOS using Build Schemas
/Labs/Workspace/Flutter/camp-flutter/ios/Runner/GeneratedPluginRegistrant.m:6:9: fatal error:
'shared_preferences/SharedPreferencesPlugin.h' file not found
#import <shared_preferences/SharedPreferencesPlugin.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Flutter Doctor输出
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.5 18F132, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.4)
[✓] VS Code (version 1.36.1)
[✓] Connected device (1 available)
• No issues found!
其他信息
我们正在使用用于iOS构建的风格和方案,并使用以下命令来运行应用程序
Additional Information
We are using flavors and schemes for iOS build and using below command to run applications
flutter run --flavor abcd --target lib/main/abcd_main.dart
推荐答案
我认为,可以通过两种方式解决此问题.他们在下面.
In my opinion, this problem can be resolved in two ways. They are below.
我检查了一个项目,发现SharedPreferencesPlugin.h具有以下代码.
I checked in one of my project and found SharedPreferencesPlugin.h has following code.
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Flutter/Flutter.h>
@interface FLTSharedPreferencesPlugin : NSObject <FlutterPlugin>
@end
此文件位于位置: (mysiyaram是项目名称)
This file is present at location : (mysiyaram is the project name)
现在,您可能有两种方法可以解决此问题. 方案A:您使用上面的代码手动创建文件.它不包含任何特定于版本的信息.
Now you might have two ways to solve this issue. Plan A : You create the file manually with the code above. It doesn't contain any version specific info any way.
计划B:创建另一个虚拟项目,在其中添加共享的首选项.并将文件(或文件夹结构)从虚拟项目复制到您的项目.
Plan B : Create another dummy project, add shared preferences in there. And copy the file (or folder structure) from the dummy project to your project.
注意:由于我不知道结构解决方案,因此请采用此选项作为解决方法.
这篇关于适用于iOS的Flutter风格在运行时给出SharedPreference错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!