All posts
flutternextjs

One Mindset, Two Platforms: Flutter and Next.js

Sharing patterns, state, and API contracts between a mobile app and a web app.

Muhamad Choirul Adam 2 min readPhoto: Unsplash

A Flutter app and a Next.js app can't share code directly. They can share something more useful: the same contracts, the same mental model of state, and the same boundaries. That's what keeps two codebases from drifting into two products.

Start from the API contract

The backend is the one thing both apps truly share. Treat its schema as the source of truth and generate clients from it instead of hand-writing types twice.

Rendering diagram…
types.ts
// Generated for the web app from the OpenAPI spec.
export type Order = {
  id: string;
  status: "pending" | "paid" | "shipped";
  totalCents: number;
};
order.dart
// The same contract on the Flutter side.
enum OrderStatus { pending, paid, shipped }
 
class Order {
  const Order({required this.id, required this.status, required this.totalCents});
 
  final String id;
  final OrderStatus status;
  final int totalCents;
}

When the schema changes, both clients fail to compile in the same places. That's a feature.

Same shape of state

Different libraries, same idea: separate server state (data you fetch and cache) from UI state (what's open, selected, or typed).

ConcernNext.jsFlutter
Server stateServer ComponentsRepository + cache
UI stateuseState, URLStatefulWidget, Riverpod
MutationsServer ActionsRepository methods

Keep business rules out of the UI

Formatting a price, deciding if an order can be cancelled, validating an address: these belong in one place, ideally the backend. The apps display decisions; they don't re-make them in two languages.

Shared design language, not shared widgets

Trying to share UI components across platforms usually costs more than it saves. Share the tokens instead: color, spacing, type scale, and motion timing. Each app then builds native-feeling components from the same ingredients.

The payoff

Two apps, one product. Features ship on both platforms without a parallel debate about what the behavior should be, because that was decided once, in the contract.