fh_sdk 0.6.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 57

fh_sdk

Unofficial flutter plugin for Red Hat Mobile. This plugin uses both Android and iOS Red Hat Mobile SDK, you can find further information herehttps://access.redhat.com/documentation/en-us/red_hat_mobile_application_platform_hosted/3/html/client_sdk/.

Usage

Prior to importing the plugin make sure your configuration files for Android and iOS are placed in the default location for each platform. As part of this plugin we provide an example project already set up with a dummy configuration file.

Importing the plugin

Import package:fh_sdk/fh_sdk.dart, instantiate FH and invoke one of the supported operations as in the following example. Take into account that you have to initialize the plugin before invoking any other operation.

Example of initialization:

import 'package:fh_sdk/fh_sdk.dart';

String result;
String message = 'Init call running';

try {
    result = await FhSdk.init();
    print('initResult' + result);
    message = result.toString();
} on PlatformException catch (e) {
    message = 'Error in FH Init $e';
}

You will find links to the API docs on the pub page.

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.6.6

  • Fixing misleading log trace at cloud call handler in android

0.6.5

  • Fixing annoying problem related to Future types

0.6.4

  • Fixing documentation

0.6.3

  • Fixed error in Android that manifested surfacing authentication

0.6.2

  • Push notifications added for iOS, example clean up

0.6.1

  • First published release, covers init, auth, cloud, getCloudUrl for Android and iOS

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fh_sdk/fh_sdk.dart';

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

