Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

ListView.Builder Flutter with filter

$
0
0

Actually I need to list replies on a comment. Code via Laravel Rest API listed me correctly separated comments, but for every comments show same replies list.I need basically:

Comment id : 1 --> Show all replies related to comment id 1
Comment is : 2 --> Show all replies reletad to comment id 2 etc etc

My code Laravel Rest

lic function fetchCommentsreply(Request $request){        $validator = Validator::make($request->all(), [ 'video_id'    => 'required',        ],[ 'video_id.required'      => 'Video id is required',                   ]);        if (!$validator->passes()) {            return response()->json(['status'=>'error','msg'=> $this->_error_string($validator->errors()->all()) ]);        }else{            $functions = new Functions();            $limit = 10;            $replies = DB::table("comments_reply as r")            ->select(DB::raw("r.*,u.user_id,u.username,u.user_dp,IF(uv.verified='A', true, false) as isVerified"))            ->join("users as u","r.user_id","u.user_id")            ->join("comments as c","c.comment_id","r.comment_id")            ->leftJoin('user_verify as uv', function ($join){                $join->on('uv.user_id','=','r.user_id')                ->where('uv.verified','A');            })            ->where("r.video_id",$request->video_id)            ->where("r.active",1)            ->orderBy("r.added_on","desc")            ->paginate($limit);            $total_records=$replies->total();                                          $data= array();            if(count($replies) > 0) {                foreach($replies as $key => $reply) {                    $data[$key]['name'] = $reply->username;                    if(stripos($reply->user_dp,'https://')!==false){                        $file_path=$reply->user_dp;                    }else{                        $file_path = asset(Storage::url('public/profile_pic/'.$reply->user_id."/small/".$reply->user_dp));                        if($file_path==""){                            $file_path=asset('default/default.png');                        }                    }                    $data[$key]['pic'] = $file_path;                    $data[$key]['reply'] = strip_tags((strlen($reply->reply) > 100) ? mb_substr($reply->reply,0,100).'..' : $reply->reply);                    $data[$key]['reply_id'] = $reply->reply_id;                    $data[$key]['comment_id'] = $reply->comment_id;                    $data[$key]['user_id'] = $reply->user_id;                    $data[$key]['isVerified'] = $reply->isVerified;                    $data[$key]['timing'] = Functions::time_elapsed_string($reply->added_on);                }            }            $response = array("status" => "success", "data" => $data,'total_records'=>$total_records);            return response()->json($response);        }    }

Flutter view Code

