flutter_response_status 1.0.1

flutter_response_status #

Flutter_response_status is a package that to standardize responses in dart.

Example the use #

class AuthRepositoryExternal{

   Future<ResponseStatus<String,UserModel>> signIn(email,password) async {
    try 
    {
      //Response structure
      /*
       {
        status:true,
        message:"Login success",
        code:"LOGIN_SUCCESS",
        data:{userCode:1,userName:'Danilo Santos',userEmail:'danilocarsan@gmail.com'}
      }
      */
      
      var dio =  Dio();
      var endpoint = 'auth/sign/in';
      var response = await dio.post(endpoint,data:{
        UserModelLabels.userEmail:email,
        UserModelLabels.userPassword:password
      });
  
      Map<String,dynamic> json = convert.jsonDecode(response.data);
      
      ResponseStatus res = ResponseStatus.fromJson(json);
      
      var responseUserModel = res.copyWith<String,UserModel>();

      if (res.status)
      {
        responseUserModel.setData(UserModel.fromJson(res.data));
      }
      
      return responseUserModel;
    }
    catch (e)
    {
      return ResponseStatus(false,"No connected the server ",code:"SERVER_ERROR",dataError:e);
    }
  }

main(){

  AuthRepositoryExternal authRep = new AuthRepositoryExternal();

  authRep.signIn('danilocarsan@gmail.com','123456').then((response){
    print(response.status);
    print(response.message);
    print(response.code);
    print(response.data);
    print(response.data.userEmail);
    print(response.dataError);
  });

}

Getting Started #

For help getting started with Flutter, view online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[1.0.1] -

  • updated README and format dart files and description packages

[1.0.0+1] -

  • updated README

[1.0.0] -

  • initial release.

example/example.dart

import '../lib/flutter_response_status.dart';
import 'user_model.dart';
import 'dart:convert' as convert;

class AuthRepositoryExternal{

   Future<ResponseStatus<String,UserModel>> signIn(email,password) async {
    try 
    {
      //Response structure
      /*
       {
        status:true,
        message:"Login success",
        code:"LOGIN_SUCCESS",
        data:{userCode:1,userName:'Danilo Santos',userEmail:'danilocarsan@gmail.com'}
      }
      */
      
      var dio =  Dio();
      var endpoint = 'auth/sign/in';
      var response = await dio.post(endpoint,data:{
        UserModelLabels.userEmail:email,
        UserModelLabels.userPassword:password
      });
  
      Map<String,dynamic> json = convert.jsonDecode(response.data);
      
      ResponseStatus res = ResponseStatus.fromJson(json);
      
      var responseUserModel = res.copyWith<String,UserModel>();

      if (res.status)
      {
        responseUserModel.setData(UserModel.fromJson(res.data));
      }
      
      return responseUserModel;
    }
    catch (e)
    {
      return ResponseStatus(false,"No connected the server ",code:"SERVER_ERROR",dataError:e);
    }
  }

main(){

  AuthRepositoryExternal authRep = new AuthRepositoryExternal();

  authRep.signIn('danilocarsan@gmail.com','123456').then((response){
    print(response.status);
    print(response.message);
    print(response.code);
    print(response.data);
    print(response.data.userEmail);
    print(response.dataError);
  });

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_response_status: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_response_status/flutter_response_status.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
41
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Feb 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health issues and suggestions

Document public APIs. (-1 points)

29 out of 29 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test