Question #34EasyFlutter BasicsImportant

Difference between flutter and react native?

#flutter#native

Answer

Overview

Flutter and React Native are the two most popular cross-platform mobile frameworks. Both allow building iOS and Android apps from a single codebase, but they differ significantly in architecture, performance, and development experience.


Quick Comparison

FeatureFlutterReact Native
Created ByGoogle (2017)Meta/Facebook (2015)
LanguageDartJavaScript/TypeScript
ArchitectureDirect native renderingJavaScript bridge
UI RenderingSkia (custom engine)Native components
PerformanceNear-native (~60fps)Good (~60fps with optimization)
Hot Reload✅ Yes (~1s)✅ Yes (~1-2s)
Learning CurveModerateEasy (if know JS)
CommunityGrowing rapidlyMature, larger
Code Reuse~90-95%~80-90%
App SizeLarger (~4-8 MB)Smaller (~2-4 MB)
PopularityRising fastMore established

Architecture Comparison

Flutter Architecture

text
┌────────────────────────────────────┐
│  Flutter Framework (Dart)          │
│  ┌──────────┐  ┌──────────┐        │
│  │ Widgets  │  │ Material │        │
│  └──────────┘  └──────────┘        │
│  ┌──────────────────────────┐      │
│  │  Flutter Engine (C++)    │      │
│  │  ┌────────┐  ┌────────┐  │      │
│  │  │ Skia   │  │ Dart   │  │      │
│  │  └────────┘  └────────┘  │      │
│  └──────────────────────────┘      │
└────────────────────────────────────┘
         ↓ (Direct rendering)
┌────────────────────────────────────┐
│  Platform (Android/iOS)            │
└────────────────────────────────────┘

Key Points:

  • Renders UI using Skia graphics engine
  • Direct communication with platform
  • No JavaScript bridge
  • Compiles to native code (ARM/x86)

React Native Architecture

text
┌────────────────────────────────────┐
│  React Native (JavaScript)         │
│  ┌──────────┐  ┌──────────┐        │
│  │ React    │  │ JSX      │        │
│  └──────────┘  └──────────┘        │
└────────────────────────────────────┘
         ↓ (JavaScript Bridge)
┌────────────────────────────────────┐
│  Native Modules (Java/Kotlin,      │
│  Objective-C/Swift)                │
│  ┌──────────┐  ┌──────────┐        │
│  │ Android  │  │ iOS      │        │
│  │ Native   │  │ Native   │        │
│  │ UI       │  │ UI       │        │
│  └──────────┘  └──────────┘        │
└────────────────────────────────────┘

Key Points:

  • Uses JavaScript bridge to communicate
  • Renders using native components
  • Requires native modules for platform features
  • Bridge can be a bottleneck

Performance

Flutter Performance

Advantages:

  • ✅ Direct native rendering (no bridge)
  • ✅ Consistent 60fps (120fps capable)
  • ✅ AOT compilation (Ahead-of-Time)
  • ✅ Fast startup time
  • ✅ Smooth animations

Code Example:

dart
// Flutter - Compiled to native
AnimationController(
  duration: Duration(milliseconds: 300),
  vsync: this,
)..forward();

React Native Performance

Advantages:

  • ✅ Uses native UI components
  • ✅ Good performance for most apps
  • ⚠️ Bridge overhead for complex interactions
  • ⚠️ Requires optimization for 60fps
  • ⚠️ Slower animations compared to Flutter

Code Example:

javascript
// React Native - Uses bridge
Animated.timing(fadeAnim, {
  toValue: 1,
  duration: 300,
  useNativeDriver: true,  // Required for performance
}).start();

UI/UX Comparison

Flutter UI

Custom rendering with Material and Cupertino widgets.

dart
// Material Design
Scaffold(
  appBar: AppBar(title: Text('Flutter')),
  body: Column(
    children: [
      ElevatedButton(
        onPressed: () {},
        child: Text('Click Me'),
      ),
      Text('Hello World'),
    ],
  ),
  floatingActionButton: FloatingActionButton(
    onPressed: () {},
    child: Icon(Icons.add),
  ),
)

Characteristics:

  • Custom-rendered widgets (looks same on all platforms)
  • Rich widget library (Material + Cupertino)
  • Highly customizable
  • Pixel-perfect design possible
  • Not native-looking by default

React Native UI

Uses native components under the hood.

javascript
// React Native
import { View, Text, Button, TouchableOpacity } from 'react-native';

<View>
  <Button title="Click Me" onPress={() => {}} />
  <Text>Hello World</Text>
  <TouchableOpacity onPress={() => {}}>
    <Text>Press Me</Text>
  </TouchableOpacity>
