flutter_fetch_widget 0.0.1+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 80

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.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:convert' as convert;

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new FetchWidget<Post>(
          url: 'https://jsonplaceholder.typicode.com/posts/1',
          transform: _toPost,
          builder: (fetchPost) {
            if (fetchPost.isWaiting) {
              return new Text('Loading...');
            }

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

            return new Column(
              children: <Widget>[
                new Text('Id: ${fetchPost.data.id}'),
                new Text('Title: ${fetchPost.data.title}'),
                new RaisedButton(
                    color: Colors.green,
                    textColor: Colors.white,
                    onPressed: () => fetchPost.doFetch(),
                    child: new Text('Refresh')),
              ],
            );
          },
        ),
      ),
    );
  }
}

Post _toPost(response) {
  final Map<String, dynamic> json = convert.json.decode(response.body);
  return new Post(json['id'], json['title']);
}

class Post {
  final int id;
  final String title;

  Post(this.id, this.title);
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_fetch_widget: ^0.0.1+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_fetch_widget/flutter_fetch_widget.dart';
  
Version Uploaded Documentation Archive
0.0.1+1 Apr 5, 2018 Go to the documentation of flutter_fetch_widget 0.0.1+1 Download flutter_fetch_widget 0.0.1+1 archive
0.0.1 Apr 5, 2018 Go to the documentation of flutter_fetch_widget 0.0.1 Download flutter_fetch_widget 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
61
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]
80
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.11.8
  • Flutter: 0.5.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
http ^0.11.3+16 0.11.3+17
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.6 1.14.11
http_parser 3.1.3
meta 1.1.5 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.3
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.8
Dev dependencies
flutter_test
test ^0.12.0