flutter_ibm_watson 0.0.1

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

flutter_ibm_watson

IBM Watson

Installation

  • Add this to your package's pubspec.yaml file:
dependencies:
  flutter_ibm_watson: "^0.0.1"
  • You can install packages from the command line: with Flutter:
$ flutter packages get
  • Import it Now in your Dart code, you can use:
 import 'package:flutter_ibm_watson/flutter_ibm_watson.dart';

Usage

Language Translator

    import 'package:flutter_ibm_watson/flutter_ibm_watson.dart';
    // or import
    import 'package:flutter_ibm_watson/language_translator/LanguageTranslator.dart';
    import 'package:flutter_ibm_watson/utils/Language.dart';
    import 'package:flutter_ibm_watson/utils/IamOptions.dart';
  • Code Flutter to translate text
IamOptions options = await IamOptions(iam_api_key: "Your ApiKey", url: "Your Url").build();
LanguageTranslator service = new LanguageTranslator(iamOptions: options);
TranslationResult translationResult = await service.translate("Your Text", Language.ENGLISH, Language.SPANISH);
print(translationResult);
  • Example
void languageTranslator(String text) async {
    IamOptions options = await IamOptions(iam_api_key: "fr8sBBKkjZidQJij6sadfxAwqwqe4S8yY_fdXmSrKZoH_F8LB", url: "https://gateway-syd.watsonplatform.net/language-translator/api").build();
    LanguageTranslator service = new LanguageTranslator(iamOptions: options);
    TranslationResult translationResult = await service.translate(text, Language.ENGLISH, Language.SPANISH);
    print(translationResult);
}

*Code Flutter to identify language

IamOptions options = await IamOptions(iam_api_key: "Your ApiKey", url: "Your Url").build();
LanguageTranslator service = new LanguageTranslator(iamOptions: options);
IdentifyLanguageResult identifyLanguageResult = await service.identifylanguage("You text to identify");
print(identifyLanguageResult);
  • Example
void identifyLanguage(String text) async {
    IamOptions options = await IamOptions(iam_api_key: "fr8sBBKkjZidQJij6sadfxAwqwqe4S8yY_fdXmSrKZoH_F8LB", url: "https://gateway-syd.watsonplatform.net/language-translator/api").build();
    LanguageTranslator service = new LanguageTranslator(iamOptions: this.options);
    IdentifyLanguageResult identifyLanguageResult = await service.identifylanguage(text);
    print(identifyLanguageResult);
}

Visual Recognition

    import 'package:flutter_ibm_watson/flutter_ibm_watson.dart';
    // or import
    import 'package:flutter_ibm_watson/visual-recognition/VisualRecognition.dart';
    import 'package:flutter_ibm_watson/utils/Language.dart';
    import 'package:flutter_ibm_watson/utils/IamOptions.dart';
  • Code Flutter for Visual Recognition Image Url
IamOptions options = await IamOptions(iam_api_key: "Your ApiKey", url: "Your Url").build();
VisualRecognition visualRecognition = new VisualRecognition(iamOptions: this.options, language: Language.ENGLISH); // Language.ENGLISH is language response 
ClassifiedImages classifiedImages = await visualRecognition.classifyImageUrl("Your Image URLS");
print(classifiedImages.getImages()[0].getClassifiers()[0].getClasses()[0].class_name);
  • Example
void visualRecognitionUrl(String url) async {
    IamOptions options = await IamOptions(iam_api_key: "PtrAMdthejasdsaqqweXpRSs3gxwQAdsasdRPNzLEnLQ", url: "https://gateway.watsonplatform.net/visual-recognition/api").build();
    VisualRecognition visualRecognition = new VisualRecognition(iamOptions: this.options, language: Language.ENGLISH);
    ClassifiedImages classifiedImages = await visualRecognition.classifyImageUrl(url);
    print(classifiedImages
        .getImages()[0]
        .getClassifiers()[0]
        .getClasses()[0]
        .class_name);
}
  • Visual Recognition File
IamOptions options = await IamOptions(iam_api_key: "Your ApiKey", url: "Your Url").build();
VisualRecognition visualRecognition = new VisualRecognition(iamOptions: this.options, language: Language.ENGLISH); // Language.ENGLISH is language response 
ClassifiedImages classifiedImages = await visualRecognition.classifyImageFile("Image File Path");
print(classifiedImages.getImages()[0].getClassifiers()[0].getClasses()[0].class_name);
  • Example
