taboola_sdk 1.0.1 copy "taboola_sdk: ^1.0.1" to clipboard
taboola_sdk: ^1.0.1 copied to clipboard

Taboola's Flutter Core SDK. This SDK provides access to Taboola's Widget and Feed integrations for Flutter applications.

example/lib/main.dart

import 'dart:collection';
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/keepAliveTest.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 'package:taboola_sdk_example/screens/publishers/walla_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;
  String? keepAlive = "true";
  String KEEP_ALIVE_KEY = "keepAlive";

  @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);
    //   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;
  }

  // pass this callback in order to change the keepAlive value in the KeepAliveTest screen, the Global will manged by the HomeScreen
  void _onKeepAliveChanged(String? value) {
    setState(() {
      keepAlive = value;
    });
    HashMap<String, String> extraProperties = HashMap();
    extraProperties[KEEP_ALIVE_KEY] = keepAlive ?? "";
    Taboola.setGlobalExtraProperties(extraProperties);
  }

  @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('SingleChildScrollView'),
              trailing: Icon(Icons.arrow_forward),
              onTap: () {
                // Update the state of the app.
                setState(() {
                  displayedScreen = SingleChildScrollViewTest(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();
                });
                // 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();
                });
                // 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);
                });
                // 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);
                });
                // 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);
                });
                // 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(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(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();
                });
                // Close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Walla example'),
              trailing: Icon(Icons.arrow_forward),
              onTap: () {
                // Update the state of the app.
                setState(() {
                  displayedScreen = WallaTest();
                });
                // Close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Keep Alive Test'),
              trailing: Icon(Icons.arrow_forward),
              onTap: () {
                // Update the state of the app.
                setState(() {
                  displayedScreen =
                      KeepAliveTest(keepAlive, _onKeepAliveChanged);
                });
                // Close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );
  }
}
6
likes
130
points
239
downloads

Publisher

unverified uploader

Weekly Downloads

Taboola's Flutter Core SDK. This SDK provides access to Taboola's Widget and Feed integrations for Flutter applications.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

crypto, cupertino_http, flutter, flutter_custom_tabs, http, plugin_platform_interface, system_info2, webview_flutter, webview_flutter_android, webview_flutter_wkwebview

More

Packages that depend on taboola_sdk