美文网首页
flutter iOS 混编步骤

flutter iOS 混编步骤

作者: mapg | 来源:发表于2020-08-05 13:11 被阅读0次

    1.创建公共文件

    image.png

    2.创建iOS项目

    image.png

    3.创建flutter模块

    image.png
    cd  xx/Hybrid Proj/
    flutter create -t module flutter_module
    

    iOS引入pod管理

    cd xx/iOS HiHouse/
    pod init
    

    在profile文件中添加依赖,两行需要放在Podfile头部执行:

    flutter_application_path = "../flutter_module"
    eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
    

    在各个target里面添加:

        #flutter
        install_all_flutter_pods(flutter_application_path)
    

    安装依赖:

    pod install
    

    注意:禁用Bitcode:

    编写代码

    原生代码跳转到flutter界面:

            //该参数用于告诉Dart代码显示哪个Flutter视图。
            vc.setInitialRoute("myApp")
            self.present(vc, animated: true) {
                //
            }
            return;
    

    flutter模块里面:

    import 'dart:ui';
    import 'package:flutter/material.dart';
    
    void main() => runApp(_widgetForRoute(window.defaultRouteName));
    
    Widget _widgetForRoute(String route) {
      switch (route) {
        case 'myApp':
          return MyApp();
        default:
          return MaterialApp(
            home: Center(
              child: Text('没找到'),
            ),
          );
      }
    }
    
    
    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
                ...
          ),
          home: MyHomePage(title: 'test'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      .....
    }
    
    

    相关文章

      网友评论

          本文标题:flutter iOS 混编步骤

          本文链接:https://www.haomeiwen.com/subject/tpbrrktx.html