releans_verify 0.0.1 copy "releans_verify: ^0.0.1" to clipboard
releans_verify: ^0.0.1 copied to clipboard

PlatformAndroidiOS
outdated

releans sms plugin

example/lib/main.dart

import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:releans_verify/models/releans_result.dart';
import 'package:releans_verify/releans_sms.dart';

void main() {
  ReleansSms().init(
      apiKey: "f22189107e095e78c97dc7e9810df017",
      sender: "GvB9RO37N1aM75AdWmpnyxV80");
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  var tf1 = TextEditingController();
  var tf2 = TextEditingController();

  String sendingMsg = "";
  String verifyMsg = "";

  bool isErrorSending = false;
  bool isErrorVerify = false;
  bool isVerified = false;

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

  @override
  Widget build(BuildContext context) {
    tf1.text = "+971527827667";
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Releans Verify'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(10.0),
          child: Column(
            children: [
              const SizedBox(height: 20),
              Row(
                children: [
                  Expanded(
                      child: TextField(
                    controller: tf1,
                    decoration: const InputDecoration(
                      focusedBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.grey, width: 1.0),
                      ),
                      enabledBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.grey, width: 1.0),
                      ),
                      hintText: 'Mobile Number',
                    ),
                  )),
                  const SizedBox(width: 15),
                  ElevatedButton(
                    onPressed: () async {
                      ReleansResult result =
                          await ReleansSms().sendCode(mobile: tf1.text.trim());
                      log("result ${result.message}");
                      setState(() {
                        sendingMsg = result.message!;
                        isErrorSending = !result.isSuccess();
                      });
                    },
                    child: const Text("Send"),
                  ),
                ],
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(
                  sendingMsg,
                  style: TextStyle(
                      color: isErrorSending ? Colors.red : Colors.green),
                ),
              ),
              const Divider(),
              Row(
                children: [
                  Expanded(
                      child: TextField(
                    controller: tf2,
                    decoration: const InputDecoration(
                      focusedBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.grey, width: 1.0),
                      ),
                      enabledBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.grey, width: 1.0),
                      ),
                      hintText: 'Code',
                    ),
                  )),
                  const SizedBox(width: 15),
                  ElevatedButton(
                    onPressed: () async {
                      var result = await ReleansSms().verifyCode(
                          code: tf2.text.trim(), mobile: tf1.text.trim());
                      log("result ${result.message}");
                      setState(() {
                        verifyMsg = result.message!;
                        isErrorVerify = !result.isSuccess();
                      });
                    },
                    child: const Text("Verify"),
                  ),
                ],
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(
                  verifyMsg,
                  style: TextStyle(
                      color: isErrorSending ? Colors.red : Colors.green),
                ),
              ),
              const SizedBox(height: 20),
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(isVerified ? "Verified" : "Unverified"),
                  Icon(isVerified
                      ? Icons.verified_user
                      : Icons.verified_user_outlined),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}