DEV Community

Cover image for Step-by-step Guide to Merge React Native and Flutter for Single Android App
Lucy
Lucy

Posted on

Step-by-step Guide to Merge React Native and Flutter for Single Android App

Let’s think practical, what if you could mix React Native’s lightning-fast coding with Flutter’s exceptional visuals to make one outstanding Android app? Sounds exciting, right? Let’s chat about how this combination will help you to level up your application with others.

So, first of all, you have a question: why combine them both in one app? Because it has the ability to deliver excellent apps that are super fast to build. Definitely you can face some challenges but blending their strengths enhances performance and flexibility for sure. Stick with me here for practical tips and a clear, step-by-step guide to make it happen!

Why Combine React Native and Flutter in One Android App?

Personally, I have tried this combination and trust me it is worth it. React Native is like your go-to for speedy coding because of its JavaScript roots and huge library of tools. Flutter, on the other hand, can bring your secret weapon for creating smooth animations and polishing a native look. So when you combine both of them together for making a single app, you need a slick dashboard but also complex logic or API calls.

If there is any existing react native app you have, in that case you can upgrade it with Flutter’s awesome UI components. The benefit you gain is to save time by reusing code and wow users with a snappy and powerful app.

Step-by-Step Guide to Combining React Native and Flutter

Alright, let’s break down how to merge React Native and Flutter step by step in a way that’s easy to follow. I’ll keep it simple and walk you through the process of integrating these two to build an app that uses React Native for logic and Flutter for a clean UI.

Step 1: Set Up Your Environment

Install React Native: If you haven’t already, install Node.js and the React Native CLI. Run this in your terminal:

npm install -g react-native-cli

Enter fullscreen mode Exit fullscreen mode

Install Flutter: Download the Flutter SDK from flutter.dev and unzip it. Add it to your system’s PATH. Check it’s working with:

flutter doctor

Enter fullscreen mode Exit fullscreen mode

You’ll need an IDE like VS Code or Android Studio, plus emulators or devices for testing.

Step 2: Create Your React Native Project

To handle the core logic, start with React Native app.

Run:

npx react-native init MyApp
Enter fullscreen mode Exit fullscreen mode

This sets up a basic React Native app. Test it with:

npx react-native run-android

Enter fullscreen mode Exit fullscreen mode

or run-ios for iOS. You should see a simple app on your emulator.

Step 3: Create a Flutter Module

Now, let’s add Flutter for the UI components.

In your terminal, navigate to your project’s root folder and create a Flutter module:

flutter create --template=module my_flutter_module

Enter fullscreen mode Exit fullscreen mode

This creates a my_flutter_module folder with a Flutter setup. It’s like a mini Flutter app that you’ll embed in React Native.

Step 4: Link Flutter to React Native

After successfully creating a Flutter Module, you need to connect them to make Flutter work inside your React Native app.

For Android:
Add the Flutter module as a dependency in your React Native settings.gradle file. Open MyApp/android/settings.gradle and add:

include ':my_flutter_module'
project(':my_flutter_module').projectDir = new File('../my_flutter_module/android')

Update app/build.gradle to include Flutter:
dependencies {
  implementation project(':my_flutter_module')
}
Enter fullscreen mode Exit fullscreen mode

Step 5: Add a Flutter Screen

Now, let’s create a Flutter screen to use in your app, like a dashboard.

In my_flutter_module/lib/main.dart, replace the default code with a simple UI:

import 'package:flutter/material.dart';

void main() {
  runApp(MyFlutterScreen());
}

class MyFlutterScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Flutter Dashboard')),
        body: Center(
          child: Text(
            'Welcome to my cool dashboard!',
            style: TextStyle(fontSize: 24),
          ),
        ),
      ),
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

Build the Flutter module for both platforms:

cd my_flutter_module
flutter build aar
flutter build ios-framework
Enter fullscreen mode Exit fullscreen mode

Step 6: Display Flutter in React Native

Now, let’s show the Flutter screen inside your React Native app.
Install the react-native-flutter package to bridge the two:

npm install react-native-flutter
Enter fullscreen mode Exit fullscreen mode

In your React Native app (e.g., App.js), add a button to launch the Flutter screen:

import React from 'react';
import { Button, View } from 'react-native';
import { FlutterView } from 'react-native-flutter';

const App = () => {
  const [showFlutter, setShowFlutter] = React.useState(false);

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      {showFlutter ? (
        <FlutterView
          style={{ flex: 1, width: '100%' }}
          moduleName="my_flutter_module"
        />
      ) : (
        <Button
          title="Open Flutter Dashboard"
          onPress={() => setShowFlutter(true)}
        />
      )}
    </View>
  );
};
Enter fullscreen mode Exit fullscreen mode

export default App;

This code adds a button that, when pressed, shows your Flutter dashboard.

Step 7: Communicate Between React Native and Flutter

Sometimes, you’ll want React Native and Flutter to talk to each other, like passing data.
Use platform channels in Flutter. In my_flutter_module/lib/main.dart, add:

import 'package:flutter/services.dart';

class MyFlutterScreen extends StatelessWidget {
  static const platform = MethodChannel('com.example/data');

  @override
  Widget build(BuildContext context) {
    platform.setMethodCallHandler((call) async {
      if (call.method == 'sendData') {
        return 'Received: ${call.arguments}';
      }
      return null;
    });
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Flutter Dashboard')),
        body: Center(child: Text('Welcome to my cool dashboard!')),
      ),
    );
  }
}

Enter fullscreen mode Exit fullscreen mode

In React Native, call this channel from App.js:

import { NativeModules } from 'react-native';

const { FlutterModule } = NativeModules;

const sendDataToFlutter = async (data) => {
  try {
    const result = await FlutterModule.invokeMethod('sendData', data);
    console.log(result); // Logs: Received: <your data>
  } catch (e) {
    console.error(e);
  }
};

// Add a button to send data
<Button title="Send Data to Flutter" onPress={() => sendDataToFlutter('Hello Flutter!')} />
Enter fullscreen mode Exit fullscreen mode

Step 8: Test and Debug

ReRun your app (npx react-native run-android or run-ios).
Test the button to open the Flutter screen and ensure data passes correctly.
If something’s off, check the console logs or use flutter doctor to troubleshoot Flutter issues.

Step 9: Optimize and Deploy

Optimize: Keep Flutter components lightweight to avoid slowing down your app. Use React Native for heavy logic and Flutter for UI-heavy screens.

Deploy: Build your app for release as you would a normal React Native app to ensure the Flutter module is included in the bundle.

Conclusion:

So, that’s it, merging React Native and Flutter is not just some difficult experiment. It is a smart move if you want the best of both worlds: React Native’s speed and flexibility with Flutter’s stunning visuals and smooth UI.

Here is the real takeaway: Blending React Native’s speed with Flutter’s UI power is a real-world solution to build Android apps that are fast, flexible and visually stunning. Yes, it takes a little setup and some technical juggling but the result? 100% worth it.

And hey, don’t get stressed about the complexity. Follow this step by step guide. Still if you have questions or want to explore this approach for your app, let’s connect. Whether you need help or plan to hire Android app developers for expert integration, I'll be happy to help you get started.

Top comments (0)