@dryv/flutter-appv0.1.0
A Flutter app from views — feature screens, go_router routes, Riverpod state, a connectivity gate, calls through flutter-api-bridge.
dryv pack add @dryv/flutter-app{#- The bound flutter-api-bridge feature client that serves an operation. -#}
{%- macro client_for(link) -%}
{%- for dependency in file.dependency_groups.operation_client %}{% if dependency.target.id == link.id %}{{ dependency.symbol }}{% endif %}{% endfor -%}
{%- endmacro -%}
{#- "yes" when a collect part of this view submits to the operation. -#}
{%- macro fed_by_form(link) -%}
{%- for part in view.parts %}{% if part.kind == 'collect' and part.collect.target.port is not none and part.collect.target.port.operation.id == link.id %}yes{% endif %}{% endfor -%}
{%- endmacro -%}
{#- The form field kind of a schema field. -#}
{%- macro field_kind(value) -%}
{%- if value is none -%}text
{%- elif value.is.boolean -%}boolean
{%- elif value.is.number -%}number
{%- elif value.is.enum -%}choice
{%- elif value.is.date or value.is.date_time -%}date
{%- else -%}text
{%- endif -%}
{%- endmacro -%}
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:{{ application.name.snake }}/api.dart';
import '../../widgets/dryv_form.dart';
// State and calls of the {{ view.name.title }} screen. Generated by Dryv; regenerated when the view changes.
{%- for part in view.parts %}
{%- if part.kind == 'present' and part.present.source.port is not none %}
{%- set operation = part.present.source.port.operation %}
/// {{ part.description or part.name.title }}
{%- if fed_by_form(operation) %}
/// Set when the form submits to {{ operation.name.title }}.
final {{ view.name.camel }}{{ part.name.pascal }}Provider = StateProvider.autoDispose<ApiResult<Object?>?>((ref) => null);
{%- else %}
/// Loads when the screen opens.
final {{ view.name.camel }}{{ part.name.pascal }}Provider = FutureProvider.autoDispose<ApiResult<Object?>>(
(ref) => {{ client_for(operation) }}({{ application.name.pascal }}.connection).{{ operation.name.camel }}(),
);
{%- endif %}
{%- elif part.kind == 'collect' and part.collect.target.port is not none %}
{%- set port = part.collect.target.port %}
{%- set operation = port.operation %}
/// Fields of the {{ part.name.title }} form.
const {{ view.name.camel }}{{ part.name.pascal }}Fields = <DryvField>[
{%- if port.value.schema is not none %}
{%- for field in port.value.schema.fields %}
DryvField(
name: '{{ field.name.raw }}',
label: '{{ field.name.title }}',
kind: DryvFieldKind.{{ field_kind(field.value) }},
required: {{ 'false' if field.optional else 'true' }},
{%- if field.value is not none and field.value.is.enum %}
options: <String>[{% for item in field.value.property.enum.values %}{{ item.value_json }}{% if not loop.last %}, {% endif %}{% endfor %}],
{%- endif %}
),
{%- endfor %}
{%- endif %}
];
/// {{ part.description or part.name.title }}: submits to {{ operation.name.title }} and shows its result.
Future<ApiResult<Object?>> submit{{ view.name.pascal }}{{ part.name.pascal }}(WidgetRef ref, Map<String, Object?> values) async {
final result = await {{ client_for(operation) }}({{ application.name.pascal }}.connection).{{ operation.name.camel }}(
{% if port.field is none %}input{% else %}{{ port.field.camel }}{% endif %}: {{ port.value.generated.schema_types.symbol }}.fromJson(values),
);
{%- for other in view.parts %}{% if other.kind == 'present' and other.present.source.port is not none and other.present.source.port.operation.id == operation.id %}
ref.read({{ view.name.camel }}{{ other.name.pascal }}Provider.notifier).state = result;
{%- endif %}{% endfor %}
return result;
}
{%- elif part.kind == 'invoke' and part.invoke.operation is not none %}
/// {{ part.description or part.name.title }}
Future<ApiResult<Object?>> invoke{{ view.name.pascal }}{{ part.name.pascal }}() =>
{{ client_for(part.invoke.operation) }}({{ application.name.pascal }}.connection).{{ part.invoke.operation.name.camel }}();
{%- endif %}
{%- endfor %}