pivo 0.2.3+1 copy "pivo: ^0.2.3+1" to clipboard
pivo: ^0.2.3+1 copied to clipboard

A wrapper for the Pivo Pro SDK. Control your Pivo device from you flutter application!

example/lib/main.dart

// Copyright (c) 2022, Sports Visio, Inc
// https://sportsvisio.com
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:pivo/pivo.dart';
import 'package:pivo_example/pivo_control_page.dart';
import 'package:pivo_example/pop_ups.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

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

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

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
      final permissions = await Permission.values.request();

      permissions.forEach((permission, status) {
        log('Permission $permission is $status');
      });

      String? licenseKey;
      if (Platform.isAndroid) {
        licenseKey =
            '{"owner":"Pivo","platform":"android","plan":"pro","appIdentifier":"app.pivo.android.prosdkdemo","createdAt":1587528360,"expiredAt":2524575600,"signature":"KqyuZmlt5rOQynORymSI+o2hMRwPdWUcU/LPBqZAQQUJybEBaL7+LlWdReAcfnNyafStKjw607s2Jf79T3Nbhq/jpvTD/upGga2BqJYTOiOsUGpZe/vjDgR3iMad0IOdmEf/68hdvo70w0AObZ9xufO5rjMTXc/sXY43kQ40/KS9UQfICUzLi1zgnJNF+C08n5fKuY7vzEOFB8P6Id0UTRFrPVDTkzTpze7aUtkF0pvJ/F+8FnRMP2r004sGVsGREJYnvAAPnV76yPzy4jsBAc4qVxTY508FwL/AwtNN5n1gJAdpS9D+0HkK1bvaxwWCBZ0Kk67uqFjXSaiOBrN5vQ=="}';
      } else {
        licenseKey =
            '{"owner":"Pivo","platform":"ios","plan":"pro","appIdentifier":"app.pivo.ios.prosdkdemo","createdAt":1589928528,"expiredAt":2537535600,"signature":"QCnY1ShAHgBRnxfkeLNesDhogCj8PtFavbeqIK/hpq0+2U1vVByvJHzYYqyD9MsqWkuhorYETmB3bGLfhQzuf1C/IYVTg6STXBu5xJJxGbchGT/YcEmnyhHMXg6kkXUUNHYQGu45iuk11olX6aaxNhVY+UatMW9V4hcBjalNoVnbQiID/Mk4jVYFw/e+lB/JX0/ALhQJb1GwsATrEbnwY4F6YNLfPyQ7AAiuf9VDa0tmf0XpV6EiRNYcuqHWta9n8Wft78iG4bxKCV7zF7VmbVI9a1wlOOXrv6bGFl85NVjtSecnai+difBqNz0QXFfD6uXoJqU9orAtc9hrI4caGg=="}';
      }

      await PivoPlatform.instance.unlockWithLicenseKey(licenseKey);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Pivo Example')),
      body: StreamBuilder(
        stream: PivoPlatform.instance.scanResults,
        builder: (context, snapshot) {
          final data = snapshot.data;
          if (!snapshot.hasData || data == null) {
            return const SizedBox.shrink();
          }

          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Expanded(
                child: ListView.builder(
                  itemCount: data.length,
                  itemBuilder: (context, index) {
                    final result = data[index];
                    return PivoDeviceTile(scanResult: result);
                  },
                ),
              ),
            ],
          );
        },
      ),
      floatingActionButton: StreamBuilder<bool>(
        stream: PivoPlatform.instance.isScanningStream,
        builder: (context, snapshot) {
          if (snapshot.data ?? false) {
            return FloatingActionButton(
              onPressed: PivoPlatform.instance.stopScan,
              backgroundColor: Colors.red,
              child: const Icon(Icons.stop),
            );
          }

          return FloatingActionButton(
            onPressed: PivoPlatform.instance.startScan,
            child: const Icon(Icons.search),
          );
        },
      ),
    );
  }
}

class PivoDeviceTile extends StatefulWidget {
  const PivoDeviceTile({
    required this.scanResult,
    super.key,
  });

  final PivoDevice scanResult;

  @override
  State<PivoDeviceTile> createState() => _PivoDeviceTileState();
}

class _PivoDeviceTileState extends State<PivoDeviceTile> {
  String get name => widget.scanResult.name;
  String get address => widget.scanResult.address;

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(name),
      subtitle: Text(address),
      trailing: IconButton(
        icon: const Icon(Icons.bluetooth),
        onPressed: () async {
          final result = await LoadingPopUp<PivoConnectionStatusEvent>(
            () => PivoPlatform.instance.connect(widget.scanResult),
            'Connecting to $name.\nMac Address $address...',
          ).show(context);

          if (!mounted) return;

          if (result is! PivoConnectionStatusCompleteEvent) {
            await const FailureToConnectPopUp().show(context);
            return;
          }

          await Navigator.of(context).push(
            MaterialPageRoute<void>(
              builder: (context) => PivoControlPage(result),
            ),
          );
        },
      ),
    );
  }
}
8
likes
150
pub points
0%
popularity

Publisher

verified publisheraquiles.dev

A wrapper for the Pivo Pro SDK. Control your Pivo device from you flutter application!

Repository

Documentation

API reference

License

MIT (license)

Dependencies

flutter, pivo_android, pivo_ios, pivo_platform_interface

More

Packages that depend on pivo