其他分享
首页 > 其他分享> > Android Flutter笔记2

Android Flutter笔记2

作者:互联网

在native中add flutter fragment

方法1:

// Get a reference to the Activity's FragmentManager to add a new
    // FlutterFragment, or find an existing one.
    FragmentManager fragmentManager = getSupportFragmentManager();

    // Attempt to find an existing FlutterFragment, in case this is not the
    // first time that onCreate() was run.
    flutterFragment = (FlutterFragment) fragmentManager.findFragmentByTag(TAG_FLUTTER_FRAGMENT);
    // Create and attach a FlutterFragment if one does not exist.
    if (flutterFragment == null) {
      flutterFragment = FlutterFragment.createDefault();

      fragmentManager
          .beginTransaction()
          .add(
              R.id.fragment_container,
              flutterFragment,
              TAG_FLUTTER_FRAGMENT
          )
          .commit();
    }

方法2:

// With a new FlutterEngine.
    FlutterFragment flutterFragment = FlutterFragment.withNewEngine()
        .initialRoute("myInitialRoute/")
        .build();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, flutterFragment);
    fragmentTransaction.commit();

 

蒋帅Android 发布了36 篇原创文章 · 获赞 19 · 访问量 2万+ 私信 关注

标签:flutterFragment,fragment,fragmentManager,笔记,add,Android,fragmentTransaction,Flut
来源: https://blog.csdn.net/j18874964028sss/article/details/103946880