void visualRecognitionFile(File image) async {
    IamOptions options = await IamOptions(iam_api_key: "PtrAMdthejasdsaqqweXpRSs3gxwQAdsasdRPNzLEnLQ", url: "https://gateway.watsonplatform.net/visual-recognition/api").build();
    VisualRecognition visualRecognition = new VisualRecognition(
        iamOptions: this.options, language: Language.ENGLISH);
    ClassifiedImages classifiedImages =
        await visualRecognition.classifyImageFile(image.path);

    print(classifiedImages
        .getImages()[0]
        .getClassifiers()[0]
        .getClasses()[0]
        .class_name);
}

Getting Started

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

For help on editing package code, view the documentation.

[0.0.1] - TODO: 24-06-2018.

  • TODO: The flutter_ibm_watson makes it easy to integrate IBM Watson

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter_ibm_watson/flutter_ibm_watson.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Watson Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Watson Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Container(
              margin: const EdgeInsets.all(10.0),
              child: new RaisedButton(
                child: const Text('Screen Language Translator'),
                color: Theme.of(context).accentColor,
                elevation: 4.0,
                splashColor: Colors.blueGrey,
                textColor: Colors.white,
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => ScreenLanguageTranslator()),
                  );
                },
              ),
            ),
            new Container(
              margin: const EdgeInsets.all(10.0),
              child: new RaisedButton(
                child: const Text('Screen Visual Recognition'),
                color: Theme.of(context).accentColor,
                elevation: 4.0,
                splashColor: Colors.blueGrey,
                textColor: Colors.white,
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => ScreenVisualRecognition()),
                  );
                },
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: null,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class ScreenLanguageTranslator extends StatefulWidget {
  ScreenLanguageTranslator({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _ScreenLanguageTranslator createState() => new _ScreenLanguageTranslator();
}

class _ScreenLanguageTranslator extends State<ScreenLanguageTranslator> {
  IamOptions options;
  String text;
  String result = "";

  Future<Null> getOptions() async {
    this.options = await IamOptions(
            iam_api_key: "fr8sBBKkjZidQJij6HWaetAWAvzfdXmSrKZoHGF8LB",
            url:
                "https://gateway-syd.watsonplatform.net/language-translator/api")
        .build();
    print(this.options.access_token);
  }

  void languageTranslator() async {
    LanguageTranslator service =
        new LanguageTranslator(iamOptions: this.options);
    TranslationResult translationResult =
        await service.translate(this.text, Language.ENGLISH, Language.SPANISH);
    print(translationResult);
    setState(() {
      this.result = translationResult.toString();
    });
  }

  void identifyLanguage() async {
    LanguageTranslator service =
        new LanguageTranslator(iamOptions: this.options);
    IdentifyLanguageResult identifyLanguageResult = await service
        .identifylanguage("You have pushed the button this many times:s");
    print(identifyLanguageResult);
    setState(() {
      this.result = identifyLanguageResult.toString();
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    getOptions();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("IBM Watson Language Translator"),
      ),
      body: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Container(
            margin: const EdgeInsets.all(10.0),
            child: new TextField(
              decoration: new InputDecoration(
                labelText: "Enter Text",
              ),
              onChanged: (String value) {
                this.text = value;
              },
            ),
          ),
          new Container(
            margin: const EdgeInsets.all(10.0),
            child: new RaisedButton(
              child: const Text('Language Translator'),
              color: Theme.of(context).accentColor,
              elevation: 4.0,
              splashColor: Colors.blueGrey,
              textColor: Colors.white,
              onPressed: languageTranslator,
            ),
          ),
          new Container(
            margin: const EdgeInsets.all(10.0),
            child: new RaisedButton(
              child: const Text('Identify Language'),
              color: Theme.of(context).accentColor,
              elevation: 4.0,
              splashColor: Colors.blueGrey,
              textColor: Colors.white,
              onPressed: identifyLanguage,
            ),
          ),
          new Text("result: $result")
        ],
      ),
    );
  }
}

