DEV Community

Cover image for DartBox Buddy: Running Flutter On-Device with a Local Gemma 4 AI Tutor for My Friend
Yadnesh Teli
Yadnesh Teli

Posted on Originally published at github.com

DartBox Buddy: Running Flutter On-Device with a Local Gemma 4 AI Tutor for My Friend

Hacktoberfest Weekend Challenge: Build for a Friend Submission 🀝

This is a submission for the Hacktoberfest Weekend Challenge: Build for a Friend

What I Built

A close friend of mine has wanted to learn Flutter for months. They had great app ideasβ€”little personal tools, habit logs, and clean interfacesβ€”but every time they sat down to start, reality hit them like a wall:

  1. The Setup Monster: First came downloading gigabytes of Android Studio, fighting Gradle daemon memory errors, configuring Java home variables, and waiting 10 minutes for an initial build. By the time the emulator booted, their creative momentum was completely gone.
  2. The Layout Maze: When they finally got code running, Flutter layouts proved deceptively tricky. Misunderstanding Row vs Column constraints, getting mysterious black-and-yellow striped overflow errors, and not knowing why an element vanished caused endless frustration.
  3. The Closed AI Trap: They tried pasting questions into cloud AI assistants, but web playgrounds only produced browser mockups, closed APIs demanded $20/month subscriptions, and personal daily habit ideas were being shipped to third-party corporate servers.

I realized what my friend needed wasn't another thick tutorial or a heavy laptop IDE. They needed a playful sandbox right in their pocket: an app where they could experiment with layouts on the subway, see changes instantly on a real touch screen, and have a patient, private mentor guiding them through every mistake.

DartBox Buddy is an on-device Flutter development studio and AI tutor that runs entirely on a mobile phone.

With DartBox Buddy, you can open any .dart file on your phone, tap Run, and watch it compile and mount as an interactive, live native Flutter widget in under 100 millisecondsβ€”with zero project setup, no laptop, no command-line tools, and no internet connection required.

Sitting beside you in the editor is an on-device AI mentor powered by Google Gemma 4 E2B running via LiteRT-LM. When a layout breaks or a compiler error occurs, Gemma analyzes the AST on your phone, explains the visual hierarchy in plain English, and auto-repairs code before mounting it on screen.

To solve my friend's layout struggles from day one, DartBox bundles 6 Progressive Layout Lessons:

  1. Centering & Text: Center, Container, padding, and decoration basics.
  2. Padding & Margins: Visualizing inner space vs outer margin boundaries.
  3. Row & Column Alignment: Mastering mainAxisAlignment and crossAxisAlignment.
  4. Stack & Positioned: Layering badges, floating tags, and overlapping cards.
  5. Scrollable Card Feed: Constructing lists with ListView, Card, and ListTile.
  6. Interactive State: Connecting taps to layout updates using StatefulWidget and setState.

Bundled lessons are read-only templates: editing any lesson automatically forks a custom copy into "My Scripts" so original reference lessons are never overwritten.

Demo

DartBox Buddy mobile studio running on a smartphone displaying dark-mode code editor with live Flutter widget preview and on-device Google Gemma 4 AI tutor recommendation pill

User Workflow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  DartBox Buddy Studio (On-Device Mobile Engine)        β”‚
β”‚                                                        β”‚
β”‚  [Code Editor] ──(Compiles in <100ms)──> [Live Widget] β”‚
β”‚        β–²                                       β”‚       β”‚
β”‚        β”‚                                       β–Ό       β”‚
β”‚   Auto-Repair <── [On-Device Gemma 4] <── [Errors/AST] β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

My Friend's Reaction

When I handed the phone to my friend and opened Lesson 3 (Row & Column Alignment), their first question was:

"Wait, where's the laptop? How is this running without Android Studio open?"

Within five minutes, they had changed the button padding, flipped the alignment from spaceEvenly to spaceBetween, and used the Gemma AI Tutor to ask why their text wasn't centered. For the first time, learning Flutter felt as fast and playful as playing a mobile game.

Code

# Clone and run locally
git clone https://github.com/yadneshteli/dartbox.git
cd dartbox
flutter pub get
flutter run
Enter fullscreen mode Exit fullscreen mode

How I Built It

DartBox Buddy connects two cutting-edge open technologies:

1. The On-Device Flutter Runtime (flutter_eval + dart_eval)

The host app runs standard Flutter compiled for Android. When the user edits code, DartBox passes the source string to the on-device Compiler with flutterEvalPlugin, producing platform-agnostic EVC bytecode in memory. The RuntimeWidget mounts the bytecode as a live widget tree with interactive touch gestures and state management (setState).

To ensure my friend wasn't restricted to basic containers, we bridged essential Flutter layout and styling primitives into the dynamic runtime:

  • Layout: Flexible, Wrap, SingleChildScrollView for scrollable, wrapping feeds.
  • Styling: BoxDecoration, BorderRadius, BoxShadow, and LinearGradient for sleek card designs.
  • Controls & Inputs: NavigationBar, Checkbox, Switch, and OutlineInputBorder for interactive components.

