Skip to main content

flutter_elevok_widget 1.1.0 copy "flutter_elevok_widget: ^1.1.0" to clipboard
flutter_elevok_widget: ^1.1.0 copied to clipboard

Elevok rewards for Flutter apps. A launcher and an instant panel with your loyalty programme, campaigns, games and rewards, signed in with your app.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_elevok_widget/flutter_elevok_widget.dart';

/// Your store id (Elevok Cockpit › Widget › Install).
const storeId =
    String.fromEnvironment('ELEVOK_STORE_ID', defaultValue: 'YOUR_STORE_ID');

/// A customer's session, made by your server with the partner API (`POST /api/v1/players/login`).
const customerToken = String.fromEnvironment('ELEVOK_CUSTOMER_TOKEN');

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

class ExampleApp extends StatefulWidget {
  const ExampleApp({super.key});

  @override
  State<ExampleApp> createState() => _ExampleAppState();
}

class _ExampleAppState extends State<ExampleApp> {
  ThemeMode _theme = ThemeMode.light;
  final _events = <String>[];

  @override
  Widget build(BuildContext context) {
    return ElevokWidget(
      appID: storeId,
      locale: const Locale('fr'),
      themeMode: _theme,
      // a partner store: a guest wants to sign in, open your sign-in
      signInRedirection: (context) => Navigator.of(context)
          .push(MaterialPageRoute<void>(builder: (_) => const SignInPage())),
      // "Show me the button" in the panel: the screen that has that button (it pulses there)
      onLocate: (context, code) => Navigator.of(context)
          .push(MaterialPageRoute<void>(builder: (_) => const ProductPage())),
      launcherInsets: const EdgeInsets.only(bottom: 16),
      onEvent: (event) =>
          setState(() => _events.insert(0, '${event.name} ${event.detail}')),
      child: MaterialApp(
        title: 'Elevok example',
        themeMode: _theme,
        theme: ThemeData(colorSchemeSeed: Colors.indigo),
        darkTheme: ThemeData(
            colorSchemeSeed: Colors.indigo, brightness: Brightness.dark),
        home: HomePage(
          events: _events,
          dark: _theme == ThemeMode.dark,
          onDark: (dark) =>
              setState(() => _theme = dark ? ThemeMode.dark : ThemeMode.light),
        ),
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage(
      {required this.events,
      required this.dark,
      required this.onDark,
      super.key});

  final List<String> events;
  final bool dark;
  final ValueChanged<bool> onDark;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Elevok example')),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          SwitchListTile(
              title: const Text('Dark theme'), value: dark, onChanged: onDark),
          const Divider(),
          Wrap(spacing: 8, runSpacing: 8, children: [
            FilledButton(
                onPressed: () => ElevokFunctions.open(),
                child: const Text('Rewards')),
            OutlinedButton(
                onPressed: () => ElevokFunctions.open(section: 'GAMES'),
                child: const Text('Games')),
            OutlinedButton(
                onPressed: () => ElevokFunctions.open(section: 'CAMPAIGNS'),
                child: const Text('Earn points')),
            OutlinedButton(
                onPressed: ElevokFunctions.openLeaderboard,
                child: const Text('Leaderboard')),
          ]),
          const SizedBox(height: 16),
          Wrap(spacing: 8, runSpacing: 8, children: [
            FilledButton.tonal(
              onPressed: customerToken.isEmpty
                  ? null
                  : () => ElevokFunctions.signIn(customerToken,
                      player: 'customer-1'),
              child: const Text('Sign in'),
            ),
            FilledButton.tonal(
                onPressed: ElevokFunctions.signOutWidget,
                child: const Text('Sign out')),
            FilledButton.tonal(
              onPressed: () => Navigator.of(context).push(
                  MaterialPageRoute<void>(builder: (_) => const ProductPage())),
              child: const Text('A product'),
            ),
          ]),
          const SizedBox(height: 24),
          Text('Events', style: Theme.of(context).textTheme.titleMedium),
          for (final event in events.take(20))
            Text(event, style: Theme.of(context).textTheme.bodySmall),
        ],
      ),
    );
  }
}

/// A product page with a button that earns points (a "site button" in Cockpit › Widget › Site buttons).
class ProductPage extends StatelessWidget {
  const ProductPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('A product')),
      body: Center(
        child: ElevokAnimatedButton(
          activityID: 'SHARE_PRODUCT_FACEBOOK',
          child: IconButton.filled(
              iconSize: 32, onPressed: null, icon: const Icon(Icons.share)),
        ),
      ),
    );
  }
}

/// Your sign-in: once the customer is signed in, your server gets their Elevok session and the app hands it over.
class SignInPage extends StatelessWidget {
  const SignInPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Sign in')),
      body: Center(
        child: FilledButton(
          onPressed: customerToken.isEmpty
              ? null
              : () async {
                  await ElevokFunctions.signIn(customerToken,
                      player: 'customer-1');
                  if (context.mounted) Navigator.of(context).pop();
                },
          child: const Text('Sign in'),
        ),
      ),
    );
  }
}
2
likes
150
points
535
downloads

Documentation

API reference

Publisher

verified publisherdiktup.com

Weekly Downloads

Elevok rewards for Flutter apps. A launcher and an instant panel with your loyalty programme, campaigns, games and rewards, signed in with your app.

Homepage

Topics

#loyalty #rewards #gamification #webview #widget

License

MIT (license)

Dependencies

flutter, http, shared_preferences, url_launcher, webview_flutter, webview_flutter_android, webview_flutter_wkwebview

More

Packages that depend on flutter_elevok_widget