flutter_qiniu_sdk 0.1.0+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Qiniu SDK plugin for Flutter #

pub package

A flutter plugin for Qiniu object storage sdk. Support the flexible configuration, progress and complete the callback.

Note: This plugin is still under development, and some APIs might not be available yet. Feedback welcome and Pull Requests are most welcome!

Support platform #

  • [x] Android
  • [ ] iOS

Dependency #

  • Android: qiniu-android-sdk:7.3.15
  • iOS:

Installation #

First, add flutter_qiniu_sdk as a dependency in your pubspec.yaml file.

Example #

  1. Configuration
import 'package:flutter_qiniu_sdk/flutter_qiniu_sdk.dart';

var conf = ConfigBuilder()
  ..enableRecord = true // enable breakpoint resume
  ..zone = Zone.autoZone // select zone service
  ..useHttps = true; // enable https

Qiniu.config(conf.build);
  1. Upload file
Qiniu.put(key, token, filepath, onProgress: (String key, double percent) {
  debugPrint("onProgress: $key, $percent");
}, onComplete: (String key, ResponseInfo info, String response) {
  debugPrint("onComplete: $key, $info, $response");
});
  1. Cancel upload task
Qiniu.cancel(key);

0.1.0+2 #

  • Fix some bugs

0.1.0+1 #

  • Fix health suggestions

0.1.0 #

  • Fix health suggestions

0.0.1 #

  • Initial Release

example/lib/main.dart

import 'dart:async';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_qiniu_sdk/flutter_qiniu_sdk.dart';
import 'package:flutter_qiniu_sdk/models.dart';

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

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

class _MyAppState extends State<MyApp> {
  var _tokenController = TextEditingController(
      text:
          "oBq1g3XfJwIoDr08eUMd8uDesH8hqexM_HKuEerb:vNLGUWlG-zN9g6Fq4ddz0pppHdI=:eyJjYWxsYmFja0JvZHlUeXBlIjoiYXBwbGljYXRpb24vanNvbiIsInNjb3BlIjoiZGFoZW5nLXl0OjQvWVRfSU0vMjAxOTA5MjUvTGJFWXVaekkvbmltYW1haW1hLnBpIiwiY2FsbGJhY2tVcmwiOiJodHRwOi8vamN0ZXN0LmZyZWUuaWRjZmVuZ3llLmNvbS9pbXMvY2FsbCIsImRlYWRsaW5lIjoxNTY5MzgxNjg5LCJjYWxsYmFja0JvZHkiOiJ7XCJrZXlcIjpcIiQoa2V5KVwiLFwiaGFzaFwiOlwiJChldGFnKVwiLFwiYnVja2V0XCI6XCIkKGJ1Y2tldClcIixcImZzaXplXCI6JChmc2l6ZSl9In0=");
  var _keyController = TextEditingController(text: "4/YT_IM/20190925/LbEYuZzI/nimamaima.pi");

  String _logs;
  String _filename;
  double _progress;
  String _state;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    if (!mounted) return;

    var conf = ConfigBuilder()
      ..enableRecord = true
      ..zone = Zone.autoZone
      ..useHttps = true;
    Qiniu.config(conf.build);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('QiNiu SDK plugin'),
        ),
        body: Container(
          padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text("Token:"),
                  Padding(padding: EdgeInsets.only(left: 10)),
                  Expanded(
                    child: TextField(
                      controller: _tokenController,
                      minLines: 2,
                      maxLines: 2,
                      decoration: InputDecoration.collapsed(hintText: null),
                    ),
                  )
                ],
              ),
              Divider(),
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text("Key:"),
                  Padding(padding: EdgeInsets.only(left: 10)),
                  Expanded(
                    child: TextField(
                      controller: _keyController,
                      minLines: 2,
                      maxLines: 2,
                      decoration: InputDecoration.collapsed(hintText: null),
                    ),
                  )
                ],
              ),
              Divider(),
              Row(
                children: <Widget>[
                  OutlineButton(onPressed: () => _selectFileAndUpload(), child: Text("Select file & Upload")),
                  VerticalDivider(),
                  OutlineButton(onPressed: () => _cancelUpload(), child: Text("Cancel")),
                ],
              ),
              Divider(),
              Text("file: ${_filename ?? ""}"),
              Divider(),
              Row(children: <Widget>[
                Text("progress: ${((_progress ?? 0) * 100).toInt()}%"),
                VerticalDivider(),
                Text("state: ${_state ?? ""}"),
              ]),
              Divider(),
              Expanded(child: Text(_logs ?? ""))
            ],
          ),
        ),
      ),
    );
  }

  void _selectFileAndUpload() async {
    var key = _keyController.text;
    if (key.isEmpty) {
      return;
    }
    var token = _tokenController.text;
    if (token.isEmpty) {
      return;
    }
    var filepath = await FilePicker.getFilePath();
    if (filepath == null) {
      return;
    }
    setState(() {
      _filename = filepath.substring(filepath.lastIndexOf("/") + 1);
      _state = "上传中";
    });
    Qiniu.put(key, token, filepath, onProgress: (String key, double percent) {
      debugPrint("onProgress: $key, $percent");
      setState(() {
        _progress = percent;
      });
    }, onComplete: (String key, ResponseInfo info, String response) {
      debugPrint("onComplete: $key, $info, $response");
      setState(() {
        _logs = info.toString();
        _state = info.isOK() ? "上传完成" : info.error;
      });
    });
  }

  _cancelUpload() {
    Qiniu.cancel(_keyController.text);
    setState(() {
      _state = "取消上传";
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_qiniu_sdk: ^0.1.0+2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_qiniu_sdk/flutter_qiniu_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/models.dart.

Run flutter format to format lib/models.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test