flutter_telegram_gateway 0.0.2 copy "flutter_telegram_gateway: ^0.0.2" to clipboard
flutter_telegram_gateway: ^0.0.2 copied to clipboard

A Flutter package for easy interaction with the Telegram Gateway API.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: VerificationScreen(),
    );
  }
}

class VerificationScreen extends StatefulWidget {
  @override
  _VerificationScreenState createState() => _VerificationScreenState();
}

class _VerificationScreenState extends State<VerificationScreen> {
  final TextEditingController _phoneNumberController = TextEditingController();
  String? _requestId;
  String? _errorMessage;

  late TelegramGatewayApi telegramApi;

  @override
  void initState() {
    telegramApi = TelegramGatewayApi(token: '<YOUR_TOKEN_HERE>');
    super.initState();
  }

  void _sendVerification() async {
    final phoneNumber = _phoneNumberController.text;

    final verificationResponse = await telegramApi.sendVerificationMessage(
      phoneNumber: phoneNumber,
    );

    setState(() {
      if (verificationResponse.result?.requestId != null) {
        _requestId = verificationResponse.result?.requestId;
        _errorMessage = null;
      } else {
        _errorMessage = 'Failed to send verification message.';
      }
    });
  }

  void _checkVerification() async {
    final code = '1234'; // This should be taken from the user input

    if (_requestId != null) {
      final verificationStatus = await telegramApi.checkVerificationStatus(
          requestId: _requestId!, code: code);

      setState(() {
        if (verificationStatus.result?.verificationStatus?.codeValid ?? false) {
          _errorMessage = 'Code verified successfully!';
        } else {
          _errorMessage = 'Failed to verify the code.';
        }
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Telegram Gateway API')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            TextField(
              controller: _phoneNumberController,
              decoration: const InputDecoration(labelText: 'Phone Number'),
              keyboardType: TextInputType.phone,
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _sendVerification,
              child: const Text('Send Verification'),
            ),
            const SizedBox(height: 20),
            if (_requestId != null) ...[
              Text('Verification Request ID: $_requestId'),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: _checkVerification,
                child: const Text('Verify Code'),
              ),
            ],
            if (_errorMessage != null) ...[
              const SizedBox(height: 20),
              Text(
                _errorMessage!,
                style: const TextStyle(color: Colors.red),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
2
likes
150
points
19
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for easy interaction with the Telegram Gateway API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on flutter_telegram_gateway