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

outdated

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.
    );
  }
}
2
likes
0
pub points
30%
popularity

Publisher

verified publishersparrow.team

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bot_toast, connectivity, dio, flutter, sparrow_utils

More

Packages that depend on sparrow_dio