greensms 0.1.1 copy "greensms: ^0.1.1" to clipboard
greensms: ^0.1.1 copied to clipboard

Flutter SDK for GreenSMS call verification: send, receive, status API and ready-made UI widgets for phone auth by call.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:greensms/greensms.dart';

const _token = String.fromEnvironment('GREENSMS_TOKEN');
const _user = String.fromEnvironment('GREENSMS_USER');
const _pass = String.fromEnvironment('GREENSMS_PASS');

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

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

  @override
  State<GreenSmsExampleApp> createState() => _GreenSmsExampleAppState();
}

class _GreenSmsExampleAppState extends State<GreenSmsExampleApp> {
  late final GreenSmsClient _client;
  String? _lastVerifiedRequestId;

  @override
  void initState() {
    super.initState();
    _client = _createClient();
  }

  GreenSmsClient _createClient() {
    if (_token.isNotEmpty) {
      return GreenSmsClient(token: _token);
    }
    if (_user.isNotEmpty && _pass.isNotEmpty) {
      return GreenSmsClient(user: _user, pass: _pass);
    }
    throw StateError(
      'Set GREENSMS_TOKEN or GREENSMS_USER/GREENSMS_PASS via --dart-define',
    );
  }

  @override
  void dispose() {
    _client.close();
    super.dispose();
  }

  void _showMessage(String message) {
    if (!mounted) return;
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text(message)),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'GreenSMS Call Verification',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.green),
        useMaterial3: true,
      ),
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            title: const Text('GreenSMS Call Auth'),
            bottom: const TabBar(
              tabs: [
                Tab(text: 'Send', icon: Icon(Icons.call_received)),
                Tab(text: 'Receive', icon: Icon(Icons.call_made)),
              ],
            ),
          ),
          body: Column(
            children: [
              if (_lastVerifiedRequestId != null)
                MaterialBanner(
                  content: Text('Verified: $_lastVerifiedRequestId'),
                  actions: [
                    TextButton(
                      onPressed: () => setState(() => _lastVerifiedRequestId = null),
                      child: const Text('OK'),
                    ),
                  ],
                ),
              Expanded(
                child: TabBarView(
                  children: [
                    CallVerificationScreen(
                      client: _client,
                      mode: CallVerificationMode.send,
                      onVerified: (requestId) {
                        setState(() => _lastVerifiedRequestId = requestId);
                        _showMessage('Send verification OK');
                      },
                      onError: (error) => _showMessage(error.toString()),
                    ),
                    CallVerificationScreen(
                      client: _client,
                      mode: CallVerificationMode.receive,
                      onVerified: (requestId) {
                        setState(() => _lastVerifiedRequestId = requestId);
                        _showMessage('Receive verification OK');
                      },
                      onError: (error) => _showMessage(error.toString()),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
155
points
24
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter SDK for GreenSMS call verification: send, receive, status API and ready-made UI widgets for phone auth by call.

Repository (GitHub)
View/report issues

Topics

#sms #authentication #verification #api #phone

License

MIT (license)

Dependencies

flutter, http, url_launcher

More

Packages that depend on greensms