last63

Untitled

Sep 2nd, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. class NewsWidget extends StatelessWidget {
  2. const NewsWidget({
  3. super.key,
  4. required this.news,
  5. });
  6.  
  7. final Future news;
  8.  
  9. @override
  10. Widget build(BuildContext context) {
  11. return Container(
  12. child: Padding(
  13. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  14. child: SizedBox(
  15. child: FutureBuilder(
  16. future: news,
  17. builder: (context, snapshot) {
  18. if (snapshot.hasData) {
  19. return Column(
  20. children: snapshot.data.map<Widget>(
  21. (item) {
  22. return Card(
  23. elevation: 3,
  24. color: Colors.white,
  25. child: Padding(
  26. padding: const EdgeInsets.all(8.0),
  27. child: Row(
  28. children: [
  29. Icon(
  30. Icons.article_outlined,
  31. color: Colors.red,
  32. ),
  33. Expanded(
  34. child: ListTile(
  35. title: Text(
  36. item.title,
  37. style: TextStyle(
  38. fontFamily: 'Poppins',
  39. fontWeight: FontWeight.w500,
  40. ),
  41. maxLines: 2,
  42. overflow: TextOverflow.ellipsis,
  43. ),
  44. subtitle: Text(
  45. DateTime.fromMillisecondsSinceEpoch(
  46. item.timestamp!)
  47. .toString(),
  48. style: TextStyle(
  49. fontFamily: 'Poppins',
  50. fontWeight: FontWeight.w300,
  51. ),
  52. maxLines: 1,
  53. overflow: TextOverflow.ellipsis,
  54. ),
  55. ),
  56. ),
  57. InkWell(
  58. child: Icon(
  59. Icons.arrow_forward_ios_outlined,
  60. color: Colors.red,
  61. ),
  62. onTap: () {
  63. print('${item.title} tapped.');
  64.  
  65. Navigator.push(
  66. context,
  67. MaterialPageRoute(
  68. builder: (context) => NewsScreen(),
  69. ),
  70. );
  71. },
  72. ),
  73. ],
  74. ),
  75. ),
  76. );
  77. },
  78. ).toList(),
  79. );
  80. } else if (snapshot.hasError) {
  81. return Text('${snapshot.error}');
  82. }
  83. return const CircularProgressIndicator();
  84. },
  85. ),
  86. ),
  87. ),
  88. );
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment