outbrain_flutter 1.4.0 outbrain_flutter: ^1.4.0 copied to clipboard
Flutter plugin for the Outbrain Smartfeed Widget
import 'package:flutter/material.dart';
import 'package:outbrain_flutter/outbrain_flutter.dart';
import 'my_custom_handler.dart' show MyCustomHandler;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Outbrain Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange),
useMaterial3: true,
),
home: const ArticlePage(title: 'Flutter Outbrain Demo'),
);
}
}
class ArticlePage extends StatefulWidget {
const ArticlePage({super.key, required this.title});
final String title;
@override
State<ArticlePage> createState() => _ArticlePageState();
}
class _ArticlePageState extends State<ArticlePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Image.asset(
'images/article_image.jpg',
height: 200,
width: double.infinity,
fit: BoxFit.cover,
),
Padding(
padding: const EdgeInsets.only(left: 16, right: 16),
child: Column(
children: [
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(10.0),
width: double.infinity,
color: Colors.blue,
child: const Text(
'Sky News',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
const SizedBox(height: 8),
const Text(
'Suarez: "Messi Was Born Great, Ronaldo Made Himself Great"',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
_buildArticleText(),
_buildArticleText(),
const SizedBox(height: 16),
OutbrainWidget(
partnerKey: 'NANOWDGT01',
articleUrl: 'https://mobile-demo.outbrain.com',
widgetId: 'MB_2',
widgetIndex: 0,
darkMode: false,
),
_buildArticleText(),
const SizedBox(height: 8),
_buildArticleText(),
OutbrainWidget(
partnerKey: 'NANOWDGT01',
articleUrl: 'https://mobile-demo.outbrain.com',
widgetId: 'MB_5',
widgetIndex: 1,
extId: "myId",
extSecondaryId: "mySecondaryId",
darkMode: false,
),
],
),
),
],
),
),
),
);
}
}
Column _buildArticleText() {
const String loremIpsum =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. '
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. '
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
return const Column(children: [
Text(
loremIpsum,
style: TextStyle(
fontSize: 16,
),
),
SizedBox(height: 24),
]);
}