Introducing Flutter into an existing project (iOS+Flutter)

iOS programming development is really getting more and more volume now, and it seems that relying solely on native development will not survive this year. The emergence of more and more cross-platform solutions allows us native engineers to draw fresh blood while catching up with the progress of the project. Flutter is a popular cross-platform (in fact, I think it is not impossible to call it a full platform) solution. However, it is not completely feasible to use Flutter for development. Is it possible that the old project is directly overturned and refactored? (Some people may secretly rejoice, and finally don’t have to sort out the complicated logic accumulated over the years.) But this is too laborious. Today, we will explore a solution to directly access Flutter on the original project.
First of all, we must have a development environment for flutter. I won’t go into too much description of this. There are many online tutorials. No matter which one you use, as long as flutter doctoryou don’t see the ‘x’ after running the command in the terminal at the end It proves that your environment is configured properly. If there is an 'x', then go to Du Niang step by step, just Google to find the answer. Then, we first create a new project with xcode (this is just an example), and then put an empty folder on the desktop, and then drag the project you just created into the empty folder you created.
Then open the terminal, execute cd 刚才文件夹的路径(从桌面直接拖到终端亦可), and press Enter. Then execute flutter create --template module 文件名(这里你想怎么写怎么写).
Then we need to do some processing on the native project, here we use cocoapods. The method of generating Podfile will not be described too much. Then we need to add the following code
Screenshot 2022-07-10 19.04.15.png

flutter_application_path = '../flutter_hybrid_project'

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

install_all_flutter_pods(flutter_application_path)

flutter_hybrid_project is the name of your flutter component. I have seen articles written ../../flutter_hybrid_projecton If you report an error at that time, you can also try it. Anyway, just make sure the path is correct. Then execute pod installthis, even if the simple integration is completed.

Guess you like

Origin juejin.im/post/7118700869071142925