sid_address_verification 0.0.6 copy "sid_address_verification: ^0.0.6" to clipboard
sid_address_verification: ^0.0.6 copied to clipboard

A Source ID location tracking/ address verification Flutter package. Refer to home page for more details

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:sid_address_verification/sid_address_verification.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _sidAddressVerificationPlugin = SidAddressVerification();

  // Configuration
  final String apiKey = "sk_rd_v1_ChoPcUQjtI9pMTivjYJ9hKXop0WeXO";
  final String customerID = "6922c72132c93e397c18ffef";
  final String verificationGroupID = '689209fc5679c2b5c30e19e4';
  final String testAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
  final String testRefreshToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";

  // State for picked location
  Map<String, dynamic>? _pickedLocation;
  bool _isPickingLocation = false;
  bool _isTracking = false;
  String? _error;

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

  Future<void> _startTracking() async {
    try {
      setState(() {
        _error = null;
      });

      final success = await SidAddressVerification.startTrackingWithConfig(
        apiKey,
        customerID,
        verificationGroupID,
      );

      if (success) {
        setState(() {
          _isTracking = true;
        });
        print('Tracking started successfully');

        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('Tracking started successfully')),
        );
      }
    } catch (e) {
      setState(() {
        _error = 'Error starting tracking: $e';
      });
      print('Error starting tracking: $e');
    }
  }

  Future<void> _stopTracking() async {
    try {
      await SidAddressVerification.stopTracking();
      setState(() {
        _isTracking = false;
      });
      print('Tracking stopped');

      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Tracking stopped')),
      );
    } catch (e) {
      print('Error stopping tracking: $e');
    }
  }

  Future<void> _fetchConfig() async {
    try {
      final config = await SidAddressVerification.fetchConfiguration(
        apiKey,
        customerID,
      );
      print('Configuration: $config');

      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Config: $config')),
      );
    } catch (e) {
      print('Error fetching config: $e');
    }
  }

  Future<void> _pickLocation() async {
    print('Picking location...');

    setState(() {
      _isPickingLocation = true;
      _error = null;
    });

    try {
      final location = await SidAddressVerification.pickLocation();

      print('Picked Location: $location');

      setState(() {
        _pickedLocation = location;
        _isPickingLocation = false;
      });

      // Show success message
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(
          content: Text('Location picked successfully!'),
          backgroundColor: Colors.green,
        ),
      );
    } catch (e) {
      setState(() {
        _error = 'Error picking location: $e';
        _isPickingLocation = false;
      });
      print('Error picking location: $e');

      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Failed to pick location: $e'),
          backgroundColor: Colors.red,
        ),
      );
    }
  }

  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await SidAddressVerification.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SID Address Verification'),
          elevation: 2,
        ),
        body: SingleChildScrollView(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              // Platform Version
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Text(
                    'Running on: $_platformVersion',
                    style: Theme.of(context).textTheme.bodyMedium,
                    textAlign: TextAlign.center,
                  ),
                ),
              ),

              const SizedBox(height: 24),

              // Location Picker Section
              Text(
                '📍 Location Picker',
                style: Theme.of(context).textTheme.titleLarge,
              ),
              const SizedBox(height: 12),

              ElevatedButton.icon(
                onPressed: _isPickingLocation ? null : _pickLocation,
                icon: _isPickingLocation
                    ? const SizedBox(
                  width: 16,
                  height: 16,
                  child: CircularProgressIndicator(
                    strokeWidth: 2,
                    color: Colors.white,
                  ),
                )
                    : const Icon(Icons.map),
                label: Text(
                  _isPickingLocation ? 'Opening Map...' : 'Pick Location',
                ),
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.all(16),
                ),
              ),

              const SizedBox(height: 16),

