flutter_baidu_imageclassify 0.0.3
flutter_baidu_imageclassify: ^0.0.3 copied to clipboard

Flutter Android iOS

flutter_baidu_imageclassify

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_baidu_imageclassify/flutter_baidu_imageclassify.dart';
import 'package:image_picker/image_picker.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  ImagePicker _imagePicker = ImagePicker();

  static StreamSubscription<String> _classifyListener;
  FlutterBaiduImageclassify _classifyPlugin = new FlutterBaiduImageclassify();

  @override
  void initState() {
    super.initState();
    initPlatformState();
    _classifyListener = _classifyPlugin.onResultCallback().listen((String result) {
      print('##########&&&&&&&&&:' + result);
    });
  }

  @override
  void dispose() {
    _classifyListener?.cancel();
    super.dispose();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterBaiduImageclassify.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            final pickedFile = await _imagePicker.getImage(source: ImageSource.camera);
            if (pickedFile != null) {
              Map<String, dynamic> map = new Map<String, String>();
              map['path'] = pickedFile.path;
              map['APP_ID'] = "APP_ID";
              map['API_KEY'] = "API_KEY";
              map['SECRET_KEY'] = "SECRET_KEY";
              map['CONNECT_TIMEOUT'] = "5000";
              map['SOCKET_TIMEOUT'] = "60000";
              map['TOP_NUM'] = "3";
              map['BAIKE_NUM'] = "5";
              String ret = await FlutterBaiduImageclassify.classify(map);
              print(ret);
            }
          },
          child: Icon(Icons.search),
        ),
      ),
    );
  }
}
1
likes
65
pub points
0%
popularity

flutter_baidu_imageclassify

Homepage

Documentation

API reference

Uploader

yangzelang@gmail.com

License

BSD (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_baidu_imageclassify