I am fetching some posts with image with infinite scroll. It's a simple app. But when scrolling down, after some post app has crashed. Note: I am using Getx, pagination_view,transparent_image,http packages.
here is my homescreen.dart
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
GlobalKey<PaginationViewState> paginationKey =
GlobalKey<PaginationViewState>();
return GetBuilder<PostController>(
init: PostController(),
initState: (state) {
Get.put(PostController()).fetchAllPostsList(0);
},
builder: (postCtrl) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
Text("Here some another widgret"),
PaginationView<PostDetailsModel?>(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
key: paginationKey,
paginationViewType: PaginationViewType.listView,
// padding: const EdgeInsets.all(8.0),
pageFetch: postCtrl.fetchAllPostsList,
itemBuilder: (BuildContext context,
PostDetailsModel? postDetails, int index) {
return MainPostWidgetScreen(
postDetails: postDetails,
);
},
pullToRefresh: true,
onError: (dynamic erro) => const Center(
child: Text(
"Something Went to wrong") //Image.asset(CustomIcon.error),
),
onEmpty: const Center(
child: Text("No TimeLine Post Avaialable"),
),
bottomLoader: CircularProgressIndicator(),
initialLoader: CircularProgressIndicator(),
),
],
),
),
);
});
}
}
here is my mainpostWidget
class MainPostWidgetScreen extends StatelessWidget {
final PostDetailsModel? postDetails;
const MainPostWidgetScreen({
super.key,
required this.postDetails,
});
@override
Widget build(BuildContext context) {
return GetBuilder<PostController>(
init: PostController(),
builder: (postCtrl) {
return Container(
color: Colors.white,
margin: const EdgeInsets.only(bottom: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
// ProfileImageWidget(
// imageUrl: postDetails!.updatedBy!.avatar),
Padding(
padding: const EdgeInsets.all(5.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
postDetails!.isPostedByOther!
? RichText(
text: TextSpan(children: [
TextSpan(
text: "",
recognizer: TapGestureRecognizer()
..onTap = () {
// SharedDataManageService()
// .getUserID()
// .then((ownUserId) {
// print(ownUserId);
// print(
// postDetails!.createdBy!.id);
// if (ownUserId !=
// postDetails!.createdBy!.id
// .toString()) {
// print("object");
// PageNavigationService
// .generalNavigation(
// "/FriendProfileScreen",
// arguments: postDetails!
// .createdBy!.id
// .toString(),
// );
// } else {
// ApiErrorHandleService
// .handleStatusCodeError({
// "code": 404,
// "message": "It's you",
// });
// }
// });
},
),
const TextSpan(
text: " > ",
),
TextSpan(
text: "",
recognizer: TapGestureRecognizer()
..onTap = () async {
// await SharedDataManageService()
// .getUserID()
// .then((ownUserId) {
// print(ownUserId);
// print(postDetails!.updatedBy!.id);
// if (ownUserId !=
// postDetails!.timelineOwner!.id
// .toString()) {
// PageNavigationService
// .generalNavigation(
// "/FriendProfileScreen",
// arguments: postDetails!
// .timelineOwner!.id
// .toString());
// } else {
// ApiErrorHandleService
// .handleStatusCodeError({
// "code": 404,
// "message": "It's you",
// });
// }
// });
},
)
]))
: InkWell(
onTap: () async {
// await SharedDataManageService()
// .getUserID()
// .then((ownUserId) {
// if (ownUserId !=
// postDetails!.updatedBy!.id
// .toString()) {
// PageNavigationService
// .generalNavigation(
// "/FriendProfileScreen",
// arguments: postDetails!
// .updatedBy!.id
// .toString());
// } else {
// ApiErrorHandleService
// .handleStatusCodeError({
// "code": 404,
// "message": "It's you",
// });
// }
// });
},
child: Text(
"",
),
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"${postDetails!.createdAt} .",
),
Icon(
postDetails!.privacy == 1
? Icons.public
: postDetails!.privacy == 2
? Icons.people_alt_outlined
: Icons.lock_outlined,
size: 15,
)
],
),
],
),
),
],
),
// GetBuilder<ProfileController>(
// init: ProfileController(),
// builder: (profileCtrl) {
// return Visibility(
// visible: postDetails!.createdBy!.id !=
// profileCtrl.myProfile.value!.id,
// child: InkWell(
// onTap: () {
// Get.dialog(CupertinoAlertDialog(
// title: const Text(
// "Alert!",
// ),
// content:
// const Text("Really report this post ?"),
// actions: [
// CupertinoButton(
// child: const Text("Cancel",
// style: CustomTextStyle
// .normalBoldStyle),
// onPressed: () {
// PageNavigationService.backScreen();
// }),
// CupertinoButton(
// child: const Text(
// "Report",
// style: CustomTextStyle
// .normalBoldStyleErrorColor,
// ),
// onPressed: () {
// PageNavigationService.backScreen();
// postCtrl
// .reportAPost(postDetails!.id);
// }),
// ],
// ));
// // postCtrl.reportAPost(postDetails!.id);
// },
// child: const Icon(Icons.do_not_touch)),
// );
// })
],
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.topLeft,
child: Text(
postDetails!.content ?? "",
textAlign: TextAlign.start,
),
),
),
const SizedBox(
height: 5,
),
postDetails!.images!.length == 1
? Container(
width: Get.width,
// height: double.infinity,
alignment: Alignment.center,
child: Image.network(
postDetails!.images?[0].path ?? "",
// height: double.infinity,
width: Get.width,
fit: BoxFit.scaleDown,
),
)
: Wrap(
runSpacing: 5.0,
spacing: 10.0,
crossAxisAlignment: WrapCrossAlignment.center,
runAlignment: WrapAlignment.center,
alignment: WrapAlignment.center,
children: postDetails!.images?.map((imagePath) {
return SizedBox(
width: Get.width / 2.5,
height: Get.width / 2.5,
child: FadeInImage(
placeholder: MemoryImage(kTransparentImage),
image: NetworkImage(imagePath.path ?? ""),
fit: BoxFit.cover,
),
);
}).toList() ??
[],
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
postDetails!.totalLikes! > 0
? Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Icon(
Icons.thumb_up_alt_outlined,
size: 16,
),
Text(
"${postDetails!.totalLikes}",
),
],
)
: Container(),
postDetails!.totalComments! > 0
? Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Icon(
Icons.mode_comment_outlined,
size: 16,
),
Text(
postDetails!.totalComments! > 1
? "${postDetails!.totalComments} comments"
: "${postDetails!.totalComments} comment",
),
],
)
: Container()
],
),
),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () async {
// postCtrl.tryToLikeUnlikeaPost(postDetails!.id);
// if (postDetails!.isLiked!) {
// postDetails!.isLiked = false;
// postDetails!.totalLikes =
// postDetails!.totalLikes! - 1;
// } else {
// postDetails!.isLiked = true;
// postDetails!.totalLikes =
// postDetails!.totalLikes! + 1;
// }
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.all(5.0),
child: Icon(
Icons.thumb_up_alt_outlined,
),
),
Padding(
padding: const EdgeInsets.all(5.0),
child: Text(
postDetails!.isLiked! ? "Liked" : "Like",
),
),
],
),
),
InkWell(
onTap: () {},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
Padding(
padding: EdgeInsets.all(5.0),
child: Icon(Icons.mode_comment_outlined),
),
Padding(
padding: EdgeInsets.all(5.0),
child: Text(
"Comment",
),
),
],
),
),
],
)
],
),
);
});
}
}
here is my controller
class PostController extends GetxController {
Future<List<PostDetailsModel?>> fetchAllPostsList(
int offset,
) async {
try {
return await PostApiService().getAllPostListRequest(offset);
} on SocketException catch (e) {
debugPrint('error $e');
} on Exception catch (e) {
debugPrint("$e");
}
return [];
}
}
here is my API service
class PostApiService {
Future<List<PostDetailsModel?>> getAllPostListRequest(
int offset,
) async {
// String? token = await SharedDataManageService().getToken();
Uri url = Uri.parse(
"https://api-backend.khelahobe.com.bd/api/v2/no-auth-post?offset=$offset&item_limit=20");
var headers = {
'Accept': 'application/json',
// 'Authorization': 'Bearer $token',
'Content-Type': 'application/json;charset=UTF-8',
'Charset': 'utf-8'
};
MultipartRequest request = http.MultipartRequest(
'GET',
url,
);
request.headers.addAll(headers);
StreamedResponse streamedResponse =
await request.send().timeout(Duration(seconds: 10));
var respStr = await http.Response.fromStream(streamedResponse);
// debugPrint(json.decode(json.encode(respStr.body)));
var response = json.decode(respStr.body);
if (respStr.statusCode == 200) {
var jsonResponse = respStr.body;
var decoded = json.decode(jsonResponse);
List<PostDetailsModel?> mapdatalist = decoded["posts"]
.map<PostDetailsModel?>((b) => PostDetailsModel.fromJson(b))
.toList();
return mapdatalist;
} else {
throw {
"code": respStr.statusCode,
"message": response["message"],
};
}
}
}
here is my model
class PostDetailsModel {
int? id;
int? privacy;
String? content;
List<Images>? images;
bool? hasVideo;
bool? isLiked;
int? totalLikes;
int? totalComments;
String? createdAt;
String? updatedAt;
bool? isPostedByOther;
String? uuid;
PostDetailsModel(
{this.id,
this.privacy,
this.content,
this.images,
this.hasVideo,
this.isLiked,
this.totalLikes,
this.totalComments,
this.createdAt,
this.updatedAt,
this.isPostedByOther,
this.uuid});
PostDetailsModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
privacy = json['privacy'];
content = json['content'];
if (json['images'] != null) {
images = <Images>[];
json['images'].forEach((v) {
images!.add(Images.fromJson(v));
});
}
hasVideo = json['has_video'];
isLiked = json['is_liked'];
totalLikes = json['total_likes'];
totalComments = json['total_comments'] ?? 0;
createdAt = json['created_at'];
updatedAt = json['updated_at'];
isPostedByOther = json['is_posted_by_other'];
uuid = json['uuid'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['privacy'] = privacy;
data['content'] = content;
if (images != null) {
data['images'] = images!.map((v) => v.toJson()).toList();
}
data['has_video'] = hasVideo;
data['is_liked'] = isLiked;
data['total_likes'] = totalLikes;
data['total_comments'] = totalComments;
data['created_at'] = createdAt;
data['updated_at'] = updatedAt;
data['is_posted_by_other'] = isPostedByOther;
data['uuid'] = uuid;
return data;
}
}
// class TimelineOwner {
// int? id;
// String? name;
// String? gender;
// String? level;
// String? badges;
// String? address;
// String? avatar;
// String? cover;
// TimelineOwner(
// {this.id,
// this.name,
// this.gender,
// this.level,
// this.badges,
// this.address,
// this.avatar,
// this.cover});
// TimelineOwner.fromJson(Map<String, dynamic> json) {
// id = json['id'];
// name = json['name'];
// gender = json['gender'];
// level = json['level'];
// badges = json['badges'];
// address = json['address'];
// avatar = json['avatar'];
// cover = json['cover'];
// }
// Map<String, dynamic> toJson() {
// final Map<String, dynamic> data = <String, dynamic>{};
// data['id'] = id;
// data['name'] = name;
// data['gender'] = gender;
// data['level'] = level;
// data['badges'] = badges;
// data['address'] = address;
// data['avatar'] = avatar;
// data['cover'] = cover;
// return data;
// }
// }
//
class Images {
int? id;
String? path;
Images({this.id, this.path});
Images.fromJson(Map<String, dynamic> json) {
id = json['id'];
path = json['path'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['path'] = path;
return data;
}
}
This is very simple app, then why has it crashed ? When it has crashed, it showed me that type of error in iOS
* thread #19, name = 'io.worker.1', stop reason = EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=2098 MB)
frame #0: 0x00000001fe6270a8 libsystem_platform.dylib`_platform_memmove + 88
libsystem_platform.dylib`:
-> 0x1fe6270a8 <+88>: stnp q0, q1, [x3]
0x1fe6270ac <+92>: add x3, x3, #0x20
0x1fe6270b0 <+96>: ldnp q0, q1, [x1]
0x1fe6270b4 <+100>: add x1, x1, #0x20
Target 0: (Runner) stopped.
In Android, it just but no error show on log.