// Display Picked Location
              if (_pickedLocation != null)
                Card(
                  color: Colors.green.shade50,
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            const Icon(
                              Icons.check_circle,
                              color: Colors.green,
                            ),
                            const SizedBox(width: 8),
                            Text(
                              'Selected Location',
                              style: Theme.of(context)
                                  .textTheme
                                  .titleMedium
                                  ?.copyWith(
                                color: Colors.green.shade700,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ],
                        ),
                        const Divider(height: 24),

                        // Latitude
                        _buildLocationRow(
                          'Latitude',
                          _pickedLocation!['latitude']?.toString() ?? 'N/A',
                        ),
                        const SizedBox(height: 8),

                        // Longitude
                        _buildLocationRow(
                          'Longitude',
                          _pickedLocation!['longitude']?.toString() ?? 'N/A',
                        ),
                        const SizedBox(height: 12),

                        const Divider(),
                        const SizedBox(height: 12),

                        // Full Address
                        Text(
                          'Full Address',
                          style: Theme.of(context)
                              .textTheme
                              .labelLarge
                              ?.copyWith(fontWeight: FontWeight.bold),
                        ),
                        const SizedBox(height: 4),
                        Text(
                          _pickedLocation!['fullAddress']?.toString() ?? 'N/A',
                          style: Theme.of(context).textTheme.bodyMedium,
                        ),

                        // Street (if available)
                        if (_pickedLocation!['street'] != null) ...[
                          const SizedBox(height: 12),
                          Text(
                            'Street',
                            style: Theme.of(context)
                                .textTheme
                                .labelLarge
                                ?.copyWith(fontWeight: FontWeight.bold),
                          ),
                          const SizedBox(height: 4),
                          Text(
                            _pickedLocation!['street']?.toString() ?? 'N/A',
                            style: Theme.of(context).textTheme.bodyMedium,
                          ),
                        ],

                        // City (if available)
                        if (_pickedLocation!['city'] != null) ...[
                          const SizedBox(height: 12),
                          Text(
                            'City',
                            style: Theme.of(context)
                                .textTheme
                                .labelLarge
                                ?.copyWith(fontWeight: FontWeight.bold),
                          ),
                          const SizedBox(height: 4),
                          Text(
                            _pickedLocation!['city']?.toString() ?? 'N/A',
                            style: Theme.of(context).textTheme.bodyMedium,
                          ),
                        ],

                        // State (if available)
                        if (_pickedLocation!['state'] != null) ...[
                          const SizedBox(height: 12),
                          Text(
                            'State',
                            style: Theme.of(context)
                                .textTheme
                                .labelLarge
                                ?.copyWith(fontWeight: FontWeight.bold),
                          ),
                          const SizedBox(height: 4),
                          Text(
                            _pickedLocation!['state']?.toString() ?? 'N/A',
                            style: Theme.of(context).textTheme.bodyMedium,
                          ),
                        ],

                        // Postal Code (if available)
                        if (_pickedLocation!['postalCode'] != null) ...[
                          const SizedBox(height: 12),
                          Text(
                            'Postal Code',
                            style: Theme.of(context)
                                .textTheme
                                .labelLarge
                                ?.copyWith(fontWeight: FontWeight.bold),
                          ),
                          const SizedBox(height: 4),
                          Text(
                            _pickedLocation!['postalCode']?.toString() ?? 'N/A',
                            style: Theme.of(context).textTheme.bodyMedium,
                          ),
                        ],

                        // Country (if available)
                        if (_pickedLocation!['country'] != null) ...[
                          const SizedBox(height: 12),
                          Text(
                            'Country',
                            style: Theme.of(context)
                                .textTheme
                                .labelLarge
                                ?.copyWith(fontWeight: FontWeight.bold),
                          ),
                          const SizedBox(height: 4),
                          Text(
                            _pickedLocation!['country']?.toString() ?? 'N/A',
                            style: Theme.of(context).textTheme.bodyMedium,
                          ),
                        ],
                      ],
                    ),
                  ),
                ),
              // Placeholder when no location
              if (_pickedLocation == null && !_isPickingLocation)
                Card(
                  color: Colors.grey.shade100,
                  child: Padding(
                    padding: const EdgeInsets.all(24.0),
                    child: Column(
                      children: [
                        Icon(
                          Icons.location_off,
                          size: 48,
                          color: Colors.grey.shade400,
                        ),
                        const SizedBox(height: 8),
                        Text(
                          'No location selected',
                          style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                            color: Colors.grey.shade600,
                          ),
                        ),
                        const SizedBox(height: 4),
                        Text(
                          'Tap "Pick Location" to select one',
                          style: Theme.of(context).textTheme.bodySmall?.copyWith(
                            color: Colors.grey.shade500,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),

              const SizedBox(height: 24),

              // Location Tracking Section
              Text(
                '🔄 Location Tracking',
                style: Theme.of(context).textTheme.titleLarge,
              ),
              const SizedBox(height: 12),

              Row(
                children: [
                  Expanded(
                    child: ElevatedButton(
                      onPressed: _isTracking ? null : _startTracking,
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.green,
                        padding: const EdgeInsets.all(16),
                      ),
                      child: const Text('Start'),
                    ),
                  ),
                  const SizedBox(width: 12),
                  Expanded(
                    child: ElevatedButton(
                      onPressed: _isTracking ? _stopTracking : null,
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.red,
                        padding: const EdgeInsets.all(16),
                      ),
                      child: const Text('Stop'),
                    ),
                  ),
                ],
              ),

              if (_isTracking)
                Padding(
                  padding: const EdgeInsets.only(top: 12),
                  child: Card(
                    color: Colors.green.shade50,
                    child: Padding(
                      padding: const EdgeInsets.all(12.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          const Icon(
                            Icons.radio_button_checked,
                            color: Colors.green,
                            size: 16,
                          ),
                          const SizedBox(width: 8),
                          Text(
                            'Tracking Active',
                            style: TextStyle(
                              color: Colors.green.shade700,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),

              const SizedBox(height: 24),

              // Other Actions
              Text(
                '⚙️ Other Actions',
                style: Theme.of(context).textTheme.titleLarge,
              ),
              const SizedBox(height: 12),

              OutlinedButton(
                onPressed: _fetchConfig,
                style: OutlinedButton.styleFrom(
                  padding: const EdgeInsets.all(16),
                ),
                child: const Text('Fetch Configuration'),
              ),

              // Error Display
           /*   if (_error != null)
                Padding(
                  padding: const EdgeInsets.only(top: 16),
                  child: Card(
                    color: Colors.red.shade50,
                    child: Padding(
                      padding: const EdgeInsets.all(12.0),
                      child: Row(
                        children: [
                          const Icon(Icons.error, color: Colors.red),
                          const SizedBox(width: 8),
                          Expanded(
                            child: Text(
                              _error!,
                              style: TextStyle(color: Colors.red.shade700),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),*/
            ],
          ),
        ),
      ),
    );
  }

  // Helper widget to build location info rows
  Widget _buildLocationRow(String label, String value) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          label,
          style: const TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 14,
          ),
        ),
        Text(
          value,
          style: const TextStyle(
            fontFamily: 'monospace',
            fontSize: 14,
          ),
        ),
      ],
    );
  }
}

// ============================================================================
// ALTERNATIVE: Simpler Version
// ============================================================================

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

  @override
  State<SimpleLocationPicker> createState() => _SimpleLocationPickerState();
}

class _SimpleLocationPickerState extends State<SimpleLocationPicker> {
  String _locationText = 'No location selected';

  Future<void> _pickLocation() async {
    try {
      final location = await SidAddressVerification.pickLocation();
      setState(() {
        _locationText = '''
Latitude: ${location['latitude']}
Longitude: ${location['longitude']}
Address: ${location['address']}
        ''';
      });
    } catch (e) {
      setState(() {
        _locationText = 'Error: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Location Picker')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              _locationText,
              style: const TextStyle(fontSize: 16),
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _pickLocation,
              child: const Text('Pick Location'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
274
downloads

Publisher

unverified uploader

Weekly Downloads

A Source ID location tracking/ address verification Flutter package. Refer to home page for more details

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on sid_address_verification

Packages that implement sid_address_verification