admesh_flutter_ui_sdk 0.1.0 copy "admesh_flutter_ui_sdk: ^0.1.0" to clipboard
admesh_flutter_ui_sdk: ^0.1.0 copied to clipboard

Flutter SDK for AdMesh recommendations with native widgets, tracking, and theming.

example/lib/main.dart

import 'package:admesh_flutter_ui_sdk/admesh_flutter_ui_sdk.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    final sessionId = AdMeshSdk.createSession();
    return MaterialApp(
      title: 'AdMesh Flutter UI SDK',
      theme: ThemeData(
        useMaterial3: true,
        extensions: <ThemeExtension<dynamic>>[
          AdMeshThemeData.light(),
        ],
      ),
      home: AdMeshProvider(
        config: const AdMeshSdkConfig(apiKey: 'replace-me'),
        sessionId: sessionId,
        theme: AdMeshThemeData.light(),
        child: ExampleHome(sessionId: sessionId),
      ),
    );
  }
}

class ExampleHome extends StatefulWidget {
  const ExampleHome({super.key, required this.sessionId});

  final String sessionId;

  @override
  State<ExampleHome> createState() => _ExampleHomeState();
}

class _ExampleHomeState extends State<ExampleHome> {
  String _bridgePrompt = '';
  String _executedQuery = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('AdMesh Flutter UI SDK')),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          TextField(
            readOnly: true,
            decoration: InputDecoration(
              labelText: 'Bridge prompt target',
              hintText: _bridgePrompt.isEmpty ? 'Tap bridge CTA in sample below' : _bridgePrompt,
              border: const OutlineInputBorder(),
            ),
          ),
          const SizedBox(height: 12),
          Text(
            _executedQuery.isEmpty
                ? 'Sponsored follow-up not executed yet'
                : 'Executed follow-up: $_executedQuery',
          ),
          const SizedBox(height: 24),
          const Text('Static ecommerce sample'),
          const SizedBox(height: 12),
          AdMeshRecommendations(
            recommendation: _sampleProductCard(widget.sessionId),
            onOpenLink: (url) async => debugPrint('Open link: $url'),
          ),
          const SizedBox(height: 24),
          const Text('Bridge + follow-up sample'),
          const SizedBox(height: 12),
          AdMeshRecommendations(
            recommendation: _sampleBridge(widget.sessionId),
            onPasteToInput: (value) {
              setState(() {
                _bridgePrompt = value;
              });
            },
            onExecuteQuery: (query) async {
              setState(() {
                _executedQuery = query;
              });
            },
            onOpenLink: (url) async => debugPrint('Open link: $url'),
          ),
          const SizedBox(height: 24),
          const Text('Manual fetch sample'),
          const SizedBox(height: 12),
          ElevatedButton(
            onPressed: () async {
              final sdk = AdMeshScope.of(context).sdk;
              final options = ShowRecommendationsOptions(
                query: 'best CRM for small business',
                sessionId: widget.sessionId,
                messageId: AdMeshSdk.createMessageId(widget.sessionId),
              );
              try {
                final recommendation = await sdk.showRecommendations(options);
                if (!context.mounted) return;
                showDialog<void>(
                  context: context,
                  builder: (context) => AlertDialog(
                    title: const Text('Fetched recommendation'),
                    content: Text(recommendation.title),
                  ),
                );
              } catch (error) {
                if (!context.mounted) return;
                showDialog<void>(
                  context: context,
                  builder: (context) => AlertDialog(
                    title: const Text('Fetch failed'),
                    content: Text('$error'),
                  ),
                );
              }
            },
            child: const Text('Fetch from /aip/context'),
          ),
        ],
      ),
    );
  }
}

AdMeshRecommendation _sampleProductCard(String sessionId) {
  return AipContextResponse.fromJson({
    'recommendation_id': 'rec_product',
    'session_id': sessionId,
    'agent_id': 'agent_1',
    'product_id': 'bundle_1',
    'brand_id': 'brand_1',
    'title': 'Acme CRM',
    'url': 'https://example.com/crm',
    'admesh_link': 'https://example.com/admesh',
    'exposure_url': 'https://example.com/exposure',
    'click_url': 'https://example.com/click',
    'contextual_relevance_score': 0.92,
    'engagement_status': 'new',
    'payout_model': 'CPC',
    'payout_amount_usd': 1.4,
    'cpx_value': 0,
    'cpc_value': 1.4,
    'cpa_value': 0,
    'creative_input': {
      'brand_name': 'Acme',
      'product_name': 'Acme CRM',
      'short_description': 'CRM and pipeline automation for small teams.',
      'long_description': 'Track leads, manage pipeline, and automate outreach.',
      'value_props': ['Pipeline automation', 'Lead routing'],
      'cta_url': 'https://example.com/crm',
      'assets': {'logo_url': 'https://example.com/logo.png'},
      'preferred_format': 'product_card'
    },
    'products': [
      {
        'product_id': 'starter',
        'product_name': 'Starter',
        'product_description': 'Basic CRM for early stage teams',
        'product_price': 29,
        'product_cta_label': 'Start free',
        'product_link': 'https://example.com/starter'
      },
      {
        'product_id': 'growth',
        'product_name': 'Growth',
        'product_description': 'Sales automation and forecasting',
        'product_price': 79,
        'product_cta_label': 'See plans',
        'product_link': 'https://example.com/growth'
      }
    ],
    'timestamps': {'generated_at': DateTime.now().toUtc().toIso8601String()},
    'created_at': DateTime.now().toUtc().toIso8601String(),
  });
}

AdMeshRecommendation _sampleBridge(String sessionId) {
  return AipContextResponse.fromJson({
    'recommendation_id': 'rec_bridge',
    'session_id': sessionId,
    'agent_id': 'agent_2',
    'product_id': 'product_2',
    'brand_id': 'brand_2',
    'title': 'Stripe for AI apps',
    'url': 'https://example.com/stripe',
    'admesh_link': 'https://example.com/admesh-bridge',
    'exposure_url': 'https://example.com/exposure-bridge',
    'click_url': 'https://example.com/click-bridge',
    'followup_query': 'How would Stripe compare to Lemon Squeezy for this stack?',
    'followup_engagement_url': 'https://example.com/followup-engagement',
    'followup_exposure_url': 'https://example.com/followup-exposure',
    'contextual_relevance_score': 0.95,
    'engagement_status': 'new',
    'payout_model': 'CPX',
    'payout_amount_usd': 2.2,
    'cpx_value': 2.2,
    'cpc_value': 0,
    'cpa_value': 0,
    'creative_input': {
      'brand_name': 'Stripe',
      'product_name': 'Stripe Billing',
      'short_description': 'Payments infrastructure for subscription apps.',
      'long_description': 'Launch billing, invoicing, and tax support for your product.',
      'value_props': ['Subscriptions', 'Tax support'],
      'cta_url': 'https://example.com/stripe',
      'assets': {'logo_url': 'https://example.com/stripe-logo.png'},
      'preferred_format': 'bridge',
      'bridge_headline': 'Want to add payments?',
      'bridge_description': 'Use Stripe Billing to launch subscriptions quickly.',
      'bridge_prompt': 'Add Stripe Billing with checkout and webhook support.',
      'cta_label': 'Paste setup prompt'
    },
    'timestamps': {'generated_at': DateTime.now().toUtc().toIso8601String()},
    'created_at': DateTime.now().toUtc().toIso8601String(),
  });
}
0
likes
150
points
43
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

Flutter SDK for AdMesh recommendations with native widgets, tracking, and theming.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, http, provider, visibility_detector

More

Packages that depend on admesh_flutter_ui_sdk