Container (        padding: EdgeInsetsDirectional.only(start: 30,),        child:   (videoRepo.homeCon.value.replies.length > 0)            ? Padding( padding: videoRepo.homeCon.value.replies.length > 5           ? currentUser.value.token != ''             ? EdgeInsets.only(bottom: 0) : EdgeInsets.zero : EdgeInsets.zero,           child: ListView.builder(             shrinkWrap: true,              controller: videoRepo.homeCon.value.scrollController,               padding:EdgeInsets.zero,                scrollDirection: Axis.vertical,          itemCount: videoRepo.homeCon.value.replies.length,           itemBuilder:(context, i) {             return  Container(              padding: EdgeInsets.only(top: 0),                child: Column(                  children: <Widget>[                       // imothek 11.2.0 put here widgtet                  Container(                                    child: Card(                                    margin: EdgeInsetsDirectional.all(0),                                    color: Colors.transparent,                                    shape: Border(                                      top: BorderSide.none,                                      left: BorderSide.none,                                      right: BorderSide.none,                                      bottom: BorderSide.none,                                    ),                                    child:                                      ListTile(                                    /*    horizontalTitleGap: -8,                                       leading:                                        videoRepo.homeCon.value.replies.elementAt(i).userDp.isNotEmpty                                                                            ? GestureDetector (                                                                              onTap: () {                                                                                videoRepo.isOnHomePage.value = false;                                                                                videoRepo.isOnHomePage.notifyListeners();                                                                                videoRepo.isOnHomePage.value = false;                                                                                videoRepo.isOnHomePage.notifyListeners();                                                                                videoRepo.homeCon.value.hideBottomBar.value = false;                                                                                videoRepo.homeCon.value.hideBottomBar.notifyListeners();                                                                                videoRepo.homeCon.notifyListeners();                                                                                Navigator.pushReplacement(                                                                                  context,                                                                                  MaterialPageRoute(                                                                                    builder: (context) => videoRepo.homeCon.value.replies.elementAt(i).userId == userRepo.currentUser.value.userId                                                                                        ? MyProfileView()                                                                                        : UsersProfileView(                                                                                            userId: videoRepo.homeCon.value.replies.elementAt(i).userId,                                                                                          ),                                                                                  ),                                                                                );                                                                              },                                                                             child: ClipRRect(                                                                                borderRadius: BorderRadius.circular(50.0),                                                                                child: CachedNetworkImage(                                                                                  imageUrl: videoRepo.homeCon.value.replies.elementAt(i).userDp,                                                                                  height: 15.0, // imothek original was 60                                                                                  width: 15.0, // imothek original was 60                                                                                  fit: BoxFit.fitHeight,                                                                                  errorWidget: (a, b, c) {                                                                                    return Image.asset("assets/images/default-user.png",                                                                                      fit: BoxFit.cover,                                                                                    );                                                                                  },                                                                                ),                                                                              ))                                                                            :  GestureDetector (                                                                              onTap: () {                                                                                videoRepo.isOnHomePage.value = false;                                                                                videoRepo.isOnHomePage.notifyListeners();                                                                                videoRepo.isOnHomePage.value = false;                                                                                videoRepo.isOnHomePage.notifyListeners();                                                                                videoRepo.homeCon.value.hideBottomBar.value = false;                                                                                videoRepo.homeCon.value.hideBottomBar.notifyListeners();                                                                                videoRepo.homeCon.notifyListeners();                                                                                Navigator.pushReplacement(                                                                                  context,                                                                                  MaterialPageRoute(                                                                                    builder: (context) => videoRepo.homeCon.value.replies.elementAt(i).userId == userRepo.currentUser.value.userId                                                                                        ? MyProfileView()                                                                                        : UsersProfileView(                                                                                            userId: videoRepo.homeCon.value.replies.elementAt(i).userId,                                                                                          ),                                                                                  ),                                                                                );                                                                              },                                                                              child: ClipRRect(                                                                                borderRadius: BorderRadius.circular(50.0),                                                                                child: Image.asset("assets/images/default-user.png", // imothek no photo profile. Orginal was Splash.gif                                                                                  height: 15.0, // original was 50 imothek                                                                                  width: 15.0, // original was 50 imothek                                                                                  fit: BoxFit.fitWidth,                                                                                ),                                    )), */                                       title :  GestureDetector (                                                                              onTap: () {                                                                                videoRepo.isOnHomePage.value = false;                                                                                videoRepo.isOnHomePage.notifyListeners();                                                                                videoRepo.isOnHomePage.value = false;                                                                                videoRepo.isOnHomePage.notifyListeners();                                                                                videoRepo.homeCon.value.hideBottomBar.value = false;                                                                                videoRepo.homeCon.value.hideBottomBar.notifyListeners();                                                                                videoRepo.homeCon.notifyListeners();                                                                                Navigator.pushReplacement(                                                                                  context,                                                                                  MaterialPageRoute(                                                                                    builder: (context) => videoRepo.homeCon.value.replies.elementAt(i).userId == userRepo.currentUser.value.userId                                                                                        ? MyProfileView()                                                                                        : UsersProfileView(                                                                                            userId: videoRepo.homeCon.value.replies.elementAt(i).userId,                                                                                          ),                                                                                  ),                                                                                );                                                                              },                                       child:                                        RichText( // imothek 11.2.0  text: TextSpan(    children: [      TextSpan(        text: "@"+videoRepo.homeCon.value.replies.elementAt(i).userName,        style: TextStyle(               fontFamily: 'Poppins',               fontSize: 12.5,               fontWeight: FontWeight.w500,              color: themeChange.darkTheme == true ? Colors.grey : Colors.grey      )),      WidgetSpan(        child: videoRepo.homeCon.value.replies.elementAt(i).isVerified == true ?              SvgPicture.asset("assets/icons/vcomment.svg",             width: 14,          color: themeChange.darkTheme == true ? Colors.grey : Colors.grey)          :  SvgPicture.asset("assets/icons/vempty.svg",             width: 1,)       ),      TextSpan(        text: " " + videoRepo.homeCon.value.replies.elementAt(i).reply,        style : TextStyle(               fontFamily: 'Poppins',               fontSize: 12.5,               fontWeight: FontWeight.normal,               color: themeChange.darkTheme == true ? Colors.white : Colors.black,      )),  ],                                      )                                      ),   ),)     )    ),      ]      )      );                                       },                                                      ),                                                    ):Container(),      ),

Flutter controller code

 Future<void> getCommentsreply(Video videoObj) async {    replies = [];    showLoadMoreReplies = true;    page = 1;    scrollController = new ScrollController();    scrollController1 = new ScrollController();    final List<CommentreplyData> newReplies =        await replyRepo.getCommentsreply(videoObj.videoId, page);    replies.addAll(newReplies);    if (replies.length == commentObj.countreply) {      showLoadMoreComments = false;    }    scrollController.addListener(() {      if (scrollController.position.pixels ==          scrollController.position.maxScrollExtent) {        if (replies.length != commentObj.countreply && showLoadMoreReplies) {          loadMore(videoObj);        }      }    });  }

Flutter Repo Code

ValueNotifier<List<CommentreplyData>> replies = new ValueNotifier([]);Future<List<CommentreplyData>> getCommentsreply(int videoId, int page) async {  Uri uri = Helper.getUri('fetch-reply-comments');  uri = uri.replace(queryParameters: {"page": page.toString(),"video_id": videoId.toString(),  });  // try {  Map<String, String> headers = {'Content-Type': 'application/json; charset=UTF-8','Authorization': 'Bearer '+ currentUser.value.token,  };  var response = await http.post(uri, headers: headers);  print("commentsreply response.body ${response.body}");  return parseCommentsreply(json.decode(response.body)['data']);  /*} catch (e) {    print("asdasdasdasdasdas $e");    return [];  }*/}

Actually I need to list replies on a comment. Code via Laravel Rest API listed me correctly separated comments, but for every comments show same replies list.I need basically:

Comment id : 1 --> Show all replies related to comment id 1
Comment is : 2 --> Show all replies reletad to comment id 2 etc etc


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>