outbrain_flutter 1.1.0 outbrain_flutter: ^1.1.0 copied to clipboard
Flutter plugin for the Outbrain SmartFeed Widget
outbrain_flutter #
Flutter plugin for the Outbrain SmartFeed Widget. This plugin allows you to easily integrate Outbrain widgets into your application with minimal effort.
Getting Started #
Installation
Add outbrain_flutter
as a dependency in your pubspec.yaml
file:
dependencies:
flutter:
sdk: flutter
outbrain_flutter: ^1.0.0
Then, run flutter pub get
to install the package.
Usage
To use the provided widget, simply import the package and include the widget in your widget tree:
import 'package:outbrain_flutter/outbrain_flutter.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('OutbrainWidget Example'),
),
body: Center(
child: OutbrainWidget(
partnerKey: 'my-partner-key',
articleUrl: 'https://mobile-demo.outbrain.com',
widgetId: 'my-widget-id',
widgetIndex: 0,
),
),
),
);
}
}
Customization #
The OutbrainWidgetHandler
interface defines 4 handler methods that correspond to ceratin widget events.
abstract class OutbrainWidgetHandler {
void onRecClick(String url);
void onOrganicRecClick(String url);
void didChangeHeight(double newHeight);
void widgetEvent(String eventName, Map<Object?, Object?> additionalData);
}
Simply implement this interface and supply an instance to the constructor of OutbrainWidget
:
class MyCustomHandler implements OutbrainWidgetHandler {
@override
void didChangeHeight(double newHeight) {
/* Your implementation here */
}
@override
void onRecClick(String url) {
/* Your implementation here - e.g. open custom browser */
}
@override
void onOrganicRecClick(String url) {
/* Your implementation here - e.g. navigate to article */
}
@override
void widgetEvent(String eventName, Map<Object?, Object?> additionalData) {
/* Your implementation here */
}
}
OutbrainWidget(
partnerKey: 'my-partner-key',
articleUrl: 'https://mobile-demo.outbrain.com',
widgetId: 'my-widget-id',
widgetIndex: 0,
handler: MyCustomHandler()
)
License #
This project is licensed under the MIT License - see the LICENSE file for details.