From 3f7b0298950c9686677fc76fa8ecad13039656bb Mon Sep 17 00:00:00 2001 From: Sparsh1212 Date: Mon, 5 Apr 2021 09:39:21 +0530 Subject: [PATCH] Fix #12: Convert issue card to stateless --- lib/pages/components/issue_intro_card.dart | 72 ++++++++++++++++++++ lib/pages/issues.dart | 79 +++------------------- 2 files changed, 80 insertions(+), 71 deletions(-) create mode 100644 lib/pages/components/issue_intro_card.dart diff --git a/lib/pages/components/issue_intro_card.dart b/lib/pages/components/issue_intro_card.dart new file mode 100644 index 0000000000..b7ebca47c4 --- /dev/null +++ b/lib/pages/components/issue_intro_card.dart @@ -0,0 +1,72 @@ +import 'package:flutter/material.dart'; + +class IssueCard extends StatelessWidget { + final String description; + final String imageSrc; + + IssueCard({required this.description, required this.imageSrc}); + + @override + Widget build(BuildContext context) { + return Column( + children: [ + Card( + margin: EdgeInsets.all(10), + elevation: 0, + clipBehavior: Clip.antiAlias, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topRight: Radius.circular(15.0), + bottomRight: Radius.circular(15.0))), + child: Container( + height: 130, + padding: const EdgeInsets.all(0), + child: Row( + children: [ + Container( + width: 200, + height: 130, + child: Hero( + tag: imageSrc, + child: DecoratedBox( + decoration: BoxDecoration( + image: DecorationImage( + image: NetworkImage(imageSrc), + fit: BoxFit.cover, + ), + ), + ), + ), + ), + Flexible( + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 10, + ), + child: Column( + children: [ + Row( + children: [ + Flexible( + child: Text( + description, + overflow: TextOverflow.fade, + softWrap: true, + style: TextStyle( + fontWeight: FontWeight.w600, fontSize: 12), + ), + ), + ], + ), + ], + ), + ), + ) + ], + ), + ), + ) + ], + ); + } +} diff --git a/lib/pages/issues.dart b/lib/pages/issues.dart index 863fe20d4d..0356a1a84e 100644 --- a/lib/pages/issues.dart +++ b/lib/pages/issues.dart @@ -1,3 +1,4 @@ +import './components/issue_intro_card.dart'; import 'package:flutter/material.dart'; import '../pages/issue_detail.dart'; @@ -119,77 +120,13 @@ class PaginatedClassState extends State ), ) }, - child: Column( - children: [ - Card( - margin: EdgeInsets.all(10), - elevation: 0, - clipBehavior: Clip.antiAlias, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topRight: Radius.circular(15.0), - bottomRight: Radius.circular(15.0))), - child: Container( - height: 130, - padding: const EdgeInsets.all(0), - child: Row( - children: [ - Container( - width: 200, - height: 130, - child: Hero( - tag: (snapshot.data! as DataModel) - .results[index] - .screenshot, - child: DecoratedBox( - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - (snapshot.data! as DataModel) - .results[index] - .screenshot, - ), - fit: BoxFit.cover, - ), - ), - ), - ), - ), - Flexible( - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 10, - ), - child: Column( - children: [ - Row( - children: [ - Flexible( - child: Text( - (snapshot.data! - as DataModel) - .results[index] - .description, - overflow: - TextOverflow.fade, - softWrap: true, - style: TextStyle( - fontWeight: - FontWeight.w600, - fontSize: 12), - ), - ), - ], - ), - ], - ), - ), - ) - ], - ), - ), - ) - ], + child: IssueCard( + description: (snapshot.data! as DataModel) + .results[index] + .description, + imageSrc: (snapshot.data! as DataModel) + .results[index] + .screenshot, ), ); });