outbrain_flutter 1.0.0
outbrain_flutter: ^1.0.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 {
/*
Implement the handler methods
*/
}
OutbrainWidget(
partnerKey: 'my-partner-key',
articleUrl: 'https://mobile-demo.outbrain.com',
widgetId: 'my-widget-id',
widgetIndex: 0,
handler: MyCustomHandler()
)
Example #
For a complete example, refer to the example directory in the repository. You can run the example app to see the widget in action:
cd example
flutter run
License #
This project is licensed under the MIT License - see the LICENSE file for details.