geophrase_flutter 1.4.1 copy "geophrase_flutter: ^1.4.1" to clipboard
geophrase_flutter: ^1.4.1 copied to clipboard

Embed Geophrase Connect in your Flutter app to capture GPS-validated delivery addresses at checkout, reducing failed deliveries for your customers.

example/lib/main.dart

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

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Geophrase Example',
      theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple)),
      home: const CheckoutScreen(),
    );
  }
}

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

  @override
  State<CheckoutScreen> createState() => _CheckoutScreenState();
}

class _CheckoutScreenState extends State<CheckoutScreen> {
  GeophraseAddress? _address;

  void _openGeophrase() {
    Navigator.of(context).push(
      MaterialPageRoute(
        fullscreenDialog: true,
        builder: (routeContext) => GeophraseConnect(
          // 'server': widget returns a short-lived token — pass it to your
          //           backend to exchange for the full address. No apiKey needed.
          // 'client': widget resolves and returns the full address directly.
          //           Requires apiKey.
          mode: 'server',

          // apiKey: 'YOUR_API_KEY', // required when mode is 'client'
          theme: 'system',          // optional — 'light' | 'dark' | 'system'
          orderId: 'ORD-98765',     // optional — your internal reference ID
          phone: '9999999999',      // optional — prefills the phone field

          onSuccess: (result) {
            Navigator.of(routeContext).pop();
            if (result is GeophraseAddress) {
              // client mode — full address returned directly
              setState(() => _address = result);
            } else if (result is GeophraseToken) {
              // server mode — POST result.token to your backend to resolve
              debugPrint('Token: ${result.token}');
            }
          },
          onError: (error) => debugPrint('Geophrase error: ${error.message}'),
          onClose: () => Navigator.of(routeContext).pop(),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Checkout')),
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            if (_address != null) ...[
              Text(_address!.contactFullName, style: Theme.of(context).textTheme.titleMedium),
              const SizedBox(height: 4),
              Text('${_address!.addressLineOne}, ${_address!.addressLineTwo}'),
              Text('${_address!.city}, ${_address!.state} ${_address!.postalCode}'),
              Text(_address!.phrase, style: const TextStyle(color: Colors.grey)),
              const SizedBox(height: 24),
            ],
            FilledButton(
              onPressed: _openGeophrase,
              child: Text(_address == null ? 'Select delivery address' : 'Change address'),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
440
downloads

Documentation

API reference

Publisher

verified publishergeophrase.com

Weekly Downloads

Embed Geophrase Connect in your Flutter app to capture GPS-validated delivery addresses at checkout, reducing failed deliveries for your customers.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, geolocator, http, package_info_plus, web, webview_flutter

More

Packages that depend on geophrase_flutter