autoussdflutter 3.2.0 copy "autoussdflutter: ^3.2.0" to clipboard
autoussdflutter: ^3.2.0 copied to clipboard

PlatformAndroid
outdated

Flutter plugin for AutoUssd which allows you to build Flutter applications on top of USSD services

example/lib/main.dart

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  AutoUssdFlutter.init();

  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: "/home",
      routes: {
        "/home": (_) => HomePage(),
      },
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  _HomePageState() {
    // Initialize the SDK by passing a session execution callback
    // The native implementation works asynchronously we'll need
    // the callback to be notified of the session execution result
    AutoUssdFlutter.onSessionCount((count) {
      debugPrint("Session count: $count");
    });

    AutoUssdFlutter.onSessionResult((result) {
      debugPrint(result.status.toString());

      if (result.status == ResultStatus.COMPLETED) {
        Future.microtask(() {
          showDialog(
            context: context,
            builder: (context) {
              return AlertDialog(
                content: Text(
                  result.lastContent ?? "Please wait for a confirmation message",
                ),
                actions: [
                  TextButton(
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                    child: Text("Ok"),
                  ),
                ],
              );
            },
          );
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('AutoUssd Flutter Example App'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              SizedBox(
                width: 300,
                child: Text(
                  "Flutter app demonstrating the use of the AutoUssd Flutter plugin",
                  textAlign: TextAlign.center,
                ),
              ),
              const SizedBox(
                height: 24,
              ),
              SizedBox(
                width: 300,
                child: Card(
                  elevation: 8,
                  child: Padding(
                    padding: const EdgeInsets.symmetric(
                      horizontal: 16,
                      vertical: 24,
                    ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Icon(
                          Icons.info_outline_rounded,
                          size: 36,
                        ),
                        Expanded(
                          flex: 1,
                          child: Text.rich(
                            TextSpan(
                              children: [
                                TextSpan(
                                  text: "Tap on the button to check the remaining balance on your ",
                                ),
                                TextSpan(
                                  text: "Vodafone Cash wallet",
                                  style: theme.textTheme.bodyText2?.copyWith(
                                    fontWeight: FontWeight.bold,
                                  ),
                                ),
                              ],
                            ),
                            textAlign: TextAlign.center,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              const SizedBox(
                height: 24,
              ),
              SizedBox(
                width: 300,
                child: ElevatedButton(
                  onPressed: () {
                    // Execute the session with this id
                    AutoUssdFlutter.executeSession(
                      "623455ec64e7d7e68f353334",
                      [
                        "0507810870",
                        "0507810870",
                        "10",
                        "PayBuddy Text",
                      ],
                    );
                  },
                  child: const Text(
                    "Check Vodafone Momo Balance",
                  ),
                ),
              ),
              const SizedBox(
                height: 24,
              ),
              SizedBox(
                width: 300,
                child: ElevatedButton(
                  onPressed: () async {
                    final networks = await AutoUssdFlutter.getDeviceSimNetworks();
                    showDialog(
                      context: context,
                      builder: (context) {
                        return AlertDialog(
                          content: Text(
                            networks.fold(
                              "${networks.length} ",
                              (accumulator, network) {
                                return "$accumulator, Network ${network.toMap()}";
                              },
                            ),
                          ),
                        );
                      },
                    );
                  },
                  child: const Text(
                    "List Device Networks",
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
160
points
62
downloads

Publisher

verified publisherautoussd.com

Weekly Downloads

Flutter plugin for AutoUssd which allows you to build Flutter applications on top of USSD services

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on autoussdflutter