import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class Errorpage extends StatefulWidget {
const Errorpage({super.key});
@override
State<Errorpage> createState() => _ErrorpageState();
}
class _ErrorpageState extends State<Errorpage> {
@override
void initState() {
super.initState();
getval2();
Data1;
}
bool? Data1;
Future<void> getval2() async {
try {
final res = await http.get(Uri.parse("https://reqres.in/api/users/23"));
if (res.statusCode == 404) {
setState(() {
Data1 = false;
});
print(Data1);
}
} catch (e) {
print('Error fetching data: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
child: Data1 == false
? const Text("404 : PAGE NOT FOUND")
: const Text("PAGE FOUND")),
));
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter