Skip to main content

mebabl_stories 1.0.0 copy "mebabl_stories: ^1.0.0" to clipboard
mebabl_stories: ^1.0.0 copied to clipboard

Typed Flutter SDK for Babilo ephemeral social stories.

mebabl_stories #

mebabl_stories is a typed Flutter SDK for creating, reading, viewing, reacting to, and deleting short-lived social stories in the Babilo Platform. It reuses an application's existing MebablCore instance and authenticated Application User session.

Stories support image and video media, captions, Followers and Public audiences, view tracking, reactions, viewer lists, and automatic expiration. The backend remains responsible for authentication, authorization, account privacy, audience visibility, blocking/muting rules, and media access checks.

Features #

  • Retrieve the signed-in user's stories feed in pages.
  • Retrieve a specific user's active story group.
  • Create a story from an existing MediaAsset ID.
  • Set the story audience to Followers or Public.
  • Mark a story as viewed.
  • Add or remove a story reaction.
  • Retrieve the viewers of an owned story.
  • Delete an owned story.
  • Parse API responses into typed Dart models: SocialStory, SocialStoryGroup, and SocialStoryViewer.
  • Filter expired stories from parsed story groups.

The package does not provide a media picker, upload UI, story viewer UI, or video player. Use mebabl_media to upload image/video files, then pass the returned MediaAsset ID to createStory.

Requirements #

  • Flutter application using Dart SDK >=3.8.0 <4.0.0.
  • mebabl_core: ^1.2.0.
  • A configured Babilo application and API base URL.
  • A signed-in Application User for all Stories API operations.
  • The uploaded MediaAsset must belong to the current application, be available to the current user, and be ready for use by the backend.

Installation #

When the package is published to pub.dev:

dependencies:
  mebabl_core: ^1.2.0
  mebabl_stories: ^1.0.0

For a local SDK workspace, use a path dependency instead:

dependencies:
  mebabl_core: ^1.2.0
  mebabl_stories:
    path: ../mebabl_stories

Then run:

flutter pub get

Initialization #

Initialize MebablCore and the authentication package once in the host application. Create MebablStoriesService with the same Core instance; this package does not create another HTTP client or authentication flow.

import 'package:flutter/widgets.dart';
import 'package:mebabl_core/mebabl_core.dart';
import 'package:mebabl_auth/mebabl_auth.dart';
import 'package:mebabl_stories/mebabl_stories.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final core = await MebablCore.initialize();
  final auth = MebablAuthService(core: core);
  await auth.initialize();

  final stories = MebablStoriesService(core: core);

  runApp(MyApp(stories: stories));
}

The user must be signed in before calling Stories API methods. The service explicitly sends requests using MebablAuthMode.user.

Upload media and create a story #

mebabl_stories accepts an existing mediaAssetId; it does not upload files itself. Upload an image or video with mebabl_media, using Unlisted visibility for story media, and wait until media processing is complete before creating the story.

import 'dart:async';

import 'package:mebabl_media/mebabl_media.dart';
import 'package:mebabl_stories/mebabl_stories.dart';

final media = MebablMediaService(core: core);
final stories = MebablStoriesService(core: core);

final uploaded = await media.uploadFile(
  filePath: pickedFile.path!,
  visibility: MebablMediaVisibility.unlisted,
);

// Upload acceptance does not necessarily mean processing has finished.
var asset = await media.get(mediaId: uploaded.id);
for (var attempt = 0; attempt < 30 && !asset.isReady; attempt++) {
  await Future<void>.delayed(const Duration(seconds: 2));
  asset = await media.get(mediaId: uploaded.id);
}
if (!asset.isReady) {
  throw TimeoutException('Media processing did not finish in time.');
}

final story = await stories.createStory(
  mediaAssetId: asset.id,
  caption: 'A moment from today',
  audience: 'Followers',
);

print('Created story: ${story.id}');

The backend validates the media asset and its access independently. Do not make story media public just to make it display: use the media delivery flow and access rules configured for the application.

Read the stories feed #

final groups = await stories.getFeed(
  page: 1,
  pageSize: 20,
);

for (final group in groups) {
  print('${group.username}: ${group.stories.length} active stories');

  for (final story in group.stories) {
    print('${story.id} expires at ${story.expiresAtUtc}');
  }
}

getFeed returns a list of SocialStoryGroup. Groups without active stories are omitted by the SDK. Use getUserStories to retrieve a specific user's active stories:

final group = await stories.getUserStories(userId);
if (group != null) {
  for (final story in group.stories) {
    print(story.caption ?? '');
  }
}

Views and reactions #

Mark a story as viewed after it has been presented to the user:

await stories.markViewed(story.id);

Add a reaction:

await stories.react(story.id, type: 'Love');

Supported reaction values are Like, Love, Laugh, Wow, Sad, and Angry. Remove the current user's reaction:

await stories.removeReaction(story.id);

Viewers and deletion #

The owner can retrieve the viewers of their story in pages:

final viewers = await stories.getViewers(
  story.id,
  page: 1,
  pageSize: 30,
);

for (final viewer in viewers) {
  print(viewer.username);
}

Delete a story:

await stories.deleteStory(story.id);

The backend enforces ownership and authorization. A client-side check is not a replacement for server-side access control.

API coverage #

Base path: /api/sdk/stories. Every route below uses the authenticated Application User session.

SDK method HTTP method Route
getFeed GET /feed?page={page}&pageSize={pageSize}
getUserStories GET /users/{userId}
createStory POST /
markViewed POST /{storyId}/views
react POST /{storyId}/reactions
removeReaction DELETE /{storyId}/reactions
getViewers GET /{storyId}/viewers?page={page}&pageSize={pageSize}
deleteStory DELETE /{storyId}

Validation and limits #

The SDK validates story and media IDs as GUIDs, page numbers, page sizes, audience values, and reaction types before making requests. The maximum caption length enforced by the SDK is 300 characters, and the maximum page size is 100.

Story lifetime, media constraints, visibility, privacy, and authorization are enforced by the backend. The expiration timestamp returned by the API is exposed as SocialStory.expiresAtUtc; SocialStory.isExpired can be used for presentation logic. The server remains authoritative and may stop returning or serving expired stories regardless of client state.

Error handling #

HTTP errors are normalized by mebabl_core as MebablException:

try {
  await stories.createStory(
    mediaAssetId: asset.id,
    caption: 'Hello',
  );
} on MebablException catch (error) {
  if (error.isUnauthorized) {
    // The user session is missing or expired.
  } else if (error.isForbidden) {
    // The user is not allowed to perform this operation.
  } else if (error.isValidationError) {
    // The server rejected the request or media asset.
  } else if (error.isNotFound) {
    // The story or user is not found or is not visible.
  }
}

Local SDK validation failures, such as invalid IDs or unsupported reaction values, throw ArgumentError. Invalid API response shapes throw FormatException.

License #

Add the project owner's chosen open-source license in a LICENSE file at the package root before publishing. The package license has not been specified in this README.

0
likes
120
points
--
downloads

Documentation

API reference

Publisher

unverified uploader

Typed Flutter SDK for Babilo ephemeral social stories.

Repository (GitHub)

License

unknown (license)

Dependencies

mebabl_core

More

Packages that depend on mebabl_stories