ddt 1.0.0 copy "ddt: ^1.0.0" to clipboard
ddt: ^1.0.0 copied to clipboard

This package helps to generate and verify authentication token.

example/lib/main.dart

import 'package:ddt/tokenizer.dart';
import 'package:flutter/material.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 String key = "datadirr";
  final dynamic _payload = {"name": "datadirr"};
  String? _token = "";
  dynamic _tokenData = "";
  bool _expired = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text("payload: $_payload"),
                ElevatedButton(
                  onPressed: () {
                    _generateToken();
                  },
                  child: const Text("Generate Token"),
                ),
                Text("token: $_token"),
                ElevatedButton(
                  onPressed: () {
                    _verifyToken();
                  },
                  child: const Text("Verify Token"),
                ),
                Text("tokenData: $_tokenData"),
                ElevatedButton(
                  onPressed: () {
                    _checkTokenExpired();
                  },
                  child: const Text("Check Token Expired"),
                ),
                Text("expired: $_expired"),
              ],
            ),
          ),
        ),
      ),
    );
  }

  void _generateToken() async {
    _token = await DDT.generateToken(_payload, key: key, seconds: 60);
    debugPrint(_token);
    setState(() {});
  }

  void _verifyToken() async {
    try {
      final result = await DDT.verifyToken(_token, key: key);
      _tokenData = result.payload;
      setState(() {});
    } catch (e) {
      debugPrint(e.toString());
    }
  }

  void _checkTokenExpired() async {
    try {
      _expired = await DDT.isTokenExpired(_token, key: key);
      setState(() {});
    } catch (e) {
      debugPrint(e.toString());
    }
  }
}
0
likes
160
points
113
downloads

Publisher

verified publisherdatadirr.com

Weekly Downloads

This package helps to generate and verify authentication token.

Homepage
Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

encrypter, flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on ddt

Packages that implement ddt