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

Enterprise REST and GraphQL API client with interceptors, caching, retry logic, file upload/download, WebSocket support and more.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: ApiExampleScreen(),
    );
  }
}

class ApiExampleScreen extends StatefulWidget {
  const ApiExampleScreen({super.key});

  @override
  State<ApiExampleScreen> createState() => _ApiExampleScreenState();
}

class _ApiExampleScreenState extends State<ApiExampleScreen> {
  late ApiClient client;

  bool loading = false;
  String error = "";
  List users = [];

  @override
  void initState() {
    super.initState();

    client = ApiClient(
      config: ApiConfig(
        baseUrl: "https://jsonplaceholder.typicode.com",
      ),
      cache: MemoryCache(),
      interceptors: [
        LoggingInterceptor(),
      ],
    );
  }

  Future<void> fetchUsers() async {
    setState(() {
      loading = true;
      error = "";
    });

    try {
      final response = await client.get("/users");

      setState(() {
        users = response.data;
      });
    } catch (e) {
      setState(() {
        error = e.toString();
      });
    }

    setState(() {
      loading = false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Zeba Academy API Client"),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: fetchUsers,
        child: const Icon(Icons.download),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          children: [
            const Text(
              "API Client Demo",
              style: TextStyle(
                fontSize: 22,
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(height: 16),

            if (loading)
              const CircularProgressIndicator(),

            if (error.isNotEmpty)
              Text(
                error,
                style: const TextStyle(color: Colors.red),
              ),

            Expanded(
              child: ListView.builder(
                itemCount: users.length,
                itemBuilder: (context, index) {
                  final user = users[index];

                  return Card(
                    elevation: 3,
                    margin: const EdgeInsets.symmetric(vertical: 8),
                    child: ListTile(
                      leading: const CircleAvatar(
                        child: Icon(Icons.person),
                      ),
                      title: Text(user["name"]),
                      subtitle: Text(user["email"]),
                    ),
                  );
                },
              ),
            )
          ],
        ),
      ),
    );
  }
}
0
likes
130
points
105
downloads
screenshot

Documentation

API reference

Publisher

verified publisherzeba.academy

Weekly Downloads

Enterprise REST and GraphQL API client with interceptors, caching, retry logic, file upload/download, WebSocket support and more.

Homepage

License

unknown (license)

Dependencies

http, path, web_socket_channel

More

Packages that depend on zeba_academy_api_client