api_provider 1.0.5 copy "api_provider: ^1.0.5" to clipboard
api_provider: ^1.0.5 copied to clipboard

A Plugin for making api calls easier and quicker for flutter developers.

example/lib/main.dart

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

ApiProvider apiProvider = ApiProvider(baseUrl: 'http://api.example.com/');
void main() {
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  bool isLoggedIn = false;
  String? authToken = '';
  String? responseData = '';

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

  _getTokenState() async {
    String? token = await apiProvider.hasAuthToken();
    setState(() {
      authToken = token;
      isLoggedIn = token != null ? true : false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Text(isLoggedIn.toString()),
              Text(authToken.toString()),
              const SizedBox(height: 10,),
              Text(responseData.toString()),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            var response = await apiProvider.post('api/v1/Data/get', data: {"page": 0, "pageSize": 10});
            setState(() {
              responseData = response.data['data'].toString();
            });
          },
          child: const Icon(Icons.network_cell),
        ),
      ),
    );
  }
}
4
likes
130
points
51
downloads

Publisher

verified publisherperitumsolution.pk

Weekly Downloads

A Plugin for making api calls easier and quicker for flutter developers.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter, flutter_secure_storage, flutter_web_plugins

More

Packages that depend on api_provider