api_provider 1.0.3 api_provider: ^1.0.3 copied to clipboard
A Plugin for making api calls easier and quicker for flutter developers.
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),
),
),
);
}
}