bitlabs 3.0.1 copy "bitlabs: ^3.0.1" to clipboard
bitlabs: ^3.0.1 copied to clipboard

PlatformAndroid

BitLabs offers the opportunity to monetize your app with rewarded surveys easily.

example/lib/main.dart

import 'dart:developer';

import 'package:bitlabs/bitlabs.dart';
import 'package:example/secrets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        ...GlobalMaterialLocalizations.delegates,
        LocalizationDelegate(),
      ],
      supportedLocales: const [
        Locale('en', ''),
        Locale('es', ''),
        Locale('de', ''),
        Locale('fr', ''),
        Locale('it', ''),
      ],
      home: const HomePage(title: 'BitLabs Example'),
    );
  }
}

class HomePage extends StatefulWidget {
  final String title;

  const HomePage({Key? key, required this.title}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  ListView? surveyWidgets;
  final uid = 'oblivatevariegata';

  bool isLeaderboardVisible = false;
  bool isSurveyWidgetVisible = false;

  @override
  void initState() {
    super.initState();
    BitLabs.instance.init(appToken, uid);

    BitLabs.instance.setOnReward(
        (reward) => log('[Example] Reward for this session: $reward'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          const SizedBox(height: 8),
          Expanded(
            flex: 5,
            child: isLeaderboardVisible
                ? BitLabsWidget(
                    token: appToken,
                    uid: uid,
                    type: WidgetType.leaderboard,
                  )
                : const SizedBox.shrink(),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Row(
                children: [
                  const SizedBox(width: 4),
                  Expanded(
                    child: CustomButton(
                      onPressed: () =>
                          setState(() => isLeaderboardVisible = true),
                      title: 'Show Leaderboard',
                    ),
                  ),
                  const SizedBox(width: 4),
                ],
              ),
              Row(
                children: [
                  const SizedBox(width: 4),
                  Expanded(
                    child: CustomButton(
                      onPressed: BitLabs.instance.requestTrackingAuthorization,
                      title: 'Authorize Tracking(iOS)',
                    ),
                  ),
                  const SizedBox(width: 8),
                  Expanded(
                    child: CustomButton(
                      onPressed: checkForSurveys,
                      title: 'Check for Surveys',
                    ),
                  ),
                  const SizedBox(width: 4),
                ],
              ),
              Row(
                children: [
                  const SizedBox(width: 4),
                  Expanded(
                    child: CustomButton(
                      onPressed: () =>
                          BitLabs.instance.launchOfferWall(context),
                      title: 'Open OfferWall',
                    ),
                  ),
                  const SizedBox(width: 4),
                ],
              ),
              Row(
                children: [
                  const SizedBox(width: 4),
                  Expanded(
                    child: CustomButton(
                      onPressed: getSurveys,
                      title: 'Get Surveys',
                    ),
                  ),
                  const SizedBox(width: 8),
                  Expanded(
                    child: CustomButton(
                      onPressed: () =>
                          setState(() => isSurveyWidgetVisible = true),
                      title: 'Show Survey Widget',
                    ),
                  ),
                  const SizedBox(width: 4),
                ],
              ),
            ],
          ),
          if (isSurveyWidgetVisible)
            BitLabsWidget(
              token: appToken,
              uid: uid,
              type: WidgetType.simple,
            ),
          const Spacer(),
        ],
      ),
    );
  }

  void checkForSurveys() => BitLabs.instance.checkSurveys(
      (hasSurveys) => log('[Example] Checking Surveys -> '
          '${hasSurveys ? 'Surveys Available!' : 'No Surveys!'}'),
      (exception) => log('[Example] CheckSurveys $exception'));

  void getSurveys() => BitLabs.instance.getSurveys(
        (surveys) {
          for (final element in surveys) {
            log('[Example] Survey: ${element.id} - ${element.value} - ${element.rating}');
          }
        },
        (exception) => log('[Example] GetSurveys $exception'),
      );
}

class CustomButton extends StatelessWidget {
  final String title;
  final VoidCallback? onPressed;

  const CustomButton({Key? key, required this.title, this.onPressed})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(onPressed: onPressed, child: Text(title));
  }
}
3
likes
150
points
2.38k
downloads

Publisher

verified publisherbitlabs.ai

Weekly Downloads

BitLabs offers the opportunity to monetize your app with rewarded surveys easily.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

advertising_id, device_info_plus, flutter, flutter_localizations, flutter_svg, http, image_picker, qr_flutter, url_launcher, webview_flutter, webview_flutter_android

More

Packages that depend on bitlabs