2. The On-Device AI Engine (flutter_gemma + LiteRT-LM)

Inference runs locally using the flutter_gemma package backed by LiteRT-LM. We deploy gemma-4-E2B-it.litertlm (an Apache-2.0 open-weight model from the LiteRT community).

flowchart TD
    A["Friend edits layout in Editor"] --> B["CompatChecker (Allowlist & Linter)"]
    B --> C["dart_eval Compiler"]
    C -->|Success in <100ms| D["Live Interactive Widget"]
    C -->|Compile Error| E["On-Device Error Console"]

    E --> F["Gemma 4 E2B Tutor (On-Device via LiteRT)"]
    F -->|System Prompts + Widget Hierarchy| G["Explain Error / Layout Hint"]
    G --> H["Self-Healing Repair Loop"]
    H -->|Repaired Code| C

3. Mobile Ergonomics & Developer Experience

Writing code on a touch keyboard requires deliberate tooling:

  • One-Tap Symbol Bar: Instant access to {, }, (, ), ;, :, =>, quotes, and brackets without toggling keyboard layers.
  • Undo & Redo: Directly integrated UndoHistoryController on the mobile toolbar.
  • Debounced Auto-Save & Safe Navigation: Code automatically saves after 1.5s of inactivity and via PopScope on back navigation.
  • Error-to-Line Navigation: Tapping any compiler error in the on-device console automatically jumps the cursor to the exact error line.
  • Script Management: Local duplicate, rename, delete with confirmation, and clipboard code paste/import.

4. Benchmarks & Verification

Tested on a OnePlus 13R (Qualcomm Snapdragon 8 Gen 3, 16 GB RAM):

  • Bytecode Compilation Time: 85 ms (average for 150-line layout scripts)
  • Warm Recompile Time: < 15 ms (using in-memory AST cache)
  • Automated Test Suite: 16 passed tests (100% pass rate across compiler units, all 6 bundled layout lessons, bridge widgets, and the multi-turn Gemma auto-repair loop)
  • Analyzer Health: 0 errors, 0 warnings with flutter analyze
  • Packaging: Standalone debug APK verified and built cleanly in 68s.

Why Does Open Innovation Matter?

This project was built to prove why open-source AI is transformative for learning and mobile development:

  • 100% Offline Independence: Learning shouldn't stop when you lose Wi-Fi. By packaging Google's open-weight Gemma 4 E2B model (.litertlm) directly onto the device, the tutor runs in airplane mode, on trains, or in remote spots with zero network latency.
  • Complete Data Sovereignty & Privacy: The friend's personal thoughts, draft widgets, and habit data never leave the phone. There is no tracking, no logging, and no telemetry sent to a remote API.
  • Zero Ongoing Costs: Cloud LLMs impose steep per-token pricing or monthly subscriptions. Open-weight models democratize accessβ€”once installed, millions of tokens of guidance cost exactly $0.00.
  • Deterministic Closed-Loop Compilation: Unlike generic cloud chatbots that hallucinate outdated syntax, DartBox pairs Gemma with an on-device compiler (dart_eval / flutter_eval). When Gemma suggests or generates a layout, DartBox compiles it in memory. If a syntax mismatch is detected, it feeds the error back to Gemma for an instant self-healing repair turn before the user even sees it.

My Agent Session

We saved the AI agent session transcript from our architectural build and test verification using DevRelay:

Building DartBox Buddy with On-Device Gemma 4
You

Build DartBox Buddy: an on-device Flutter runner and local Google Gemma 4 AI tutor for my friend learning Flutter layouts without laptop setup.

Agent

Designing 100% offline architecture: local bytecode compilation via flutter_eval, on-device Gemma 4 E2B inference via LiteRT-LM, debounced auto-save, and self-healing auto-repair loop.

The agent session covers designing the 100% offline runtime architecture, extending flutter_eval with layout bridges, implementing the 3-turn Gemma auto-repair loop, and passing all 16 automated tests.

Prize Categories

Featured Category: Best Use of Gemma ($200)

DartBox Buddy enters the Best Use of Gemma category. The project features Google's open-weight Gemma 4 E2B model (gemma-4-E2B-it.litertlm, Apache-2.0) running natively on-device via LiteRT-LM.

Gemma serves as an on-device tutor and autonomous code repair engine:

  1. Visual Hierarchy Explanation: Deconstructs Flutter widget trees and explains layout rules in plain English without cloud latency.
  2. Self-Healing Auto-Repair: Automatically catches compiler errors, feeds AST error diagnostics into an on-device 3-turn repair loop, and outputs corrected code that compiles and mounts live.
  3. Local Privacy: Ensures all user code, draft widgets, and learning conversations remain 100% local on the device.

Thank you to DEV, Google, and the Hacktoberfest organizers for this challenge!

Top comments (0)