shareid_sdk_flutter 2.0.4 copy "shareid_sdk_flutter: ^2.0.4" to clipboard
shareid_sdk_flutter: ^2.0.4 copied to clipboard

The ShareID SDKs are built in design to offer the best user experience.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:shareid_sdk_flutter/shareid_sdk_flutter.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _shareid = ShareidSdkFlutter();
  Color primaryColor = const Color(0xff2A4DC6);
  bool isLoading = false;
  String uuid = "";

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

  String onBoardingServiceToken = "";
  late MessageHandler result;

  void getOnboardingToken() {
    setState(() {
      isLoading = true;
    });
    _shareid
        .onboarding("SHARE_ID_SERVER_URL", "SHARE_ID_SERVICE_TOKEN")
        .then((value) {
      setState(() {
        Map<String, dynamic> valueMap = json.decode(value!);
        result = MessageHandler.fromJson(valueMap);
        switch (result.messageHandler) {
          case "success":
            Fluttertoast.showToast(msg: result.message!);
            break;
          case "exit":
            Fluttertoast.showToast(msg: result.message!);
            break;
          case "failure":
            Fluttertoast.showToast(msg: result.message!);
            break;
          default:
            break;
        }
      });
    });
    setState(() {
      isLoading = false;
    });
  }

  void getAuthenticateToken() {
    setState(() {
      isLoading = true;
    });
    _shareid
        .authenticate("SHARE_ID_SERVER_URL", "SHARE_ID_SERVICE_TOKEN")
        .then((value) {
      setState(() {
        Map<String, dynamic> valueMap = json.decode(value!);
        result = MessageHandler.fromJson(valueMap);
        switch (result.messageHandler) {
          case "success":
            Fluttertoast.showToast(msg: result.message!);
            break;
          case "exit":
            Fluttertoast.showToast(msg: result.message!);
            break;
          case "failure":
            Fluttertoast.showToast(msg: result.message!);
            break;
          default:
            break;
        }
      });
    });

    setState(() {
      isLoading = false;
    });
  }

  Future<void> displayDialog(BuildContext context) async {
    return showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: const Text('Your UUID'),
            content: TextField(
              onChanged: (value) {
                setState(() {
                  uuid = value;
                });
              },
              //controller: _textFieldController,
              decoration: const InputDecoration(hintText: "Put your uuid"),
            ),
            actions: <Widget>[
              MaterialButton(
                color: primaryColor,
                textColor: Colors.white,
                child: const Text('Submit'),
                onPressed: () {
                  setState(() {
                    getAuthenticateToken();
                    Navigator.pop(context);
                  });
                },
              ),
            ],
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 32),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                margin: const EdgeInsets.only(top: 140),
                padding:
                    const EdgeInsets.symmetric(horizontal: 10, vertical: 20),
                child: Image.asset("images/logo_share.png"),
              ),
              isLoading
                  ? CircularProgressIndicator(
                      color: primaryColor,
                    )
                  : const SizedBox.shrink(),
              Container(
                margin: const EdgeInsets.only(bottom: 56),
                child: Column(
                  children: [
                    ElevatedButton(
                      onPressed: () {
                        if (!isLoading) displayDialog(context);
                      },
                      style: ElevatedButton.styleFrom(
                        side: BorderSide(width: 2.0, color: primaryColor),
                        backgroundColor: primaryColor,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(32.0),
                        ),
                      ),
                      child: Container(
                        width: double.infinity,
                        padding: const EdgeInsets.symmetric(vertical: 15),
                        child: const Center(
                          child: Text(
                            'Se connecter',
                            style: TextStyle(color: Colors.white),
                          ),
                        ),
                      ),
                    ),
                    const SizedBox(
                      height: 10,
                    ),
                    ElevatedButton(
                      onPressed: () {
                        if (!isLoading) getOnboardingToken();
                      },
                      style: ElevatedButton.styleFrom(
                        side: BorderSide(width: 2.0, color: primaryColor),
                        backgroundColor: Colors.white,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(32.0),
                        ),
                      ),
                      child: Container(
                        width: double.infinity,
                        padding: const EdgeInsets.symmetric(vertical: 15),
                        child: Center(
                          child: Text(
                            'S\'inscrire',
                            style: TextStyle(color: primaryColor),
                          ),
                        ),
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

class MessageHandler {
  String? messageHandler;
  String? code;
  String? message;

  MessageHandler(this.code, this.message, this.messageHandler);

  MessageHandler.fromJson(Map<String, dynamic> json) {
    code = json['code'];
    message = json['message'];
    messageHandler = json['messageHandler'];
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['code'] = code;
    map['message'] = message;
    map['messageHandler'] = messageHandler;
    return map;
  }
}
0
likes
160
points
263
downloads

Publisher

verified publishershareid.ai

Weekly Downloads

The ShareID SDKs are built in design to offer the best user experience.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on shareid_sdk_flutter