wapas 0.0.9 copy "wapas: ^0.0.9" to clipboard
wapas: ^0.0.9 copied to clipboard

This package will be used for quick and easy integration with WaPaS in your app.

example/lib/main.dart

import 'dart:math';

import 'package:confetti/confetti.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:wapas/models/achievement_model.dart';
import 'package:wapas/models/config_model.dart';
import 'package:wapas/models/user_achievement_list_model.dart';
import 'package:wapas/wapas.dart';
import 'package:wapas_example/screens/add_partner_screen.dart';
import 'package:wapas_example/screens/balance/partner_balance_chart_screen.dart';
import 'package:wapas_example/screens/reports/mini_transaction_card_screen.dart';
import 'package:wapas_example/screens/reports/partner_balance_report_chart_screen.dart';
import 'package:wapas_example/screens/partner_levels_screen.dart';
import 'package:wapas_example/screens/reports/partner_report_chart_screen.dart';
import 'package:wapas_example/screens/reports/partner_transactions_table_screen.dart';

// TODO : Add your crdentials
const applicationId = "";
const clientId = "";
const clientSecret = "";
const version = "";

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _wapasPlugin = Wapas();
  final navigatorKey = GlobalKey<NavigatorState>();

  AchievementModel? _achievement;
  late ConfettiController _confettiController;

  @override
  void initState() {
    super.initState();
    _confettiController =
        ConfettiController(duration: const Duration(seconds: 10));
    initPlatformState();
    initWapas();
  }

  @override
  void dispose() {
    _confettiController.dispose();
    super.dispose();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _wapasPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  initWapas() async {
    Config config = Config(
        applicationId: applicationId,
        clientId: clientId,
        clientSecret: clientSecret,
        version: version);
    UserAchievementListModel? achievementsList;
    try {
      await _wapasPlugin.init(config!); // initialize the library
      achievementsList = await _wapasPlugin.getUnacknowledgedAchievements(
        "II-1234",
      ); // get all achievements
    } on PlatformException {
      // Log exception and report [email protected]
    }

    if (achievementsList!.rows != null) {
      if (achievementsList!.rows!.isNotEmpty) {
        if (achievementsList!.rows![0].achievement != null) {
          setState(() {
            _achievement = achievementsList!.rows![0].achievement;
          });

          showAchievement(navigatorKey.currentContext!);
        }
      }
    }
  }

  showAchievement(BuildContext context) {
    _confettiController.play();
    showDialog(
      context: context,
      builder: (BuildContext context) => Align(
        alignment: Alignment.center,
        child: Scaffold(
          backgroundColor: Colors.transparent,
          body: Center(
            child: Container(
              width: 240,
              height: 300,
              padding: EdgeInsets.all(16),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                color: Colors.white,
              ),
              child: Column(
                children: [
                  Align(
                    alignment: Alignment.topRight,
                    child: GestureDetector(
                      onTap: () {
                        navigatorKey.currentState!.pop();
                        _confettiController.stop();
                      },
                      child: Icon(Icons.close),
                    ),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Text(
                    _achievement!.title.toString(),
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  /// A custom Path to paint stars.
  Path drawStar(Size size) {
    // Method to convert degree to radians
    double degToRad(double deg) => deg * (pi / 180.0);

    const numberOfPoints = 5;
    final halfWidth = size.width / 2;
    final externalRadius = halfWidth;
    final internalRadius = halfWidth / 2.5;
    final degreesPerStep = degToRad(360 / numberOfPoints);
    final halfDegreesPerStep = degreesPerStep / 2;
    final path = Path();
    final fullAngle = degToRad(360);
    path.moveTo(size.width, halfWidth);

    for (double step = 0; step < fullAngle; step += degreesPerStep) {
      path.lineTo(halfWidth + externalRadius * cos(step),
          halfWidth + externalRadius * sin(step));
      path.lineTo(halfWidth + internalRadius * cos(step + halfDegreesPerStep),
          halfWidth + internalRadius * sin(step + halfDegreesPerStep));
    }
    path.close();
    return path;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: navigatorKey,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        drawer: Drawer(
          child: ListView(
            // Important: Remove any padding from the ListView.
            padding: EdgeInsets.zero,
            children: [
              const DrawerHeader(
                decoration: BoxDecoration(
                  color: Colors.blue,
                ),
                child: Text('Plugin example app'),
              ),
              ListTile(
                title: const Text('Add Partner'),
                onTap: () {
                  navigatorKey.currentState!.push(
                    MaterialPageRoute(
                      builder: (context) => AddPartnerScreen(
                        wapasPlugin: _wapasPlugin,
                      ),
                    ),
                  );
                },
              ),
              ListTile(
                title: const Text('Partner levels'),
                onTap: () {
                  navigatorKey.currentState!.push(
                    MaterialPageRoute(
                      builder: (context) => PartnerLevelsScreen(
                        wapasPlugin: _wapasPlugin,
                      ),
                    ),
                  );
                },
              ),
              ExpansionTile(
                title: Text("Partner Reports Widgets"),
                children: <Widget>[
                  ListTile(
                    title: const Text('Balance Report Chart'),
                    onTap: () {
                      navigatorKey.currentState!.push(
                        MaterialPageRoute(
                          builder: (context) =>
                              PartnerBalanceReportChartScreen(),
                        ),
                      );
                    },
                  ),
                  ListTile(
                    title: const Text('Report Chart'),
                    onTap: () {
                      navigatorKey.currentState!.push(
                        MaterialPageRoute(
                          builder: (context) => PartnerReportChartScreen(),
                        ),
                      );
                    },
                  ),
                  ListTile(
                    title: const Text('Recent Transaction Table'),
                    onTap: () {
                      navigatorKey.currentState!.push(
                        MaterialPageRoute(
                          builder: (context) =>
                              PartnerTransactionsTablesScreen(),
                        ),
                      );
                    },
                  ),
                  ListTile(
                    title: const Text('Mini Transaction Card'),
                    onTap: () {
                      navigatorKey.currentState!.push(
                        MaterialPageRoute(
                          builder: (context) => MiniTransactionCardScreen(),
                        ),
                      );
                    },
                  ),
                ],
              ),
              ExpansionTile(
                title: Text("Partner Balance Widgets"),
                children: <Widget>[
                  ListTile(
                    title: const Text('Balance Chart'),
                    onTap: () {
                      navigatorKey.currentState!.push(
                        MaterialPageRoute(
                          builder: (context) => PartnerBalanceChartScreen(),
                        ),
                      );
                    },
                  ),
                ],
              ),
            ],
          ),
        ),
        body: _achievement != null
            ? Stack(
                children: [
                  Align(
                    alignment: Alignment.center,
                    child: ConfettiWidget(
                      confettiController: _confettiController,
                      blastDirectionality: BlastDirectionality.explosive,
                      // don't specify a direction, blast randomly
                      shouldLoop: true,
                      // start again as soon as the animation is finished
                      colors: const [
                        Colors.green,
                        Colors.blue,
                        Colors.pink,
                        Colors.orange,
                        Colors.purple
                      ],
                      // manually specify the colors to be used
                      createParticlePath: drawStar,
                    ),
                  ),
                  Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(_achievement!.title.toString()),
                        Builder(
                          builder: (context) => ElevatedButton(
                            onPressed: () {
                              showAchievement(context);
                            },
                            child: Text('Show Achievement'),
                          ),
                        )
                      ],
                    ),
                  ),
                ],
              )
            : Center(
                child: Text('Running on: $_platformVersion\n'),
              ),
      ),
    );
  }
}
1
likes
140
points
3
downloads

Publisher

unverified uploader

Weekly Downloads

This package will be used for quick and easy integration with WaPaS in your app.

Homepage

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, http, plugin_platform_interface, shared_preferences

More

Packages that depend on wapas

Packages that implement wapas