Skip to content
VerificationWould you notice if your agent drifted in production?Explore the 5-stage harness›
Framework Architecture

Flutter UI & Reactive BLoCs

The Flutter client layer exposes a unified, type-safe API barrel through package:<app>_flutter/api.dart. Hand-written Flutter screens in client/lib/ consume pre-configured Serverpod clients, authentication gates, and generated reactive BLoCs without boilerplate networking code.

You never need to hunt through multiple generated folders. Every Flutter screen needs only one Aegil import:

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:helpdesk_flutter/api.dart';

What api.dart provides:

  • All protocol models and enums (Ticket, TicketStatus, TicketComment).
  • Pre-configured client: createAppClient() initializes connectivity and session persistence.
  • Authentication gate: SignInGate shows email sign-in whenever the user is logged out.
  • Generated BLoCs: <Entity>Bloc, events, and states for every model with an @autoQuery.

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:helpdesk_flutter/api.dart';
late final Client client;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
client = await createAppClient();
runApp(const HelpdeskApp());
}
class HelpdeskApp extends StatelessWidget {
const HelpdeskApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Helpdesk',
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue)),
home: SignInGate(
client: client,
child: BlocProvider(
create: (_) => TicketBloc(client: client)..add(const ListTicketsRequested()),
child: const TicketsScreen(),
),
),
);
}
}

For every model with an @autoQuery in your specs, Aegil generates a complete flutter_bloc implementation:

class TicketsScreen extends StatelessWidget {
const TicketsScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Support Tickets')),
body: BlocBuilder<TicketBloc, TicketState>(
builder: (context, state) {
if (state.status == TicketLoadStatus.loading && state.items.isEmpty) {
return const Center(child: CircularProgressIndicator());
}
if (state.status == TicketLoadStatus.failure && state.items.isEmpty) {
return Center(child: Text('Failed to load tickets: ${state.error}'));
}
if (state.items.isEmpty) {
return const Center(child: Text('No tickets found.'));
}
return ListView.builder(
itemCount: state.items.length,
itemBuilder: (context, index) {
final ticket = state.items[index];
return ListTile(
title: Text(ticket.title),
subtitle: Text('Status: ${ticket.status.name}'),
trailing: IconButton(
icon: const Icon(Icons.arrow_upward),
onPressed: () {
context.read<TicketBloc>().add(
EscalateTicketRequested(
ticketId: ticket.id,
assignedAgentId: 'agent-101',
),
);
},
),
);
},
);
},
),
);
}
}
  • Query events: List<Entity>Requested(...) dispatches queries with optional filtering parameters.
  • Mutation events: Create<Entity>Requested(...) or custom mutation events execute backend operations and update state.items.
  • Real-time stream updates: If @autoStream is declared in specs, the BLoC subscribes to incoming WebSocket messages and updates state.items without manual stream management.
  • State properties:
    • state.status: initial | loading | success | failure.
    • state.items: Normalized list of entities.
    • state.error: Error object (Object?) if an operation failed.

createAppClient() resolves the Serverpod backend URL in this order:

  1. --dart-define=SERVER_URL=https://api.example.com/ passed at build/run time.
  2. apiUrl in client/assets/config.json.
  3. http://localhost:8080/ (default for local desktop/web).

Mobile physical devices: When running on a physical phone on your local Wi-Fi, pass --dart-define=SERVER_URL=http://<your-computer-ip>:8080/ to allow your phone to reach your local Serverpod server.


What you see Why What to do
SocketException: Connection refused The Flutter client cannot reach the Serverpod server at localhost:8080. Ensure aegil run is running, or pass --dart-define=SERVER_URL for physical devices.
Red screen: SignInGate unauthenticated An operation requires login, but the user is signed out. Wrap your protected screens with SignInGate(client: client, child: ...).
ERR_UI_BOUNDARY_VIOLATION Flutter code imported internal .aegil/client/lib/src/... files directly. Import strictly from package:<app>_flutter/api.dart.