Build your first FlutterJS app in 5 minutes!
flutterjs init my-app
cd my-appThis creates a new FlutterJS project with the following structure:
my-app/
├── lib/
│ └── main.dart # Your Flutter/Dart code
├── build/
│ └── flutterjs/ # Generated JavaScript (auto-created)
├── pubspec.yaml # Dart dependencies
└── README.md
The lib/main.dart file contains a simple counter app by default:
// lib/main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FlutterJS Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'FlutterJS Counter'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}Navigate to your project directory and run:
cd examples/counter # or your project directory
# Run the full pipeline: Dart → IR → JavaScript → Dev Server
dart run ../../bin/flutterjs.dart run --to-js --serveThis will:
- Analyze your Dart code
- Generate intermediate representation (IR)
- Convert IR to JavaScript
- Start a development server
- Open your browser automatically
You should see:
✅ Dev Server running at http://localhost:3000
📁 Project root: C:\...\my-app\build\flutterjs
🌐 Opening browser...
Open your browser to http://localhost:3000
Inspect the page source — you'll see real HTML elements, not canvas!
<div class="flutter-scaffold">
<header class="flutter-appbar">
<h1>FlutterJS Counter</h1>
</header>
<main>
<div class="flutter-center">
<div class="flutter-column">
<span class="flutter-text">You have pushed the button this many times:</span>
<span class="flutter-text">0</span>
</div>
</div>
</main>
<button class="flutter-fab">
<svg>...</svg>
</button>
</div>Try editing lib/main.dart:
Change the title:
home: MyHomePage(title: 'My Awesome Counter App'),Save the file and the Dart CLI will detect changes. Run the development server again to see your updates!
When ready to deploy:
flutterjs buildThis creates optimized, production-ready files in the dist/ directory:
dist/
├── index.html
├── app.min.js # Minified JavaScript
└── styles.min.css # Minified CSS
Deploy these files to any static hosting service:
- Netlify
- Vercel
- GitHub Pages
- AWS S3
- Any web server
- Learn more widgets: Check out the Widget Catalog
- Understand state management: See State Management Guide
- Add routing: Build multi-page apps with Routing & Navigation
- Explore examples: See Examples for more patterns
If port 3000 is already in use:
dart run bin/flutterjs.dart run --to-js --serve --server-port 4000Manually navigate to http://localhost:3000
Make sure you have:
- Dart SDK installed
- Run
dart pub getin your project directory - Valid Dart syntax in
lib/main.dart