api_service_helper 1.0.0 copy "api_service_helper: ^1.0.0" to clipboard
api_service_helper: ^1.0.0 copied to clipboard

ApiServices in Flutter uses Dio for HTTP requests, supporting GET, POST, PUT, and DELETE methods with data, authentication, and progress tracking.

example/lib/main.dart

import 'package:api_service_helper/api_service_helper.dart'; // Import the API service helper package.
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
            seedColor:
                Colors.deepPurple), // Create a color scheme with a seed color.
        useMaterial3: true, // Enable Material 3 theme.
      ),
      home:
          const HomeScreen(), // Display the HomeScreen as the root of the app.
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    // Initialize an instance of ApiServices with a base URL.
    ApiServices myServices =
        ApiServices(baseUrl: "https://jsonplaceholder.typicode.com");

    return Scaffold(
      appBar: AppBar(
        title: const Text("Example"),
      ),
      body: ElevatedButton(
        onPressed: () {
          // Make a GET request to "/users" and handle the response.
          myServices.request(HttpMethod.get, "/users").then((response) {
            debugPrint("Response Data: ${response.data}");
          }).catchError((error) {
            debugPrint("Error: $error");
          });
        },
        child: const Text("GET"),
      ),
    );
  }
}
4
likes
160
points
28
downloads

Publisher

verified publisherthecodewisetechnology.com

Weekly Downloads

ApiServices in Flutter uses Dio for HTTP requests, supporting GET, POST, PUT, and DELETE methods with data, authentication, and progress tracking.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

dio, flutter

More

Packages that depend on api_service_helper