Build UI before backend: fixtures and a staging gate

How to build UI before backend work lands: a repository on fixture JSON, one staging gate, a preview menu and simulator passes that find bugs early.

By

A new feature with a lot of screens does not have to wait for its API. On a fitness app I work on, I built the whole UI of a weekly goals feature first, on fixture data, inside the live codebase. To build UI before backend work lands without creating a throwaway prototype, I used four pieces: a repository with its final method signatures, fixture JSON fed through the real models, one gate that keeps it all out of production, and a preview menu to reach every state. This post covers each piece, what simulator passes found, and which part I can't vouch for yet.

Why this feature suited UI first work

The feature touches a lot of the app. There is a card in the community feed, a goals screen, setup, managing goals and rest weeks, goal details and history, cards and popups on the workout results screen, a Monday recap, sharing, and comeback screens for people who have lapsed. Most of those have several states, and the design board lays them all out.

That shape of feature suits UI first work. The hard questions are about flow: what shows when, what replaces what, and which popup wins when two want the same moment. You answer those by holding a phone, and you can do that without a server. In my view, screens that have been used are also a better brief for the backend than a list of endpoints.

Can you build UI before backend work starts?

Yes, as long as the UI talks to a repository with its final method signatures and the repository returns fixture data for now. The screens and view models should stay the same when the real API arrives, because only the method bodies change. Keep it all behind a gate so nothing unfinished reaches production.

Give the repository its final signatures now

The first commit was groundwork with no screens in it: models, fixtures, a provider and shared widgets. The repository has the final method signatures, so the backend later replaces only its bodies. Flutter's app architecture guide describes repositories as the source of truth for model data, turning raw data into domain models. That is the seam to use, because everything above it already expects a clean model and a Future.

The detail that makes this work is where the fixtures enter. They are snake_case JSON, the way an API sends it, and they go through the same fromJson as a real response would. Trimmed and renamed:

class GoalsRepository {
  GoalsRepository({DateTime Function()? clock})
      : _clock = clock ?? DateTime.now;

  final DateTime Function() _clock;

  Future<GoalsWeek> fetchWeek() async {
    final Map<String, dynamic> json = weekFixture(_clock());
    return GoalsWeek.fromJson(json);
  }
}

Returning ready-made Dart objects from the fixtures would be quicker and teach you less. Going through JSON exercises the parsing, the null handling and the field names from day one, and the fixtures double as a written proposal for the response shape.

Because the method is already async, a loading state is real from the start. My default is to give a fixture repository a slow mode and a failing mode as well, so loading and error states get looked at as often as the happy path.

Put everything behind one gate

Building inside the real app only works if production stays untouched. Everything sits behind one gate, which is on for staging and debug builds and off otherwise:

class FeatureGate {
  static bool get enabled {
    if (kDebugMode) return true;
    try {
      return AppFlavor.isStaging();
    } catch (_) {
      return false;
    }
  }
}

kDebugMode covers local runs, and the flavor check covers staging. If the flavor cannot be read, the gate answers no, so the failure case is the safe one.

Existing screens get one gated line each: the feed, the results screen, the streak popup, Settings, the Medals and Stats tabs and the profile card. Each of those hooks renders nothing outside staging and debug builds, or when it is hosted without the provider. One line per screen keeps the diff in shared code tiny, and it makes the feature easy to review and easy to remove.

The same held when I wired every trigger into the real flows: app open, the results screen, weigh-ins, posts, starting a plan and resubscribing. The Monday recap shows in place of the streak popup, and a goal-complete popup appears about 1.5 seconds into the results screen, only when nothing else is on top. Every one of those hooks does nothing outside staging and debug builds. The paywall got the same treatment: a new slide joins the carousel in those builds only, production keeps its shipped slides, and the test for the paywall dots now counts the slides of the build it runs in.

A runtime gate hides code, and the code still ships in the binary. That is fine for a feature in progress. If what you are hiding is a secret, you need it out of the build altogether, which I covered in keeping test keys out of production builds.

A preview menu beats a pile of test accounts

Real test accounts are a slow way to reach a state like a lapsed subscriber on a Monday. Fixtures make that one tap away if you build the tap.

So the feature has a staging preview menu. Long-press the card, or tap the tune icon on the goals screen, and it switches the fixture user and the fixture week, and opens any screen by its code on the design board. That last part gives the board and the app one vocabulary, so you can jump straight to a screen and compare it with the design. The menu is staging only, and users never see it.

Put the real rules on the fixture data

A fixture build can carry real product logic, and it should. These rules went in while the data was still fixtures:

  • Closing the invite hides it until Monday, and two dismissals stop it.
  • Closing the free teaser hides it for 14 days.
  • A warm-up week scales count goals to the days left.
  • Goals set during the week start from what's already done.

Rules like these read fine on a board and only start to feel right or wrong in use. My view is that settling them before the backend exists lets the API be designed around answers instead of guesses.

Simulator passes found what fixtures hid

Running the build on a simulator and walking every screen found bugs I would not have seen in a diff. The first pass turned up these:

  • The fixture week was out of step with the calendar. It now runs from the real Monday, so dates and the day dots match today.
  • Lists inside one shared header screen added a safe-area gap they should not have.
  • The share card's content was off centre.
  • The preview menu's detail entries needed unique keys.
  • A Settings row did not match the other settings cards.

The first one is worth a thought. Static fixtures with hard-coded dates go stale the day after you write them, so pass a clock in, as the repository above does.

A second pass found flow problems. Some ways of starting a week did not count what was already done since Monday, a button landed on the wrong tab, and a popup's button competed with Close. Those are the bugs people hit, and they are the kind I talk about in what end-to-end testing found in done tickets. If you want a repeatable version of these passes, see letting an AI agent test your Flutter app.

Then the scaffolding started coming out. The developer notes on screens, such as "Staging only" and the preview notes on the feed post and results, were removed so the build shows what a user will see. Put that on your list early. Those labels help while you build and embarrass you in a release.

Where I'd start

The one thing I can't report on yet is the swap itself. Replacing the repository's bodies with API calls is the design, and I will know how clean it is once that work has landed in the app. Until then, treat that step as a plan.

  1. Write the spec and the design states first. I explain why in spec-driven development.
  2. Write the repository with final signatures, and feed snake_case fixture JSON through the real models.
  3. Add one gate, and limit existing screens to one gated line each.
  4. Build a preview menu that switches user and week and opens any screen.
  5. Put real product rules in now, and pass an injectable clock to anything with dates.
  6. Walk every screen on a simulator, then remove the developer notes before release.

More of my Flutter work is on the projects page.

Want this kind of work on your product?

Get in touch