


--
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.
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');
}
}
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:
and this is my code :
- LoginPage
- Data_helper
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.