Skip to main content

storifyme_flutter 3.0.0-beta.1 copy "storifyme_flutter: ^3.0.0-beta.1" to clipboard
storifyme_flutter: ^3.0.0-beta.1 copied to clipboard

StorifyMe Flutter SDK is the official SDK from StorifyMe GmbH that helps you add stories to your Flutter app.

example/lib/main.dart

import 'dart:async';

import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:storifyme_flutter/storifyme_flutter.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const StorifyMeFlutterDemoApp());
}

class StorifyMeFlutterDemoApp extends StatefulWidget {
  const StorifyMeFlutterDemoApp({super.key});

  @override
  State<StorifyMeFlutterDemoApp> createState() =>
      _StorifyMeFlutterDemoAppState();
}

class _StorifyMeFlutterDemoAppState extends State<StorifyMeFlutterDemoApp>
    with
        NativeEventListener,
        StorifyMeAdEventListener,
        StorifyMeInteractionListener,
        StorifyMeCommerceListener {
  final _storifyMeFlutterPlugin = StorifyMeFlutterPlugin();
  bool _initialized = false;

  @override
  void initState() {
    super.initState();
    _storifyMeFlutterPlugin.setEventListener(this);
    _storifyMeFlutterPlugin.setAdEventListener(this);
    _storifyMeFlutterPlugin.setInteractionListener(this);
    _storifyMeFlutterPlugin.setCommerceListener(this);
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    try {
      await _storifyMeFlutterPlugin.initPlugin({
        Params.API_KEY_ID: 'API_KEY',
        Params.ACCOUNT_ID_KEY: 'ACCOUNT_ID',
        Params.ENVIRONMENT_KEY: 'EU',
      });
      if (mounted) setState(() => _initialized = true);
    } on PlatformException {
      debugPrint('Failed to get platform version.');
    }
  }

  @override
  Widget build(BuildContext context) {
    // Your widgets that you want to show
    final widgetIds = [1, 2];
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('StorifyMe Flutter Demo 1')),
        body: !_initialized
            ? const Center(child: CircularProgressIndicator())
            : SingleChildScrollView(
                child: Column(
                  children: widgetIds
                      .map(
                        (widgetId) => StorifyMeWidget(
                          widgetId: widgetId,
                          // Estimated height for each widget
                          // Default value is 180.0
                          // Please enter the most approximate value to achieve best performance
                          estimatedHeight: 180.0,
                        ),
                      )
                      .toList(),
                ),
              ),
      ),
    );
  }

  @override
  void onFailed(StorifyMeError error) {
    debugPrint('onFailed: ${error.type}: ${error.message}');
  }

  @override
  void onLoad(int widgetId, List<StorifyMeExperience> experiences) {
    debugPrint('onLoad: widgetId - $widgetId, count: ${experiences.length}');
  }

  @override
  void onOpened(StorifyMeExperience? experience, int index) {
    debugPrint('onOpened: $experience at $index');
  }

  @override
  void onFinished(StorifyMeExperience? experience, int index) {
    debugPrint('onFinished: $experience at $index');
  }

  @override
  void onClosed(StorifyMeExperience? experience) {
    debugPrint('onClosed: $experience');
  }

  @override
  void onShared(StorifyMeExperience? experience) {
    debugPrint('onShared: $experience');
  }

  @override
  Future<StorifyMeOpenAction> onExperienceWillOpen(
    StorifyMeExperience? experience,
  ) {
    debugPrint('onExperienceWillOpen: $experience');
    return Future.value(StorifyMeOpenAction.open);
  }

  @override
  void onAdDisplayed(StorifyMeExperience? experience, int index) {
    debugPrint('onAdDisplayed: $experience at $index');
  }

  @override
  void onInteractionAction(StorifyMeInteractionAction action) {
    debugPrint('onInteractionAction: ${action.type}');
  }

  @override
  void onInteractionEvent(StorifyMeInteractionEvent event) {
    debugPrint('onInteractionEvent: ${event.action}');
  }

  @override
  void onCartItemAdded(String productId, int quantity) {
    debugPrint('onCartItemAdded: $productId x $quantity');
  }

  @override
  void onCheckout(StorifyMeCart cart) {
    debugPrint('onCheckout: ${cart.total} ${cart.currency}');
  }
}
8
likes
160
points
2.51k
downloads

Documentation

API reference

Publisher

verified publisherstorifyme.com

Weekly Downloads

StorifyMe Flutter SDK is the official SDK from StorifyMe GmbH that helps you add stories to your Flutter app.

Homepage

License

Apache-2.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on storifyme_flutter

Packages that implement storifyme_flutter