Skip to content

Instantly share code, notes, and snippets.

@yakubpashask
Last active April 9, 2020 17:16
Show Gist options
  • Save yakubpashask/54426eaafb403a8f6f9de7ccc6a6be29 to your computer and use it in GitHub Desktop.
Save yakubpashask/54426eaafb403a8f6f9de7ccc6a6be29 to your computer and use it in GitHub Desktop.
StackOverFlow-PrintData
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: FilterScreen(),
),
),
);
}
}
class FilterScreen extends StatefulWidget {
final int id= 1;
@override
_FilterScreenState createState() => _FilterScreenState();
}
class Post{
int id;
String authorName;
String authorImageUrl;
String timeAgo;
String imageUrl;
Post({this.id,this.authorName,this.authorImageUrl,this.timeAgo,this.imageUrl});
Map<String, dynamic> toJson()=>{// to print the JSON
'id': this.id,
'authorName': this.authorName,
'authorImageUrl': this.authorImageUrl,
'timeAgo': this.timeAgo,
'imageUrl': this.imageUrl,
};
@override
String toString( ) {
return 'authorName: $authorName'; // to just print the author name
//return 'Post{id: $id, authorName: $authorName, authorImageUrl: $authorImageUrl, timeAgo: $timeAgo, imageUrl: $imageUrl}';
}
}
class _FilterScreenState extends State<FilterScreen> {
List showPost;
final List<Post> posts = [
Post(
id: 0,
authorName: 'Umaiz Khan',
authorImageUrl: 'assets/images/user0.png',
timeAgo: '5 min',
imageUrl: 'assets/images/post0.jpg',
),
Post(
id: 1,
authorName: 'Saad ahmed',
authorImageUrl: 'assets/images/user1.png',
timeAgo: '10 min',
imageUrl: 'assets/images/post1.jpg',
),
Post(
id: 2,
authorName: 'Hiba',
authorImageUrl: 'assets/images/user4.png',
timeAgo: '10 min',
imageUrl: 'assets/images/post2.jpg',
),
];
@override
void initState(){
super.initState();
showPost = posts.where((i) => i.id == widget.id).toList();
print(showPost.toJson());
//you can print the id
}
@override
Widget build(BuildContext context) {
return Container();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment