'i am making app using flutter i followed tutorial but i don't see where is error in my code

where is wrong in my code i want get post from a social site using api http.post but it not display post widget. i followed lot of tutorial but it not working please someone help me i am new with dart language . here is my code to fetch post :

Future<List<Post>> fetchPost(http.Client client) async {
  dynamic token = await FlutterSession().get("token");
  final response = await client.post(Uri.parse('https://localhost/api/posts?access_token=$token'),
      body: {
        "server_key": "",
        "type": "get_news_feed",
        "ad_id": "5",
      });

  // Use the compute function to run parsePhotos in a separate isolate.
  return compute(parsePost, response.body);
}

this is function that converts response

// A function that converts a response body into a List<Photo>.
List<Post> parsePost(String responseBody) {
  final parsed = jsonDecode(responseBody).cast<Map<String, dynamic>>();

  return parsed.map<Post>((json) => Post.fromJson(json)).toList();
}

here is my class

class Post {
  Post({
    required this.id,
    required this.postId,
    required this.userId,
    required this.recipientId,
    required this.postText,
    required this.pageId,
    required this.groupId,
    required this.eventId,
    required this.pageEventId,
    required this.postLink,
    required this.postLinkTitle,
    required this.postLinkImage,
    required this.postLinkContent,
    required this.postVimeo,
    required this.postDailymotion,
    required this.postFacebook,
    required this.postFile,
    required this.postFileName,
    required this.postFileThumb,
    required this.postYoutube,
    required this.postVine,
    required this.postSoundCloud,
    required this.postPlaytube,
    required this.postDeepsound,
    required this.postMap,
    required this.postShare,
    required this.postPrivacy,
    required this.postType,
    required this.postFeeling,
    required this.postListening,
    required this.postTraveling,
    required this.postWatching,
    required this.postPlaying,
    required this.postPhoto,
    required this.time,
    required this.registered,
    required this.albumName,
    required this.multiImage,
    required this.multiImagePost,
    required this.boosted,
    required this.productId,
    required this.pollId,
    required this.blogId,
    required this.forumId,
    required this.threadId,
    required this.videoViews,
    required this.postRecord,
    required this.postSticker,
    required this.sharedFrom,
    required this.postUrl,
    required this.parentId,
    required this.cache,
    required this.commentsStatus,
    required this.blur,
    required this.colorId,
    required this.jobId,
    required this.offerId,
    required this.fundRaiseId,
    required this.fundId,
    required this.active,
    required this.streamName,
    required this.agoraToken,
    required this.liveTime,
    required this.liveEnded,
    required this.agoraResourceId,
    required this.agoraSid,
    required this.sendNotify,
    required this.the240P,
    required this.the360P,
    required this.the480P,
    required this.the720P,
    required this.the1080P,
    required this.the2048P,
    required this.the4096P,
    required this.processing,
    required this.publisher,
    required this.limitComments,
    required this.limitedComments,
    required this.isGroupPost,
    required this.groupRecipientExists,
    required this.groupAdmin,
    required this.postIsPromoted,
    required this.postTextApi,
    required this.orginaltext,
    required this.postTime,
    required this.page,
    required this.url,
    required this.seoId,
    required this.viaType,
    required this.recipientExists,
    required this.recipient,
    required this.admin,
    required this.postPostShare,
    required this.isPostSaved,
    required this.isPostReported,
    required this.isPostBoosted,
    required this.isLiked,
    required this.isWondered,
    required this.postComments,
    required this.postShares,
    required this.postLikes,
    required this.postWonders,
    required this.isPostPinned,
    required this.getPostComments,
    required this.photoAlbum,
    required this.options,
    required this.votedId,
    required this.postFileFull,
    required this.reaction,
    required this.job,
    required this.offer,
    required this.fund,
    required this.fundData,
    required this.forum,
    required this.thread,
    required this.isStillLive,
    required this.liveSubUsers,
    required this.sharedInfo,
    required this.userData,
  });

