Flutter 起步问题汇总

https://book.flutterchina.club/chapter1/dart.html

https://flutterchina.club/widgets-intro/

https://www.cnblogs.com/zhangrunhao/p/9970656.html
https://www.jianshu.com/p/eb782589be82

文章目录

  • 0.当运行flutter doctor报错
  • 1.当运行flutter run是报错Exception: idevice_id returned an error: 可以执行下边命令
  • 2.configure: error: Package requirements (libusbmuxd >= 1.1.0) were not met:
  • 3.热更新问题
    • 3-1 混合开发热更新
  • 4.打开指定iOS 模拟器
  • 5.混合开发准备
    • 5.1 podfile 编写
    • 5.2 项目适配
    • 5.3 原生和flutter相互传值
    • 报错记录

0.当运行flutter doctor报错

0.问题:[!] Xcode - develop for iOS and macOS (Xcode 11.3.1)
✗ CocoaPods installed but not working.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to
invoke it.
This can usually be fixed by re-installing CocoaPods. For more info, see
https://github.com/flutter/flutter/issues/14293.
To re-install CocoaPods, run:
sudo gem install cocoapods
解答:当执行 sudo gem install cocoapods 无效是 或者提示没有权限的时候 执行

sudo gem install -n /usr/local/bin cocoapods

1.问题: ✗ Android license status unknown.
解答:打开“Android studio”,点“Configure”选择“SDK Manager ” -> android sdk -> sdk tools 然后把右下角的 hiden obsolete package 前边的对号点掉 然后上边的列表就多出了一个 Android sdk tools obsolete 然后点击前边的勾选 然后下载就行了 终端执行 flutter doctor --android-licenses 一直y下去

1.当运行flutter run是报错Exception: idevice_id returned an error: 可以执行下边命令

brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller

Flutter 起步问题汇总_第1张图片

2.configure: error: Package requirements (libusbmuxd >= 1.1.0) were not met:

作为一个同时开发Android和iOS的人,我本地AndroidStudio和Xcode都安装了最新版。解压完zip包并且配置完环境变量之后运行flutter docker会提示安装brew install --HEAD libimobiledevice,直接运行这句命令会抛出以下异常:
configure: error: Package requirements (libusbmuxd >= 1.1.0) were not met:
Requested ‘libusbmuxd >= 1.1.0’ but version of libusbmuxd is 1.0.10
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables libusbmuxd_CFLAGS
and libusbmuxd_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
READ THIS: https://docs.brew.sh/Troubleshooting

这时候需要运行brew unlink usbmuxd & brew install --HEAD usbmuxd而不是libusbmuxd。
另外建议不用先按照flutter docker返回的提示安装,可以接着往下看,后面的文档写明了如何安装所有组件。

3.热更新问题

在编辑完成后保存对应页面就会更新

3-1 混合开发热更新

1.flutter attach
2.as编辑器右上角手机标志
更新内容后command + s

4.打开指定iOS 模拟器

查看模拟器列表

 xcrun simctl list

开模拟器

open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/ 打

加载指定模拟器

xcrun simctl boot C86A559A-1F50–40D1–8D84–954EDFBBCE18 

as连接不上iOS模拟器

sudo xcode-select --switch/Applications/Xcode.app/Contents/Developer

5.混合开发准备

5.1 podfile 编写

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
inhibit_all_warnings!
use_frameworks!

flutter_application_path = '\(path)'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target '**' do

install_all_flutter_pods(flutter_application_path)

end

5.2 项目适配

1.flutter工程不支持bitcode,所以需要在xcode中设置Build Settings->Build Options->Enable Bitcode为NO
2.每一个Xcode target都需要绑定flutter,调用install_all_flutter_pods(flutter_application_path)
3.任何时候,如果你修改了flutter工程中some/path/my_flutter/pubspec.yaml中的三方依赖,在flutter工程所在目录,都需要执行flutter packages get来更新从podhelper.rb脚本中读取的plugins列表,然后在app所在目录执行 pod install

5.3 原生和flutter相互传值

swift

        let flutter: FlutterViewController = FlutterViewController.init()
        let flutterPara:FlutterMethodChannel = FlutterMethodChannel(name: "com.fullter_hulitest.navtiveCallBack",binaryMessenger: flutter.binaryMessenger)
        flutterPara.setMethodCallHandler { (call, result) in
            print(call.method)
            print(call.arguments as Any)
            if call.method == "getParaFromNative" {
                result("原生接收到请求值的方法")
            }
        }

flutter

  String _navtiveCallBackValue = "原生传值";

  //交互通道
  static const communticateChannel = MethodChannel('com.fullter_hulitest.navtiveCallBack');

  //异步执行调用原生方法,保证页面不卡顿,trycatch保证方法实现
  Future<Void> _communicateNativeFunc(flutterPara) async {
    debugPrint("flutter 开始调用原生方法");
    try {
      //原生方法名为callNativeMethond,flutterPara为flutter调用原生方法传入的参数,await等待方法执行
      final result = await communticateChannel.invokeMethod('funcFromFlutterMethod',flutterPara);
      _navtiveCallBackValue = result;
    } on Exception catch(e) {//抛出异常
      print("flutter 调用原生方法失败");
    }
  }

  //异步执行从原生获取值
  Future<Null> _getParaFromNative() async {
    String platString;
    try{
      platString = await communticateChannel.invokeMethod('getParaFromNative');
    } on PlatformException catch(e){
      platString = e.message;
    }
    setState(() {
      _navtiveCallBackValue = platString;
    });
  }

报错记录

'_InternalLinkedHashMap' is not a subtype of type 'Map'

-> new Map.from(params)

热更新Error -32601 received from application: Method not found

-> flutter pub cache repair
flutter clean

MissingPluginException(No implementation found for method * on channel *)

-> 有可能是你原生和flutter的channel名字没有对应 / 或者是可以 flutter pub cache repair, flutter clean

你可能感兴趣的:(Flutter,Flutter)