taboola_sdk 1.0.0 taboola_sdk: ^1.0.0 copied to clipboard
Taboola's Flutter Core SDK. This SDK provides access to Taboola's Widget and Feed integrations for Flutter applications.
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:taboola_sdk_example/screens/ExtraPropertiesExampleScreen.dart';
import 'package:taboola_sdk_example/screens/GUEH_example.dart';
import 'package:taboola_sdk_example/screens/listView_example.dart';
import 'package:taboola_sdk_example/screens/publishers/ali_test.dart';
import 'package:taboola_sdk_example/screens/publishers/nikib_test.dart';
// import screens
import 'package:taboola_sdk_example/screens/single_child_scroll_view_test.dart';
import 'package:taboola_sdk_example/screens/taboola_custom_scrollview_screen.dart';
import 'package:taboola_sdk_example/screens/taboola_dedupe_screen.dart';
import 'package:taboola_sdk_example/screens/taboola_tabs_screen.dart';
import 'package:taboola_sdk_example/screens/taboola_pageview_screen.dart';
import 'package:taboola_sdk_example/DefaultProperties.dart'
as PublisherProperties;
import 'package:taboola_sdk/taboola.dart';
void main() {
// simulate publisher error handling, also used for QA testing of GUEH
FlutterError.onError = (details) {
Fluttertoast.showToast(
msg: details.exceptionAsString(),
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
};
PlatformDispatcher.instance.onError = (error, stack) {
if (error is PlatformException) {
Fluttertoast.showToast(
msg: error.message.toString(),
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}
return false;
};
// Init Taboola SDK
WidgetsFlutterBinding.ensureInitialized();
Taboola.setLogsEnabled(true);
Taboola.init(TBLPublisherInfo(PublisherProperties.publisher));
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(home: new HomeScreen());
}
}
class HomeScreen extends StatefulWidget {
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
late Widget displayedScreen;
bool keepAlive = false;
@override
void initState() {
super.initState();
// We want the test app to show logs, current SDK default is to not show logs.
// Taboola.setLogsEnabled(false);
// Set default screen
// displayedScreen = TaboolaTabsScreen(PublisherProperties.publisher, PublisherProperties.page_url, PublisherProperties.page_type, PublisherProperties.placement, PublisherProperties.mode);
displayedScreen = TaboolaCustomScrollviewScreen(
PublisherProperties.publisher,
PublisherProperties.page_url,
PublisherProperties.page_type,
PublisherProperties.placement,
PublisherProperties.mode,
keepAlive);
// displayedScreen = NikiB();
// displayedScreen = AliTest();
// displayedScreen = SingleChildScrollViewTest();
// displayedScreen = TOnlineScreen("exampleArticle");
// displayedScreen = TaboolaPageViewScreen(PublisherProperties.publisher, PublisherProperties.pageUrl, PublisherProperties.pageType, PublisherProperties.placement, PublisherProperties.mode);
// Allow gesture debugging
// debugPrintGestureArenaDiagnostics = true;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.dark,
title: Text('TaboolaFlutterDemo'),
),
body: Center(
child: displayedScreen,
),
drawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Taboola Sample Screens'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text("Is keep alive Unit?"),
trailing: Switch(
// This bool value toggles the switch.
value: keepAlive,
activeColor: Colors.blueAccent,
onChanged: (bool value) {
// This is called when the user toggles the switch.
setState(() {
keepAlive = value;
});
},
),
),
ListTile(
title: Text('SingleChildScrollView'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen =
SingleChildScrollViewTest(keepAlive, context);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('Dedupe Example'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = TaboolaDedupeScreen(keepAlive);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('ListViewExample'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen =
CustomListViewPageFeedAndWidget(isKeepAlive: keepAlive);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('TaboolaClassic | CustomScrollView w/ Feed'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = TaboolaCustomScrollviewScreen(
PublisherProperties.publisher,
PublisherProperties.page_url,
PublisherProperties.page_type,
PublisherProperties.placement,
PublisherProperties.mode,
keepAlive);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('TaboolaClassic | Tabs w/ Feed'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = TaboolaTabsScreen(
PublisherProperties.publisher,
PublisherProperties.page_url,
PublisherProperties.page_type,
PublisherProperties.placement,
PublisherProperties.mode,
keepAlive);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('TaboolaClassic | PageView w/ Feed'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = TaboolaPageViewScreen(
PublisherProperties.publisher,
PublisherProperties.page_url,
PublisherProperties.page_type,
PublisherProperties.placement,
PublisherProperties.mode,
keepAlive);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('TaboolaClassic | Ali\'s Case'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = AliTest(keepAlive, context);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('TaboolaClassic | Niki Bs Case'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = NikiB(keepAlive, context);
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('GUEH Example'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = GUEHExample();
});
// Close the drawer
Navigator.pop(context);
},
),
ListTile(
title: Text('ExtraProperties Example Screen'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
// Update the state of the app.
setState(() {
displayedScreen = ExtraPropertiesExampleScreen(keepAlive);
});
// Close the drawer
Navigator.pop(context);
},
),
],
),
),
);
}
}