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

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() {
  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> {
  // AutoUssd Flutter SDK reference
  late final AutoUssdFlutter sdk;

  // Indicates if there are active sessions
  bool ready = false;

  _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
    sdk = AutoUssdFlutter(
      (int count) {
        setState(() {
          ready = count > 0;
        });
      },
      (Result result) {
        // Be sure to check the status of the result before
        // processing the result
        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,
              ),
              ready
                  ? SizedBox(
                      width: 300,
                      child: ElevatedButton(
                        onPressed: () {
                          // Execute the session with this id
                          sdk.executeSession(
                            "623455ec64e7d7e68f353334",
                            [
                              "0507810870",
                              "0507810870",
                              "10",
                              "PayBuddy Text",
                            ],
                          );
                        },
                        child: const Text(
                          "Check Vodafone Momo Balance",
                        ),
                      ),
                    )
                  : const CircularProgressIndicator()
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
0
pub points
38%
popularity

Publisher

verified publisherautoussd.com

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

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on autoussdflutter