title: How to solve the "Type Null is not a subtype of type ..." error?
body: <p>When I run the code below, it prints this error to the screen, and I don't know why:</p>
  <blockquote>
  <p>type Null is not a subtype of type int</p>
  </blockquote>
  <p>This is my model class for the data from the API:</p>
  <pre><code>class data {
    final int id;
    final String email;
    final String first_name;
    final String last_name;
    final String avatar;
  
    data({
      required this.id,
      required this.email,
      required this.first_name,
      required this.last_name,
      required this.avatar,
    });
  
    factory data.fromJson(Map&lt;String, dynamic&gt; json) {
      return data(
        id: json['id'],
        email: json['email'],
        first_name: json['first_name'],
        last_name: json['last_name'],
        avatar: json['avatar'],
      );
    }
  }
  
  </code></pre>
  <p>API calling part(this part is the calling):</p>
  <pre><code>import 'dart:async';
  import 'dart:convert';
  import 'package:api_data/models/datamodel.dart';
  import 'package:http/http.dart' as http;
  
  class ApiManager {
    Future&lt;data&gt; fetchAlbum() async {
      final response =
          await http.get(Uri.parse('https://reqres.in/api/users?page=2'));
  
      if (response.statusCode == 200) {
        // If the server did return a 200 OK response,
        // then parse the JSON.
        return data.fromJson(jsonDecode(response.body));
      } else {
        // If the server did not return a 200 OK response,
        // then throw an exception.
        throw Exception('Failed to load album');
      }
    }
  }
  </code></pre>
  <p>Main part</p>
  <pre><code>import 'package:api_data/models/datamodel.dart';
  import 'package:api_data/network/api_data.dart';
  import 'package:flutter/material.dart';
  
  class Testpage extends StatefulWidget {
    const Testpage({Key? key}) : super(key: key);
  
    @override
    _TestpageState createState() =&gt; _TestpageState();
  }
  
  class _TestpageState extends State&lt;Testpage&gt; {
    late Future&lt;data&gt; futureAlbum;
  
    @override
    void initState() {
      super.initState();
      futureAlbum = ApiManager().fetchAlbum();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(title: Text('Test2'), centerTitle: true),
        body: Center(
          child: FutureBuilder&lt;data&gt;(
            future: futureAlbum,
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                return Text(snapshot.data!.email.toString());
              } else if (snapshot.hasError) {
                return Text(&quot;${snapshot.error}&quot;);
              }
  
              // By default, show a loading spinner.
              return CircularProgressIndicator();
            },
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>I don't understand why this doesn't work properly.</p>