  String id;
  String postId;
  String userId;
  String recipientId;
  String postText;
  String pageId;
  String groupId;
  String eventId;
  String pageEventId;
  String postLink;
  String postLinkTitle;
  String postLinkImage;
  String postLinkContent;
  String postVimeo;
  String postDailymotion;
  String postFacebook;
  String postFile;
  String postFileName;
  String postFileThumb;
  String postYoutube;
  String postVine;
  String postSoundCloud;
  String postPlaytube;
  String postDeepsound;
  String postMap;
  String postShare;
  String postPrivacy;
  String postType;
  String postFeeling;
  String postListening;
  String postTraveling;
  String postWatching;
  String postPlaying;
  String postPhoto;
  String time;
  String registered;
  String albumName;
  String multiImage;
  String multiImagePost;
  String boosted;
  String productId;
  String pollId;
  String blogId;
  String forumId;
  String threadId;
  String videoViews;
  String postRecord;
  dynamic postSticker;
  bool sharedFrom;
  dynamic postUrl;
  String parentId;
  String cache;
  String commentsStatus;
  String blur;
  String colorId;
  String jobId;
  String offerId;
  String fundRaiseId;
  String fundId;
  String active;
  String streamName;
  dynamic agoraToken;
  String liveTime;
  String liveEnded;
  dynamic agoraResourceId;
  String agoraSid;
  String sendNotify;
  String the240P;
  String the360P;
  String the480P;
  String the720P;
  String the1080P;
  String the2048P;
  String the4096P;
  String processing;
  Publisher publisher;
  int limitComments;
  bool limitedComments;
  bool isGroupPost;
  bool groupRecipientExists;
  bool groupAdmin;
  int postIsPromoted;
  String postTextApi;
  String orginaltext;
  String postTime;
  int page;
  String url;
  String seoId;
  String viaType;
  bool recipientExists;
  String recipient;
  bool admin;
  String postPostShare;
  bool isPostSaved;
  bool isPostReported;
  int isPostBoosted;
  bool isLiked;
  bool isWondered;
  String postComments;
  String postShares;
  String postLikes;
  String postWonders;
  bool isPostPinned;
  List<GetPostComment> getPostComments;
  List<dynamic> photoAlbum;
  List<dynamic> options;
  int votedId;
  String postFileFull;
  Reaction reaction;
  List<dynamic> job;
  List<dynamic> offer;
  List<dynamic> fund;
  List<dynamic> fundData;
  List<dynamic> forum;
  List<dynamic> thread;
  bool isStillLive;
  int liveSubUsers;
  dynamic sharedInfo;
  dynamic userData;

