Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest for pinnedpost #2203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ Route<dynamic> generateRoute(RouteSettings settings) {
);
case Routes.pinnedPostScreen:
// final Map<String, dynamic> post = settings.arguments! as Map<String, dynamic> ;
final Map<String, String> post =
settings.arguments! as Map<String, String>;
final Post post = settings.arguments! as Post;

return MaterialPageRoute(
builder: (context) => PinnedPostScreen(post: post),
Expand Down
13 changes: 7 additions & 6 deletions lib/views/after_auth_screens/feed/pinned_post_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:talawa/apptheme.dart';
import 'package:talawa/models/post/post_model.dart';

import 'package:talawa/services/size_config.dart';

Expand All @@ -11,7 +12,7 @@ class PinnedPostScreen extends StatefulWidget {

/// Contains the data of the post.
///
final Map<String, String> post;
final Post post;

@override
State<PinnedPostScreen> createState() => _PinnedPostScreenState();
Expand All @@ -29,7 +30,7 @@ class _PinnedPostScreenState extends State<PinnedPostScreen> {
Padding(
padding: const EdgeInsets.all(18.0),
child: Text(
widget.post['title']!,
widget.post.description!,
maxLines: 2,
style: AppTheme.title.copyWith(
color: Colors.white,
Expand All @@ -43,7 +44,7 @@ class _PinnedPostScreenState extends State<PinnedPostScreen> {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'${widget.post['time']!}hr',
'${widget.post.createdAt!}hr',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w200,
Expand All @@ -55,10 +56,10 @@ class _PinnedPostScreenState extends State<PinnedPostScreen> {
],
),
CachedNetworkImage(
cacheKey: widget.post['postId'],
imageUrl: (widget.post['imageUrl'] ?? '').isEmpty
cacheKey: widget.post.sId,
imageUrl: (widget.post.imageUrl ?? '').isEmpty
? 'placeHolderUrl'
: widget.post['imageUrl']!,
: widget.post.imageUrl!,
errorWidget: (context, url, error) {
return const CircularProgressIndicator();
},
Expand Down
182 changes: 61 additions & 121 deletions lib/widgets/pinned_post.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/post/post_model.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/views/after_auth_screens/feed/pinned_post_screen.dart';

/// a_line_ending_with_end_punctuation.
///
Expand All @@ -13,143 +12,84 @@ class PinnedPost extends StatelessWidget {
/// contains the pinned post.
///
final List<Post> pinnedPost;

/// a_line_ending_with_end_punctuation.
///
/// more_info_if_required
static const List<Map<String, String>> pinnedPosts = [
{
'title': 'Church Meeting',
'postId': 'hdkahfu567',
'imageUrl':
'https://i2-prod.manchestereveningnews.co.uk/incoming/article25630061.ece/ALTERNATES/s615/2_Church-PA.jpg',
'time': '1',
},
{
'title': 'Russia-Ukraine war leads to Hike in Gas prices in Europe.',
'postId': 'hfkajhk669',
'imageUrl':
'https://gdb.voanews.com/3B960F7F-786C-452C-8ABD-9D5AEEAED9D9.jpg',
'time': '3',
},
{
'title': 'Flood in near village.',
'postId': 'adadada555',
'imageUrl':
'https://www.deccanherald.com/sites/dh/files/styles/article_detail/public/articleimages/2022/08/03/file7m4trf3i92e1krs53cn6-1132513-1659475940.jpg?itok=oVs3TTP8',
'time': '3',
},
{
'title': 'The craze behind auto-tech stocks.',
'postId': 'nvikaebkf',
'imageUrl':
'https://akm-img-a-in.tosshub.com/businesstoday/images/assets/202303/stock-market-02136-4-sixteen_nine.jpg',
'time': '7',
},
{
'title': 'High seas treaty',
'postId': 'nfqbkbd',
'imageUrl':
'https://ichef.bbci.co.uk/news/976/cpsprodpb/A194/production/_128846314_humpbackwhale.jpg',
'time': '5',
},
{
'title': 'WWE Wrestking and Gambling',
'postId': 'dadadada',
'imageUrl':
'https://staticc.sportskeeda.com/editor/2023/03/a9b3a-16783664764772-1920.jpg',
'time': '6',
},
{
'title': 'Dead of Silicon Valley Bank.',
'postId': 'hfkaaddadajhk669',
'imageUrl':
'https://thechainsaw.com/wp-content/uploads/2023/03/2023-50.jpg?w=1200',
'time': '7',
},
{
'title': 'What if women were paid for chores',
'postId': 'kofapjfn',
'imageUrl':
'https://www.shethepeople.tv/wp-content/uploads/2019/06/household.png',
'time': '8',
},
{
'title': 'Debate over stocks bybacks.',
'postId': 'agdjvfhsjaf',
'imageUrl':
'https://m.wsj.net/video/20200105/wsjglossarystockbuybackssplash/wsjglossarystockbuybackssplash_640x360.jpg',
'time': '9',
},
];

@override
Widget build(BuildContext context) {
return Container(
child: pinnedPosts.isNotEmpty
key: const Key('hello'),
child: pinnedPost.isNotEmpty
? SizedBox(
height: SizeConfig.screenHeight! * 0.25,
child: ListView.builder(
itemCount: pinnedPosts.length,
shrinkWrap: true,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.only(
left: 10,
),
child: GestureDetector(
onTap: () {
// final Map<String, dynamic> arg = {"index": "$index","post": pinnedPosts};
navigationService.pushScreen(
'/pinnedpostscreen',
arguments: pinnedPosts[index],
);
},
child: SizedBox(
width: SizeConfig.screenWidth! / 4.1,
child: Column(
children: [
CachedNetworkImage(
cacheKey: pinnedPosts[index]['postId'],
imageUrl:
(pinnedPosts[index]['imageUrl'] ?? '').isEmpty
? 'placeHolderUrl'
: pinnedPosts[index]['imageUrl']!,
errorWidget: (context, url, error) {
return const CircularProgressIndicator();
},
height: SizeConfig.screenHeight! * 0.15,
fit: BoxFit.cover,
child: ListView.builder(
itemCount: pinnedPost.length,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.only(
left: 10,
),
child: GestureDetector(
onTap: () {
// final Map<String, dynamic> arg = {"index": "$index","post": pinnedPost};
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
PinnedPostScreen(post: pinnedPost[index]),
),
const SizedBox(height: 5),
Row(
);
},
child: SizedBox(
width: SizeConfig.screenWidth! / 4.1,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'${pinnedPosts[index]['time']!}hr',
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.w200,
Image.network(
(pinnedPost[index].imageUrl ?? '').isEmpty
? 'placeHolderUrl'
: pinnedPost[index].imageUrl!,
errorBuilder: (context, error, stackTrace) {
return const CircularProgressIndicator();
},
height: SizeConfig.screenHeight! * 0.15,
fit: BoxFit.cover,
),
const SizedBox(height: 5),
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'${pinnedPost[index].createdAt!}hr',
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.w200,
),
),
),
),
),
],
),
const SizedBox(height: 5),
Text(
pinnedPost[index].description!,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
const SizedBox(height: 5),
Text(
pinnedPosts[index]['title']!,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
),
),
),
)
: Container(),
: Container(
key: const Key('hi'),
),
);
}
}
Loading