class ScreenVisualRecognition extends StatefulWidget {
  ScreenVisualRecognition({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _ScreenVisualRecognition createState() => new _ScreenVisualRecognition();
}

class _ScreenVisualRecognition extends State<ScreenVisualRecognition> {
  IamOptions options;
  File _image;
  String _text = "Loading";
  String _text2 = "";
  String url;

  Future<Null> getOptions() async {
    this.options = await IamOptions(
            iam_api_key: "PtrgxzcADASVCXCjDmalrW1gXSADDgEt533gxwQAliAnvvjDDFmNHKNzgnLQ",
            url: "https://gateway.watsonplatform.net/visual-recognition/api")
        .build();
    print(this.options.access_token);
  }

  @override
  void initState() {
    // TODO: implement initState
    getOptions();
    super.initState();
  }

  void visualRecognitionUrl() async {
    VisualRecognition visualRecognition = new VisualRecognition(
        iamOptions: this.options, language: Language.ENGLISH);
    ClassifiedImages classifiedImages =
        await visualRecognition.classifyImageUrl(this.url);
    print(classifiedImages
        .getImages()[0]
        .getClassifiers()[0]
        .getClasses()[0]
        .class_name);
    setState(() {
      _text = classifiedImages.getImages()[0].getClassifiers()[0].toString();
      _text2 = classifiedImages
          .getImages()[0]
          .getClassifiers()[0]
          .getClasses()[0]
          .class_name;
    });
  }

  void visualRecognitionFile() async {
    VisualRecognition visualRecognition = new VisualRecognition(
        iamOptions: this.options, language: Language.ENGLISH);
    ClassifiedImages classifiedImages =
        await visualRecognition.classifyImageFile(_image.path);

    print(classifiedImages
        .getImages()[0]
        .getClassifiers()[0]
        .getClasses()[0]
        .class_name);
    setState(() {
      _text = classifiedImages.getImages()[0].getClassifiers()[0].toString();
      _text2 = classifiedImages
          .getImages()[0]
          .getClassifiers()[0]
          .getClasses()[0]
          .class_name;
    });
  }

  Future getPhoto() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);

    setState(() {
      _image = image;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("IBM Watson Visual Recognition"),
      ),
      body: new SingleChildScrollView(
        child: new Container(
          // Center is a layout widget. It takes a single child and positions it
          // in the middle of the parent.
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              _image == null
                  ? new Text('Not image selected.')
                  : new Image.file(
                      _image,
                      height: 300.0,
                      width: 300.0,
                    ),
              new RaisedButton(
                child: const Text('Photo'),
                onPressed: getPhoto,
              ),
              new Text("or"),
              new Container(
                margin: const EdgeInsets.all(5.0),
                child: new TextField(
                  decoration: new InputDecoration(labelText: "Enter Url Image"),
                  onChanged: (String value) {
                    this.url = value;
                  },
                ),
              ),
              new Container(
                margin: const EdgeInsets.all(5.0),
                child: new Text(_text2,
                    style: new TextStyle(
                        fontSize: 14.0, fontWeight: FontWeight.bold)),
              ),
              new Container(
                margin: const EdgeInsets.all(5.0),
                child: new Text(_text),
              ),
              new Container(
                margin: const EdgeInsets.all(10.0),
                child: new RaisedButton(
                  child: const Text('Visual Recognition File'),
                  color: Theme.of(context).accentColor,
                  elevation: 4.0,
                  splashColor: Colors.blueGrey,
                  textColor: Colors.white,
                  onPressed: visualRecognitionFile,
                ),
              ),
              new Container(
                margin: const EdgeInsets.all(10.0),
                child: new RaisedButton(
                  child: const Text('Visual Recognition Url'),
                  color: Theme.of(context).accentColor,
                  elevation: 4.0,
                  splashColor: Colors.blueGrey,
                  textColor: Colors.white,
                  onPressed: visualRecognitionUrl,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_ibm_watson: ^0.0.1

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:flutter_ibm_watson/flutter_ibm_watson.dart';
  
Version Uploaded Documentation Archive
0.0.1 Jun 24, 2018 Go to the documentation of flutter_ibm_watson 0.0.1 Download flutter_ibm_watson 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

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

  • Dart: 2.0.0-dev.69.0
  • pana: 0.11.7
  • Flutter: 0.5.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Fix lib/visual-recognition/VisualRecognition.dart.

Analysis of lib/visual-recognition/VisualRecognition.dart reported 9 hints, including:

line 25 col 12: 'JSON' is deprecated and shouldn't be used.

line 54 col 12: 'JSON' is deprecated and shouldn't be used.

line 57 col 18: 'JSON' is deprecated and shouldn't be used.

line 97 col 12: 'JSON' is deprecated and shouldn't be used.

line 98 col 22: 'JSON' is deprecated and shouldn't be used.

Fix lib/language_translator/LanguageTranslator.dart.

Analysis of lib/language_translator/LanguageTranslator.dart reported 3 hints:

line 43 col 12: 'JSON' is deprecated and shouldn't be used.

line 108 col 34: 'JSON' is deprecated and shouldn't be used.

line 124 col 18: 'JSON' is deprecated and shouldn't be used.

Format lib/flutter_ibm_watson.dart.

Run flutter format to format lib/flutter_ibm_watson.dart.

Fix lib/utils/IamOptions.dart.

Analysis of lib/utils/IamOptions.dart reported 1 hint:

line 35 col 16: 'JSON' is deprecated and shouldn't be used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
flutter 0.0.0
http ^0.11.3+16 0.11.3+17
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.6 1.14.11
http_parser 3.1.3
meta 1.1.5 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.3
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.7
Dev dependencies
flutter_test