  factory Post.fromJson(Map<String, dynamic> json) => Post(
    id: json["id"],
    postId: json["post_id"],
    userId: json["user_id"],
    recipientId: json["recipient_id"],
    postText: json["postText"],
    pageId: json["page_id"],
    groupId: json["group_id"],
    eventId: json["event_id"],
    pageEventId: json["page_event_id"],
    postLink: json["postLink"],
    postLinkTitle: json["postLinkTitle"],
    postLinkImage: json["postLinkImage"],
    postLinkContent: json["postLinkContent"],
    postVimeo: json["postVimeo"],
    postDailymotion: json["postDailymotion"],
    postFacebook: json["postFacebook"],
    postFile: json["postFile"],
    postFileName: json["postFileName"],
    postFileThumb: json["postFileThumb"],
    postYoutube: json["postYoutube"],
    postVine: json["postVine"],
    postSoundCloud: json["postSoundCloud"],
    postPlaytube: json["postPlaytube"],
    postDeepsound: json["postDeepsound"],
    postMap: json["postMap"],
    postShare: json["postShare"],
    postPrivacy: json["postPrivacy"],
    postType: json["postType"],
    postFeeling: json["postFeeling"],
    postListening: json["postListening"],
    postTraveling: json["postTraveling"],
    postWatching: json["postWatching"],
    postPlaying: json["postPlaying"],
    postPhoto: json["postPhoto"],
    time: json["time"],
    registered: json["registered"],
    albumName: json["album_name"],
    multiImage: json["multi_image"],
    multiImagePost: json["multi_image_post"],
    boosted: json["boosted"],
    productId: json["product_id"],
    pollId: json["poll_id"],
    blogId: json["blog_id"],
    forumId: json["forum_id"],
    threadId: json["thread_id"],
    videoViews: json["videoViews"],
    postRecord: json["postRecord"],
    postSticker: json["postSticker"],
    sharedFrom: json["shared_from"],
    postUrl: json["post_url"],
    parentId: json["parent_id"],
    cache: json["cache"],
    commentsStatus: json["comments_status"],
    blur: json["blur"],
    colorId: json["color_id"],
    jobId: json["job_id"],
    offerId: json["offer_id"],
    fundRaiseId: json["fund_raise_id"],
    fundId: json["fund_id"],
    active: json["active"],
    streamName: json["stream_name"],
    agoraToken: json["agora_token"],
    liveTime: json["live_time"],
    liveEnded: json["live_ended"],
    agoraResourceId: json["agora_resource_id"],
    agoraSid: json["agora_sid"],
    sendNotify: json["send_notify"],
    the240P: json["240p"],
    the360P: json["360p"],
    the480P: json["480p"],
    the720P: json["720p"],
    the1080P: json["1080p"],
    the2048P: json["2048p"],
    the4096P: json["4096p"],
    processing: json["processing"],
    publisher: Publisher.fromJson(json["publisher"]),
    limitComments: json["limit_comments"],
    limitedComments: json["limited_comments"],
    isGroupPost: json["is_group_post"],
    groupRecipientExists: json["group_recipient_exists"],
    groupAdmin: json["group_admin"],
    postIsPromoted: json["post_is_promoted"],
    postTextApi: json["postText_API"],
    orginaltext: json["Orginaltext"],
    postTime: json["post_time"],
    page: json["page"],
    url: json["url"],
    seoId: json["seo_id"],
    viaType: json["via_type"],
    recipientExists: json["recipient_exists"],
    recipient: json["recipient"],
    admin: json["admin"],
    postPostShare: json["post_share"],
    isPostSaved: json["is_post_saved"],
    isPostReported: json["is_post_reported"],
    isPostBoosted: json["is_post_boosted"],
    isLiked: json["is_liked"],
    isWondered: json["is_wondered"],
    postComments: json["post_comments"],
    postShares: json["post_shares"],
    postLikes: json["post_likes"],
    postWonders: json["post_wonders"],
    isPostPinned: json["is_post_pinned"],
    getPostComments: List<GetPostComment>.from(json["get_post_comments"].map((x) => GetPostComment.fromJson(x))),
    photoAlbum: List<dynamic>.from(json["photo_album"].map((x) => x)),
    options: List<dynamic>.from(json["options"].map((x) => x)),
    votedId: json["voted_id"],
    postFileFull: json["postFile_full"],
    reaction: Reaction.fromJson(json["reaction"]),
    job: List<dynamic>.from(json["job"].map((x) => x)),
    offer: List<dynamic>.from(json["offer"].map((x) => x)),
    fund: List<dynamic>.from(json["fund"].map((x) => x)),
    fundData: List<dynamic>.from(json["fund_data"].map((x) => x)),
    forum: List<dynamic>.from(json["forum"].map((x) => x)),
    thread: List<dynamic>.from(json["thread"].map((x) => x)),
    isStillLive: json["is_still_live"],
    liveSubUsers: json["live_sub_users"],
    sharedInfo: json["shared_info"],
    userData: json["user_data"],
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "post_id": postId,
    "user_id": userId,
    "recipient_id": recipientId,
    "postText": postText,
    "page_id": pageId,
    "group_id": groupId,
    "event_id": eventId,
    "page_event_id": pageEventId,
    "postLink": postLink,
    "postLinkTitle": postLinkTitle,
    "postLinkImage": postLinkImage,
    "postLinkContent": postLinkContent,
    "postVimeo": postVimeo,
    "postDailymotion": postDailymotion,
    "postFacebook": postFacebook,
    "postFile": postFile,
    "postFileName": postFileName,
    "postFileThumb": postFileThumb,
    "postYoutube": postYoutube,
    "postVine": postVine,
    "postSoundCloud": postSoundCloud,
    "postPlaytube": postPlaytube,
    "postDeepsound": postDeepsound,
    "postMap": postMap,
    "postShare": postShare,
    "postPrivacy": postPrivacy,
    "postType": postType,
    "postFeeling": postFeeling,
    "postListening": postListening,
    "postTraveling": postTraveling,
    "postWatching": postWatching,
    "postPlaying": postPlaying,
    "postPhoto": postPhoto,
    "time": time,
    "registered": registered,
    "album_name": albumName,
    "multi_image": multiImage,
    "multi_image_post": multiImagePost,
    "boosted": boosted,
    "product_id": productId,
    "poll_id": pollId,
    "blog_id": blogId,
    "forum_id": forumId,
    "thread_id": threadId,
    "videoViews": videoViews,
    "postRecord": postRecord,
    "postSticker": postSticker,
    "shared_from": sharedFrom,
    "post_url": postUrl,
    "parent_id": parentId,
    "cache": cache,
    "comments_status": commentsStatus,
    "blur": blur,
    "color_id": colorId,
    "job_id": jobId,
    "offer_id": offerId,
    "fund_raise_id": fundRaiseId,
    "fund_id": fundId,
    "active": active,
    "stream_name": streamName,
    "agora_token": agoraToken,
    "live_time": liveTime,
    "live_ended": liveEnded,
    "agora_resource_id": agoraResourceId,
    "agora_sid": agoraSid,
    "send_notify": sendNotify,
    "240p": the240P,
    "360p": the360P,
    "480p": the480P,
    "720p": the720P,
    "1080p": the1080P,
    "2048p": the2048P,
    "4096p": the4096P,
    "processing": processing,
    "publisher": publisher.toJson(),
    "limit_comments": limitComments,
    "limited_comments": limitedComments,
    "is_group_post": isGroupPost,
    "group_recipient_exists": groupRecipientExists,
    "group_admin": groupAdmin,
    "post_is_promoted": postIsPromoted,
    "postText_API": postTextApi,
    "Orginaltext": orginaltext,
    "post_time": postTime,
    "page": page,
    "url": url,
    "seo_id": seoId,
    "via_type": viaType,
    "recipient_exists": recipientExists,
    "recipient": recipient,
    "admin": admin,
    "post_share": postPostShare,
    "is_post_saved": isPostSaved,
    "is_post_reported": isPostReported,
    "is_post_boosted": isPostBoosted,
    "is_liked": isLiked,
    "is_wondered": isWondered,
    "post_comments": postComments,
    "post_shares": postShares,
    "post_likes": postLikes,
    "post_wonders": postWonders,
    "is_post_pinned": isPostPinned,
    "get_post_comments": List<dynamic>.from(getPostComments.map((x) => x.toJson())),
    "photo_album": List<dynamic>.from(photoAlbum.map((x) => x)),
    "options": List<dynamic>.from(options.map((x) => x)),
    "voted_id": votedId,
    "postFile_full": postFileFull,
    "reaction": reaction.toJson(),
    "job": List<dynamic>.from(job.map((x) => x)),
    "offer": List<dynamic>.from(offer.map((x) => x)),
    "fund": List<dynamic>.from(fund.map((x) => x)),
    "fund_data": List<dynamic>.from(fundData.map((x) => x)),
    "forum": List<dynamic>.from(forum.map((x) => x)),
    "thread": List<dynamic>.from(thread.map((x) => x)),
    "is_still_live": isStillLive,
    "live_sub_users": liveSubUsers,
    "shared_info": sharedInfo,
    "user_data": userData,
  };
}

and this is my screen code



class FeedScreen extends StatefulWidget {
  const FeedScreen({Key? key}) : super(key: key);

  @override
  _FeedScreenState createState() => _FeedScreenState();
}

class _FeedScreenState extends State<FeedScreen> {


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FutureBuilder<List<Post>>(
        future: fetchPost(http.Client()),
        builder: (context, snapshot) {
          if (snapshot.hasError) {
            return const Center(
              child: Text('An error has occurred!'),
            );
          } else if (snapshot.hasData) {
            return PostList(post: snapshot.data!);
          } else {
            return const Center(
              child: CircularProgressIndicator(),
            );
          }
        },
      ),
    );
  }
}

class PostList extends StatelessWidget {
  const PostList({Key? key, required this.post}) : super(key: key);

  final List<Post> post;

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
      ),
      itemCount: post.length,
      itemBuilder: (context, index) {
        return ListTile(
          title: Text(post[index].postText.toString()),
          subtitle: Text(post[index].postText.toString()),
        );
      },
    );
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source