</View>

Characteristics:

  • Native components (Button, Text, etc.)
  • Looks native on each platform
  • Limited styling compared to Flutter
  • Platform-specific quirks

Development Experience

Flutter

Language: Dart

dart
// Type-safe, compiled
class User {
  final String name;
  final int age;
  
  User({required this.name, required this.age});
}

final user = User(name: 'John', age: 30);
print(user.name);

Pros:

  • ✅ Strong typing
  • ✅ Fast hot reload (~1s)
  • ✅ Rich widget library
  • ✅ Excellent DevTools
  • ✅ Single codebase for UI

Cons:

  • ❌ Smaller community than JS
  • ❌ Dart is less popular
  • ❌ Fewer packages than npm

React Native

Language: JavaScript/TypeScript

javascript
// JavaScript/TypeScript
interface User {
  name: string;
  age: number;
}

const user: User = { name: 'John', age: 30 };
console.log(user.name);

Pros:

  • ✅ Huge JavaScript ecosystem
  • ✅ Familiar to web developers
  • ✅ Large community
  • ✅ More third-party libraries
  • ✅ Expo for easier development

Cons:

  • ❌ JavaScript bridge overhead
  • ❌ Platform-specific bugs
  • ❌ Requires native code for some features

Code Comparison

Counter App Example

Flutter:

dart
class Counter extends StatefulWidget {
  
  _CounterState createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  int count = 0;
  
  
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Counter')),
      body: Center(
        child: Text('Count: $count', style: TextStyle(fontSize: 32)),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => setState(() => count++),
        child: Icon(Icons.add),
      ),
    );
  }
}

React Native:

javascript
import React, { useState } from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';

const Counter = () => {
  const [count, setCount] = useState(0);
  
  return (
    <View style={styles.container}>
      <Text style={styles.text}>Count: {count}</Text>
      <TouchableOpacity 
        style={styles.button}
        onPress={() => setCount(count + 1)}
      >
        <Text>+</Text>
      </TouchableOpacity>
    </View>
  );
};

const styles = StyleSheet.create({
  container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  text: { fontSize: 32 },
  button: { padding: 20, backgroundColor: 'blue' },
});

Ecosystem & Community

AspectFlutterReact Native
Packages40,000+ (pub.dev)800,000+ (npm)
GitHub Stars165K+118K+
Contributors1,400+2,900+
Companies UsingGoogle, Alibaba, BMW, eBayFacebook, Instagram, Discord, Shopify
Job MarketGrowingMore established
Learning ResourcesGrowing rapidlyAbundant

When to Choose Flutter

✅ Choose Flutter If:

  • You want consistent UI across platforms
  • You need high performance animations
  • You want faster development (rich widget library)
  • You prefer strong typing and Dart
  • You're building a new app from scratch
  • You want pixel-perfect custom designs

Best For:

  • Apps with custom UI/UX
  • High-performance apps
  • MVP development
  • Startups

When to Choose React Native

✅ Choose React Native If:

  • You have JavaScript/TypeScript expertise
  • You want native-looking UI components
  • You need extensive third-party libraries
  • You have existing web codebase (code sharing)
  • You want to hire easily (JS developers abundant)
  • You're building simple to moderate complexity apps

Best For:

  • Web developers transitioning to mobile
  • Apps needing extensive native modules
  • Large JavaScript teams
  • Companies already using React

App Size Comparison

Flutter:

text
Release APK: ~4-8 MB (hello world)
With dependencies: 15-30 MB

React Native:

text
Release APK: ~2-4 MB (hello world)
With dependencies: 10-20 MB

Why Flutter is larger:

  • Includes Skia engine
  • Dart runtime
  • Framework code

Popular Apps Built With Each

Flutter Apps

  • Google Ads
  • Alibaba
  • BMW
  • eBay Motors
  • Reflectly
  • Hamilton Musical

React Native Apps

  • Facebook
  • Instagram
  • Discord
  • Shopify
  • Tesla
  • Bloomberg

Best Practices Comparison

Flutter:

dart
// ✅ Use const constructors
const Text('Hello')

// ✅ Extract widgets for reusability
class CustomButton extends StatelessWidget {
  
  Widget build(BuildContext context) {
    return ElevatedButton(...);
  }
}

React Native:

javascript
// ✅ Use memo for optimization
const MyComponent = React.memo(() => {
  return <View>...</View>;
});

// ✅ Use useCallback
const handlePress = useCallback(() => {
  // ...
}, [dependencies]);

Resources