API auth/login erreur

31 views
Skip to first unread message

Hamza AYADA

unread,
May 28, 2019, 6:22:54 AM5/28/19
to Flutter Dev
hi every Flutter's...
i try to inser my api login in my Flutter App, and when i try to test i have error. 
like this picture:

Capture d’écran 2019-05-28 à 11.17.12.png

and this is my code :




  • LoginPage

Capture d’écran 2019-05-28 à 11.16.49.png


  • Data_helper    


    Capture d’écran 2019-05-28 à 11.16.38.png

                        

    Hugo van Galen

    unread,
    May 28, 2019, 6:46:56 AM5/28/19
    to Hamza AYADA, Flutter Dev
    The stack-trace shows the error is in login.dart, on line 30. 

    Your screenshot of the code has the line numbers cut off, but I guess the culprit is the "if (databaseHelper.status)" line. I suspect you need to strongly declare DatabaseHelper.status as an implicit boolean in stead of a dynamic var. )The if() clause expects boolean only.)

    Also, the login handling code is flawed: the `status` never gets a value assigned, so the code is likely to fail even when strongly typing it. 

    Hope this helps.

    --
    You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/fa9cf0fc-133d-4932-abd2-8e2863c44ddd%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

    Hamza AYADA

    unread,
    May 28, 2019, 7:28:27 AM5/28/19
    to Flutter Dev
    import 'dart:convert';
    import 'package:http/http.dart' as http;
    import 'package:shared_preferences/shared_preferences.dart';


    class DatabaseHelper {
    String serverUrl = "https://api.backend.dvticketing.io/auth";
    var status;
    var token ;

    loginData(String login, String password) async {
    //var bytes = utf8.encode("$password");
    //var conver64 = base64.encode(bytes);
    String myUrl = "$serverUrl/login";
    final response = await http.post(myUrl,
    headers: {
    "Content-Type" : "application/vnd.api+json",
    "Accept" : "application/vnd.api+json"
    },
    body: {
    "login" : "$login",
    "password" : "$password",
    }
    );
    var data = json.decode(response.body);
    if(status){
    print('data: ${data["token"]}');
    _save(data["token"]);

    }else{
    print('data : ${data["error"]}');
    }
    }

    _save(String token) async {
    final pref = await SharedPreferences.getInstance();
    final key = 'token';
    final value = token;
    pref.setString(key, value);
    }
    read() async {
    final pref = await SharedPreferences.getInstance();
    final key = 'token';
    final value = pref.get(key)?? 0;
    print('read : $value');
    }

    }

    Le mardi 28 mai 2019 11:46:56 UTC+1, Hugo van Galen a écrit :
    The stack-trace shows the error is in login.dart, on line 30. 

    Your screenshot of the code has the line numbers cut off, but I guess the culprit is the "if (databaseHelper.status)" line. I suspect you need to strongly declare DatabaseHelper.status as an implicit boolean in stead of a dynamic var. )The if() clause expects boolean only.)

    Also, the login handling code is flawed: the `status` never gets a value assigned, so the code is likely to fail even when strongly typing it. 

    Hope this helps.

    On Tue, 28 May 2019 at 12:22, Hamza AYADA <hamza....@gmail.com> wrote:
    hi every Flutter's...
    i try to inser my api login in my Flutter App, and when i try to test i have error. 
    like this picture:

    Capture d’écran 2019-05-28 à 11.17.12.png

    and this is my code :




    • LoginPage

    Capture d’écran 2019-05-28 à 11.16.49.png


    • Data_helper    


      Capture d’écran 2019-05-28 à 11.16.38.png

                          

      --
      You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.
      Reply all
      Reply to author
      Forward
      0 new messages