http_base_client 1.0.2 copy "http_base_client: ^1.0.2" to clipboard
http_base_client: ^1.0.2 copied to clipboard

outdated

A minimalistic http client wrapped around the dart HTTP package.

A minimalistic http client.

Features #

This package simplifys http requests, making it really easy and simple.

Usage #

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

import 'package:http_base_client/http_base_client.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Basic Loading Overlay',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _data = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Padding(
        padding: const EdgeInsets.all(10.0),
        child: SingleChildScrollView(
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const SizedBox(
                  height: 15,
                ),
                const Text(
                  'Press the button to fetch data',
                ),
                const SizedBox(
                  height: 25,
                ),
                Text(
                  _data,
                ),
              ],
            ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _fatchData,
        tooltip: 'fetch data',
        child: const Icon(Icons.download),
      ),
    );
  }

  Future _fatchData() async {
    /// CHECKING IF THERE IS INTERNET
    bool check = await HttpBaseClient.checkInternetConnection;

    if (check) {
      /// MAKKING A GET CALL
      var res = await HttpBaseClient.get(
          Uri.parse("https://jsonplaceholder.typicode.com/users"));

      setState(() {
        _data = jsonEncode(jsonDecode(res.payload));
      });
    }
  }
}

Additional information #

If you like this package and find it usefull, please give it a like.

0
likes
0
pub points
4%
popularity

Publisher

unverified uploader

A minimalistic http client wrapped around the dart HTTP package.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, http, universal_io

More

Packages that depend on http_base_client