kd_api_call 0.0.6 copy "kd_api_call: ^0.0.6" to clipboard
kd_api_call: ^0.0.6 copied to clipboard

outdated

A composable, multi-platform, Future-based API for HTTP requests.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:kd_api_call/kd_api_call.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Response? apiResponse;

  bool _isLoading = false;

  @override
  void initState() {
    super.initState();
    // Fetch data from internet...
    fetchData();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        // App bar...
        appBar: AppBar(
          title: const Text('Kd Api Call Example'),
        ),
        body: Center(
          child: _isLoading
              ? const CircularProgressIndicator.adaptive()
              : apiResponse == null
                  ? const Text('Something went wrong!')
                  : Text(apiResponse!.body),
        ),
      ),
    );
  }

  // Fetch data from internet...
  Future<void> fetchData() async {
    try {
      if (mounted) {
        setState(() {
          _isLoading = true;
        });
      }
      // Api request info...
      APIRequestInfoObj requestInfo = APIRequestInfoObj(
        url: "https://jsonplaceholder.typicode.com/albums/1",
        requestType: HTTPRequestType.GET,
      );

      // Call api...
      apiResponse = await ApiCall.callService(requestInfo: requestInfo);
    } catch (e) {
      // Show error in snack bar...
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text(e.toString()),
        ),
      );
    } finally {
      if (mounted) {
        setState(() {
          _isLoading = false;
        });
      }
    }
  }
}
9
likes
0
points
400
downloads

Publisher

verified publishersutariya-technologies.com

Weekly Downloads

A composable, multi-platform, Future-based API for HTTP requests.

Repository (GitLab)
View/report issues

License

unknown (license)

Dependencies

connectivity_plus, flutter, http, path

More

Packages that depend on kd_api_call