i have this problem, i make an http request on an api, and i am supposed to display a simple message when i have situation = 0 in the response, and it works well but when in the response situation doesn’t exist i have this message and my code doesn’t execute however I specified that in the response situation may not exist. this is the message i get
Another exception was thrown: TypeError: null: type ‘Null’ is not a subtype of type ‘String’
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
class GamePage extends StatefulWidget {
String time = "";
GamePage({
super.key, //required this.mailc, required this.mdp
// required GlobalKey<FormState> formKey,
required this.mail,
required this.password,
//required this.controllermotdepasse
});
final String mail;
final String password;
@override
State<GamePage> createState() => _GamePageState();
}
class _GamePageState extends State<GamePage> {
Future<void> container() async {
var url = Uri.parse('https://konamicash.com/vfetch_app');
var response = await http.post(url, headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
}, body: {
"adresse_mail": widget.mail,
});
if (response.statusCode == 200) {
var reponse = jsonDecode(response.body);
String? situation = reponse['situation'];
if (situation == 0) {
print('no data avalaible');
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('no game'),
),
);
} else {// here is where situation is supposed to not exist and where i get this message //Another exception was thrown: TypeError: null: type 'Null' is not a subtype of type 'String'
var image_team = reponse['image_team'];
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => team(
mail: widget.mail,
password: widget.password,
team: image_team),
// TestVfetch(mail: widget.mail, password: widget.password),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
animation =
CurvedAnimation(parent: animation, curve: Curves.ease);
return FadeTransition(
opacity: animation,
child: child,
);
}),
);
}
print(reponse);
}
}
}
3
var image_team = reponse.containsKey('image_team')?reponse['image_team']:'';
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => team(
mail: widget.mail,
password: widget.password,
team: image_team),
// TestVfetch(mail: widget.mail, password: widget.password),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
animation =
CurvedAnimation(parent: animation, curve: Curves.ease);
return FadeTransition(
opacity: animation,
child: child,
);
}),
);
the “image_team” key is not available in your json response
3