flutter_spi 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new56

Flutter Spi #

A Dio NetWork plugin

How to Use #

# add this line to your dependencies
flutter_spi: ^0.1.1

Import #

import 'package:flutter_spi/flutter_spi.dart';

RxDart Extension #

extension PGSpiRx on PGSpi {
  // object stream
  Stream<T> mapSpiObject<T>({String path}) => this
      .responseSpiJson(path: path)
      .asStream()
      .map((value) => BaseBeanEntity.fromJson(value).object<T>());
  // objects stream
  Stream<List<T>> mapSpiObjects<T>({String path}) => this
      .responseSpiJsons(path: path)
      .asStream()
      .map((value) => BaseBeanEntity.fromJsonList(value).objects<T>());
}

Bean #

class EntityFactory {
  static T generateOBJ<T>(json) {
    if (1 == 0) {
      return null;
    } else if (T.toString() == "News") {
      return News.fromJson(json) as T;
    } else {
      return null;
    }
  }
}

Example #

PGSpi(AccountAPI.login(
            {
                "type": "top",
                "key": "8093f06289133b469be6ff7ab6af1aa9"
            }
        )
    )
    .mapSpiObjects<News>(path: "data")
    .listen(
        (value) => print(value[0].authorName),
        onError: (e) {
            print((e.error as PGSpiError).message);
      },
    );
classdescription
pg_spiSpi
pg_spi_dioDio Response Convert
pg_spi_errorError
pg_spi_loggerLogger
pg_spi_managerNetWork Manage
pg_spi_responseResponse Convert
pg_spi_targetApi Enum

License #

MIT License

[0.1.1] #

* Modification Error

[0.1.0] #

* Official Version

[0.0.2] #

* Update Package Documents

[0.0.1] #

* Logger Plugin
* Error Plugin
* Serialize Plugin
* Dio Manager.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_spi/flutter_spi.dart';

import 'account_api.dart';
import 'news.dart';
import 'network/rx/rx_extension.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    // 设置解析Key和成功状态
    // PGSpiManager.shared.key = ResponseKey(
    //   data: 'result',
    //   status: 'error_code',
    //   msg: 'reason',
    //   success: 0,
    // );
    // 请求示例
    PGSpi(AccountAPI.login(
            {"type": "top", "key": "8093f06289133b469be6ff7ab6af1aa9"}))
        .mapSpiObjects<News>(path: "data")
        .listen(
      (value) => print(value[0].authorName),
      onError: (e) {
        //获取失败
        print('错误:' + (e.error as PGSpiError).message);
      },
    );

    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

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

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(child: Text('Dio Extension')),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_spi: ^0.1.1

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_spi/flutter_spi.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
12
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]
56
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_spi that is a package requiring null.

Package not compatible with runtime flutter-web on web

Because:

  • package:flutter_spi/flutter_spi.dart that imports:
  • package:flutter_spi/src/pg_spi_dio.dart that imports:
  • package:dio/native_imp.dart that imports:
  • package:dio/src/entry/dio_for_native.dart that imports:
  • package:dio/src/adapters/io_adapter.dart that imports:
  • dart:io

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
dio ^3.0.9 3.0.9
flutter 0.0.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
http_parser 3.1.4
meta 1.1.8 1.2.2
path 1.7.0
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test