sparrow_dio 0.15.1 copy "sparrow_dio: ^0.15.1" to clipboard
sparrow_dio: ^0.15.1 copied to clipboard

sparrow团队完成的对dio的封装,实现dio的async await调用以及回调方式的调用.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:sparrow_dio/sparrow_dio.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    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> {
  String _result = "get 请求示例";
  @override
  void initState() {
    super.initState();
  }

  Future _getUrl() async {
    /// async await 请求示例
    // var res = await Request.get(url: "http://www.baidu.com");
    // print(res);
    // _result = res.data;
    // setState(() {});

    /// callback 请求示例
    Request.getCallback(
      "http://www.baidu.com",
      data: {},
      queryParameters: {},
      complete: () {},
      success: (res) {
        _result = res.data;
        setState(() {});
      },
      error: (err) {},
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(child: Text(_result)),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _getUrl,
        tooltip: 'Get Url',
        child: Icon(Icons.send),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
3
likes
105
pub points
56%
popularity

Publisher

verified publishersparrow.team

sparrow团队完成的对dio的封装,实现dio的async await调用以及回调方式的调用.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

connectivity, dio, enum_to_string, flutter, pretty_dio_logger

More

Packages that depend on sparrow_dio