class TitleSection extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Container(
      padding: const EdgeInsets.fromLTRB(32.0, 24.0, 32.0, 24.0),
      child: new Row(
        children: [
          new Expanded(
            child: new Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                new Text(
                  'This is just and example Flutter app using the hello endpoint. Please, type something (your name for instance) and hit the button',
                  style: new TextStyle(
                    color: Colors.grey[500],
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}

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

class _MyAppState extends State<MyApp> {
  // Change this to match your Authentication Policy on Red Hat Mobile if you plan to test authentication
  static const String AUTH_POLICY = 'flutter';

  BuildContext _context;

  bool _sdkInit = false;

  @override
  initState() {
    super.initState();
    initPlugin(); // Init plugin lowlevel
    initSDK(); // Init Red Hat Mobile SDK
  }

  // This method takes care of push notifications
  void notificationHandler (MethodCall call) {
    assert(call != null);
    if ('push_message_received' == call.method) {
        print ('push_message_received ' + call.toString());
        if (call.arguments != null && call.arguments['userInfo'] != null) {
          var userInfo = call.arguments['userInfo'];
          showSnackBarMessage(userInfo['aps']['alert']['body']);
        } else {
          showSnackBarMessage(call.toString());
        }
      }
  }

  // Initialize plugin this allows us to receive push notification messages
  initPlugin() async {
    String message = 'Init plugin in progress...';

    try {
      FhSdk.initialize(notificationHandler);
      print('plugin channel ready');
      message = 'Plugin channel ready';
      showSnackBarMessage(message);
    } on PlatformException catch (e) {
      message = 'Error in plugin initialize method $e';
      showSnackBarMessage(message);
    }
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  initSDK() async {
    String result;
    String message = 'Init call running';

    try {
      result = await FhSdk.init();
      print('init call ' + result);
      message = result.toString();
      showSnackBarMessage(message);
      getCloudUrl();
    } on PlatformException catch (e) {
      message = 'Error in FH Init $e';
      showSnackBarMessage(message);
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _sdkInit = result != null && result.contains('SUCCESS') ? true : false;
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  getCloudUrl() async {
    String result;
    String message;

    try {
      result = await FhSdk.getCloudUrl();
      print('cloudHost' + result);
      message = result.toString();
      showSnackBarMessage(message);
    } on PlatformException catch (e) {
      message = 'Error in FH getCloudUrl $e';
      showSnackBarMessage(message);
    }
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  sayHello(String name) async {
    dynamic data;
    String message;
    
    String hello = (name == null || name.length <= 0) ? 'world' : name;

    try {
      Map<String, dynamic> options = {
        "path": "/hello?hello=" + hello.replaceAll(' ', ''),
        "method": "GET",
        "contentType": "application/json",
        "timeout": 25000 // timeout value specified in milliseconds. Default: 60000 (60s)
      };
      data = await FhSdk.cloud(options);
      print('data ==> ' + data.toString());
      message = data.toString();
      showSnackBarMessage(message);
    } on PlatformException catch (e, s) {
      print('Exception details:\n $e');
      print('Stack trace:\n $s');
      message = 'Error calling hello/';
      showSnackBarMessage(message);
    }
  }

  // Authentication test
  auth(String authPolicy, String username, String password) async {
    dynamic data;
    String message;

    try {
      data = await FhSdk.auth(authPolicy, username, password);
      message = 'Authentication success';
      showSnackBarMessage (message);
      print('auth data' + data.toString());
    } catch (e, s) {
      print('Exception details:\n $e');
      print('Stack trace:\n $s');
      message = 'Authentication error';
      showSnackBarMessage (message);
    }
  }

  // Registers for RH Mobile Push Notifications with alias and categories
  // Both parameters, alias and categories cannot be null (categories can be empty though)
  pushRegister(String alias, List<String> categories) async {
    dynamic data;
    String message;

    try {
      data = await FhSdk.pushRegisterWithAliasAndCategories(alias, categories);
      message = data.toString();
      showSnackBarMessage('Registered as: ' + alias + ' as ' + categories.toString());
      print('pushRegister data ' + data.toString());
    } on PlatformException catch (e, s) {
      print('Exception details:\n $e');
      print('Stack trace:\n $s');
      message = 'Error calling pushRegister';
      showSnackBarMessage(message);
    }
  }

  void showSnackBarMessage(String message, [int duration = 3]) {
    Scaffold.of(_context).showSnackBar(new SnackBar(
      content: new Text(message),
      duration: new Duration(seconds: duration),
    ));
  }

  @override
  Widget build(BuildContext context) {
    final TextEditingController _nameFieldController = new TextEditingController();
    final TextEditingController _usernameFieldController = new TextEditingController();
    final TextEditingController _passwordFieldController = new TextEditingController();
    final TextEditingController _categoryFieldController = new TextEditingController();
    TitleSection titleSection = new TitleSection();
    Container formSection = new Container(
      padding: const EdgeInsets.fromLTRB(20.0, 8.0, 20.0, 16.0),
      child: new Row(
        children: [
          new Expanded(
            child: new Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                new ListTile(
                  leading: const Icon(Icons.person_outline),
                  title: new TextField(
                    controller: _nameFieldController,
                    decoration: new InputDecoration(
                      hintText: "Name",
                    ),
                  ),
                ),
                new ListTile(
                  leading: const Icon(Icons.person),
                  title: new TextField(
                    controller: _usernameFieldController,
                    autocorrect: false,
                    decoration: new InputDecoration(
                      hintText: "Username",
                    ),
                  ),
                ),
                new ListTile(
                  leading: const Icon(Icons.vpn_key),
                  title: new TextField(
                    controller: _passwordFieldController,
                    obscureText: true,
                    autocorrect: false,
                    decoration: new InputDecoration(
                      hintText: "Password",
                    ),
                  ),
                ),
                new ListTile(
                  leading: const Icon(Icons.category),
                  title: new TextField(
                    controller: _categoryFieldController,
                    decoration: new InputDecoration(
                      hintText: "Category",
                    ),
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );

    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Red Hat MAP - Hello Test'),
          ),
          //floatingActionButton: new FloatingActionButton(
          //  tooltip: 'Add', // used by assistive technologies
          //  child: new Icon(Icons.add),
          //  onPressed: null,
          //),
          body: new Builder(
            // Create an inner BuildContext so that the onPressed methods
            // can refer to the Scaffold with Scaffold.of().
            builder: (BuildContext context) {
              _context = context;
              return new ListView(children: [
              titleSection,
              formSection,
              const Divider(
                height: 1.0,
              ),
              new Container(
                  padding: const EdgeInsets.fromLTRB(32.0, 28.0, 32.0, 8.0),
                  child: new RaisedButton(
                      child: new Text(_sdkInit ? 'Say Hello to Username' : 'Init in progress...'),
                      color: Theme.of(context).primaryColor,
                      textColor: Colors.white,
                      onPressed: !_sdkInit ? null : () {
                              // Perform some action
                              sayHello(_nameFieldController.text);
                      }
                  )
              ),
              new Container(
                  padding: const EdgeInsets.fromLTRB(32.0, 8.0, 32.0, 8.0),
                  child: new RaisedButton(
                      child: new Text(_sdkInit ? 'Test auth' : 'Init in progress...'),
                      color: Theme.of(context).primaryColor,
                      textColor: Colors.white,
                      onPressed: !_sdkInit ? null : () {
                              auth(AUTH_POLICY, _usernameFieldController.text,  _passwordFieldController.text);
                      }
                  )
              ),
              new Container(
                  padding: const EdgeInsets.fromLTRB(32.0, 8.0, 32.0, 8.0),
                  child: new RaisedButton(
                      child: new Text(_sdkInit ? 'Register for push notifications' : 'Init in progress...'),
                      color: Theme.of(context).primaryColor,
                      textColor: Colors.white,
                      onPressed: !_sdkInit  ? null : () {
                              // Perform some action
                              pushRegister(_usernameFieldController.text, [_categoryFieldController.text]);
                      }
                  )
              )
            ]);
          })),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fh_sdk: ^0.6.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fh_sdk/fh_sdk.dart';
  
Version Uploaded Documentation Archive
0.6.6 May 5, 2018 Go to the documentation of fh_sdk 0.6.6 Download fh_sdk 0.6.6 archive
0.6.5 Apr 26, 2018 Go to the documentation of fh_sdk 0.6.5 Download fh_sdk 0.6.5 archive
0.6.4 Apr 22, 2018 Go to the documentation of fh_sdk 0.6.4 Download fh_sdk 0.6.4 archive
0.6.3 Apr 22, 2018 Go to the documentation of fh_sdk 0.6.3 Download fh_sdk 0.6.3 archive
0.6.2 Apr 18, 2018 Go to the documentation of fh_sdk 0.6.2 Download fh_sdk 0.6.2 archive
0.6.1 Apr 16, 2018 Go to the documentation of fh_sdk 0.6.1 Download fh_sdk 0.6.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/fh_sdk.dart.

Run flutter format to format lib/fh_sdk.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8