flutter_api_request 0.0.1 copy "flutter_api_request: ^0.0.1" to clipboard
flutter_api_request: ^0.0.1 copied to clipboard

Using this package to easily call rest apis and get a response.

example/lib/main.dart

import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_api_request/api/ApiCallBackListener.dart';
import 'package:flutter_api_request/api/ApiRequest.dart';
import 'package:flutter_api_request/api/CommonFile.dart';
import 'package:flutter_api_request/api/HttpMethods.dart';
import 'package:flutter_api_request/api/ProgressDialog.dart';
import 'package:flutter_image_uploading/ImageHelper.dart';

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();


}

class _MyHomePageState extends State<MyHomePage> implements ApiCallBackListener{
  int _counter = 0;
  Future logout() async {
    print('logout');

    await Future.delayed(const Duration(seconds: 5),(){
      print(" logout successful");
    });
  }

  apiCall() {
    ApiRequest(
      context: context,
      apiCallBackListener: this,
      showLoader: true,
      httpType: HttpMethods.POST,
      url: "https://abc.cmsbox.in/api/connectionList",
      apiAction: "CONNECTION_LIST",
      logoutFunction: logout,
      headers: CommonFile.getApiHeader("vnS-w7jftlfDBPLtsfRoLE8pNpsCr78THxtNQyQaal0Cg3VyvVU1I2Bj5JBYvCQcAZ5IPcgS7kRhvk7E_yJYrKcZ_ODXdpk5OcmQzJ6wS0_srItzoDmKYIhlk8MYrLuNWGcDJTVEyxVNCCsB4WlwWKxuaPE40WVRYEUe1yfZRK--n9NUVsbFWkdXiSIQC-8ibZ93wmJxGbdbDfleHipoN9pFwMN-K4ogOtK7Dtf8R0qgaOFpu1z-DoBSJ8aqZNH__pKWbTFH67PGQRo9f1IWeW_ylGOgVnbwGmDMO-qJ4YC0x6CsUyR0XXzhpy-08oZ7HwnX8Bu_TN6x4SbYuSZ3kmdmr-_Ajjol562Yq1g9E3ZusluGyFXX7QCzMDY9hdH_tOHrvFrS4YuR4jTbbHoPMKpCLriIicW5_l3fhAmvd2AfP0gL5Z33remIbQTzKeg4DfomkIRc2-JaxgurPXUlm-e7wKlEOdVvMbJeXwnJUnFTcNpI9wbI2IMvO2IZIcNFuYrNGa9e3KU2FEiwb5OXpHTvcVn1HlAp2FxfYx3jczMO9FXRwqD15t-E43vl6Tsw6ET0qzWljFMV8PZdxfpA0tZ_fjrmBfmTkQmqVJKfT0X2AORP-IZM2wG1KOORjp__N4TsWI2dLrmr7S3ykbkA")
    );
  }


  @override
  apiCallBackListener(String action, result) {
    // TODO: implement apiCallBackListener
    if(action=="CONNECTION_LIST"){
      Map<String, dynamic> jsonResult = JsonDecoder().convert(result);
      if (jsonResult["success"]!) {


        print("success==${jsonResult.toString()}");

      } else {
        print("Failed==");
        print(jsonResult["message"]!.toString());
      }

      return ;
    }else
    if(action=="UpdateCoverProfile"){
      // return;
      Map<String, dynamic> jsonResult =  Map<String, dynamic>.from(result);
      if (jsonResult["success"]!) {
        print("success");
        print("success==$jsonResult");

      } else {
        print("Failed==");
        print(jsonResult["message"]!.toString());
      }

      return ;
    }
    throw UnimplementedError();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
             Text(
              'Api response:',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: apiCall,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  // void updateAPI() {
  //   Map<String, String> body = Map();
  //   if(!socialLogin){
  //     body["first_name"] = fullName;
  //     body["last_name"] = lastname;
  //     body["name"] = fullName+" "+lastname;
  //   }else {
  //     body["name"] = fullName;
  //   }
  //   body["email"] = email;
  //   body["license_expiry_date"] = expirationDate;
  //   body["location"] = location;
  //   body["profession"] = selectedProfessionModel.id.toString();
  //   body["specialist"] = specialist;
  //   body["about"] = about;
  //
  //   Map<String, File> mapOfFilesAndKey = Map();
  //   if (isFileExist(profileImage)) {
  //     mapOfFilesAndKey["profile_picture"] = profileImage;
  //   }
  //
  //
  //   ApiRequest(
  //     context: context,
  //     apiCallBackListener: this,
  //     showLoader: true,
  //     httpType: HttpMethods.POST,
  //     url: Url.updateProfile,
  //     apiAction: ApiAction.updateProfile,
  //     body: body,
  //     isMultiPart: true,
  //     mapOfFilesAndKey: mapOfFilesAndKey,
  //   );
  // }

  bool isFileExist(File? file) {
    return file!.existsSync();
  }

  void getImageFile() {
    ImageHelper().showPhotoBottomDialog(context, Platform.isIOS,(file)  {
      if(file!=null){
        Map<String, File> mapOfFilesAndKey = Map();
        if (isFileExist(file)) {
          mapOfFilesAndKey["cover_picture"] = file;
        }

        ApiRequest(
          context: context,
          apiCallBackListener: this,
          showLoader: true,
          httpType: HttpMethods.POST,
          url: "https://abc.cmsbox.in/api/updateCoverProfile",
          apiAction: "UpdateCoverProfile",
          isMultiPart: true,
          mapOfFilesAndKey: mapOfFilesAndKey,
          headers: CommonFile.getApiHeader("ecLeVm0vwaFxC0hMzsxCwBjcXLxZLl1n0s2xtdfdsSy8w3mdP7vhlWeWruFTkW7RAd8h6gcnHpBDjma-JaCU0pfjVaJ1WD1SEuR2LTvXPCypJpeA7XJ0qZ23dEaDl3bymeL7fmn7-pECi1fJPvu0_jk1hn8SRtTkiD1DWVyijXwi51PD-KR3eHnjjszTEWUVFFLjTGLXBcySMVWBDDdfjsee0_H2ugdz4qEDIBRi1woiiZVVSGgG7HCj3df5r68W3r8IJoBIKU0gcJTgUD6QUeV2qeF08OZDzt46ldpYUNPxaooO9xFpzgwYYrWInVUesZBuXuuIl6rYhz8pG5PGk_mox8pO_ehtbKHpGLouLfHQMAsjiSKCnJ2Rg-vpJ-llDsaHdSSD3pxLv4DIucHQLN1wqg-06LVDUXJzgnZs9wf316fF7pYHIxbAC-kW8EZF7yjRdVnbK0kJiUnvH0cODl2WY3lSX5bmocuVGEG5gjOfO4WrkT354mgeODOxktJKXnl6sCtkmirXbgm5EPtWeGTBoVykSMQPArbK2TtdmlVwl90k-Q")
        );
      }
    },

    );
  }
}
0
likes
80
pub points
0%
popularity

Publisher

unverified uploader

Using this package to easily call rest apis and get a response.

Documentation

API reference

License

unknown (LICENSE)

Dependencies

connectivity_plus, flutter, fluttertoast, http

More

Packages that depend on flutter_api_request