flutter_fetch_widget 0.0.1+1 copy "flutter_fetch_widget: ^0.0.1+1" to clipboard
flutter_fetch_widget: ^0.0.1+1 copied to clipboard

Make simple http requests with a widget.

flutter_fetch_widget #

Make simple http requests with a Flutter widget.

Features #

  • Uses package http for requests
  • Allows to transform response to a data model
  • supports GET/POST methods

Getting started #

Here is a quick look at using the fetch widget:

// import 'dart:convert' as convert;
// import 'package:http/http.dart' as http;

FetchWidget<Post>(
  url: "https://jsonplaceholder.typicode.com/posts/1",
  transform: _toPost,
  builder: (model) {
    if (model.isWaiting) {
      return Text('Loading...');
    }

    if (model.isDone && model.statusCode != 200) {
      return Text(
        'Could not connect to API service. `${model.response.body}`');
    }

    return Column(
      children: <Widget>[
        Text(model.data.id),
        Text(model.data.title),
      ]
    )
  },
)
//
Post _toPost(http.Response response) {
  final json = convert.json.decode(response.body);
  return Post(json['id'], json['title']);
}

Acknowledgements #

This was inspired by https://github.com/tkh44/holen

0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Make simple http requests with a widget.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, http

More

Packages that depend on flutter_fetch_widget