How to get started
Installation
Add the dependency in your app's pubspec.yaml.
dependencies:
inappstory_plugin: ^0.8.2
Or run this command:
flutter pub add inappstory_plugin
Android Requirements
Step 1:
Make sure you update your Android SDK versions in app/build.gradle.
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
Step 2:
Initialize Android SDK in your Application class.
Without this, the library will not work on Android devices
- Kotlin
- Java
package com.example.yourapp
import android.app.Application
import com.inappstory.inappstory_plugin.InAppStoryPlugin
class ExampleApplication : Application() {
override fun onCreate() {
super.onCreate()
// init SDK
InAppStoryPlugin.initSDK(this)
}
}
package com.example.yourapp;
import android.app.Application;
import com.inappstory.inappstory_plugin.InAppStoryPlugin;
class ExampleApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// init SDK
InAppStoryPlugin.initSDK(this);
}
}
Step 3:
Extend your MainActivity class from InAppStoryActivity.
- Kotlin
- Java
package com.example.yourapp
import io.flutter.embedding.android.FlutterActivity
import com.inappstory.inappstory_plugin.activity.InAppStoryActivity
class MainActivity : FlutterActivity()
class MainActivity : InAppStoryActivity()
package com.example.yourapp;
import io.flutter.embedding.android.FlutterActivity;
import com.inappstory.inappstory_plugin.activity.InAppStoryActivity;
class MainActivity extends FlutterActivity(){
class MainActivity extends InAppStoryActivity {
}
Step 4:
Add manifestPlaceholders to your app/build.gradle file
android {
...
defaultConfig {
...
manifestPlaceholders['applicationName'] = '<name of your custom application class>'
}
}
Why do I need this?
InAppStoryActivity extends FlutterFragmentActivity and intercepts the Back button tap at the Android hardware/software
level. This feature is only used when an In-App message (IAM) is shown. It first redirects
the tap through the SDK, so pressing the Back button closes the In-App message within the app rather than
navigating to another screen. If MainActivity continues to extend FlutterActivity, the Back button bypasses the SDK, and
the reader will not close correctly.
iOS Requirements
Make sure you run pod install or pod install --repo-update in the ios folder of your Flutter project.
Basic initialization
Await the plugin return before the use of other API's.
Future<void> initSDK() async {
await InAppStoryPlugin().initWith(
'<your api key>',
'<user id>',
locale: <locale>,
cacheSize: CacheSize.medium
);
// ... any other calls to API
}
- Parameter
userIdcan be empty. - Parameter
localeused to set up story reader in case, that you need right-to-left direction of interface. It is optional and must be created with region subtag (likeLocale('en', 'US')). Otherwise, locale will be default en-US - Parameter
cacheSizeis optional and used to changing space of caching stories files (images, videos) (works only on Android devices, default isCacheSize.medium)
CacheSize.small //equal to 15mb;
CacheSize.medium //equal to 110mb, uses by default;
CacheSize.large //equal to 210mb;
Usage
To use the library, add FeedStoriesWidget to your widget tree.
class FeedExample extends StatelessWidget {
const FeedExample({super.key});
Widget build(BuildContext context) {
return FeedStoriesWidget(
feed: '<your feed id>',
);
}
}
Full example
Full example
import 'package:flutter/material.dart';
import 'package:inappstory_plugin/inappstory_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _inAppStoryPlugin = InAppStoryPlugin();
final apiKey = '<your-api-key>';
// can be empty
final userId = '<user-id>';
final feed = '<your-feed-id>';
late final initialization = initSdk();
Future<void> initSdk() async {
await _inAppStoryPlugin.initWith(apiKey, userId);
}
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('InAppStory Example'),
),
body: FutureBuilder(
future: initialization,
builder: (context, initializationSnapshot) {
if (initializationSnapshot.connectionState ==
ConnectionState.done) {
if (initializationSnapshot.hasError) {
return const Text('SDK was not initialized');
} else {
return Column(
children: [
FeedStoriesWidget(
feed: feed,
),
],
);
}
}
return const Center(
child: CircularProgressIndicator(),
);
},
),
),
);
}
}