autoussdflutter 1.0.0-alpha-02 copy "autoussdflutter: ^1.0.0-alpha-02" to clipboard
autoussdflutter: ^1.0.0-alpha-02 copied to clipboard

outdated

Flutter plugin for the AutoUssd Android SDK

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;

  _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(
      (Result result) {
        // Be sure to check the status of the result before
        // processing the result
        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
                    sdk.executeSession(
                      "60a53f240000000000000000",
                    );
                  },
                  child: const Text(
                    "Check Vodafone Momo Balance",
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
6
likes
0
pub points
46%
popularity

Publisher

verified publisherautoussd.com

Flutter plugin for the AutoUssd Android SDK

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on autoussdflutter