Skip to content

Stateless Widget

In React, a function component is a function that receives props and returns JSX. Flutter’s equivalent is a StatelessWidget: a class with a single build() method that receives a BuildContext and returns a Widget. The rendering model is identical — both describe what the UI should look like given some input, and the framework re-runs the description when inputs change.

The main differences are syntax-deep: instead of a function you write a class, instead of return <div> you return Widget objects, and instead of JSX angle-brackets you nest constructor calls.

React
// React function component
function Greeting({ name }) {
return (
<div style={{ padding: 16 }}>
<h2>Hello, {name}!</h2>
<p>Welcome to Flutter for React Devs.</p>
</div>
);
}
// Usage
<Greeting name="Ava" />
Flutter
// Flutter StatelessWidget
class Greeting extends StatelessWidget {
final String name;
const Greeting({super.key, required this.name});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Hello, $name!',
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
const Text('Welcome to Flutter for React Devs.'),
],
),
);
}
}
// Usage
const Greeting(name: 'Ava')
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(
          child: ProfileCard(
            name: 'Ava Tavos',
            role: 'React → Flutter Developer',
          ),
        ),
      ),
    );
  }
}

class ProfileCard extends StatelessWidget {
  final String name;
  final String role;

  const ProfileCard({super.key, required this.name, required this.role});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.08),
            blurRadius: 12,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          const CircleAvatar(radius: 36, backgroundColor: Colors.blue,
              child: Icon(Icons.person, size: 36, color: Colors.white)),
          const SizedBox(height: 12),
          Text(name,
              style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
          const SizedBox(height: 4),
          Text(role,
              style: const TextStyle(fontSize: 14, color: Colors.grey)),
        ],
      ),
    );
  }
}
What is the Flutter equivalent of a React function component with no local state?
What does the `BuildContext context` parameter in `build()` provide?
Why should you mark widget constructors `const` in Flutter?
What is the purpose of `super.key` in a Flutter widget constructor?