aiprise_flutter_sdk 2.0.1 copy "aiprise_flutter_sdk: ^2.0.1" to clipboard
aiprise_flutter_sdk: ^2.0.1 copied to clipboard

Identity verification made simple

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:aiprise_flutter_sdk/aiprise_flutter_sdk.dart';
import 'package:permission_handler/permission_handler.dart';

// 1 - Material Button Example
class MaterialExample extends StatelessWidget {
  const MaterialExample({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
          useMaterial3: true,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text('Material Example'),
            backgroundColor: Colors.blue,
            foregroundColor: Colors.white,
          ),
          body: const Center(
              child: AiPriseMaterialButton(
                  mode: AiPriseEnvironment.sandbox,
                  templateID: "TEMPLATE_ID_HERE")),
        ));
  }
}

// 2 - Cupertino Button Example
class CupertinoExample extends StatelessWidget {
  const CupertinoExample({super.key});

  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      theme: CupertinoThemeData(primaryColor: CupertinoColors.activeBlue),
      home: CupertinoPageScaffold(
          navigationBar: CupertinoNavigationBar(
            middle: Text('Cupertino Example'),
          ),
          child: Center(
              child: AiPriseCupertinoButton(
                  mode: AiPriseEnvironment.sandbox,
                  templateID: "TEMPLATE_ID_HERE"))),
    );
  }
}

// 3 - Splits the screen into 2 and shows both examples
// Also handles asking for camera permission

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

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

class _MyAppState extends State<MyApp> {
  bool _isCameraPermissionGranted = false;

  @override
  initState() {
    super.initState();

    Permission.camera.request().then((cameraStatus) {
      if (cameraStatus.isPermanentlyDenied) {
        openAppSettings(); // Open settings to prompt user to allow camera permission!
      }
      if (cameraStatus.isGranted) {
        setState(() {
          _isCameraPermissionGranted = true;
        });
      }
    });
  }

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return SizedBox.expand(
      child: Column(
        children: (!_isCameraPermissionGranted
            // Show text if camera permission is not granted
            ? [Text("Camera permission not granted yet!")]
            : [
                //  Show Material Example
                Expanded(child: MaterialExample()),

                Divider(
                  height: 1,
                ),

                // Show Cupertino Example
                Expanded(
                  child: CupertinoExample(),
                ),
              ]),
      ),
    );
  }
}

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