Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. class NewsItem extends StatefulWidget {
  2. NewsItem(this.newsArticle);
  3. final NewsArticle newsArticle;
  4. final bool expanded = false;
  5.  
  6. @override
  7. createState() => NewsItemState();
  8. }
  9.  
  10. class NewsItemState extends State<NewsItem> {
  11. void navigateToUrl(String url) async {
  12. if (await canLaunch(url)) {
  13. await launch(url);
  14. } else {
  15. throw 'Could not launch $url';
  16. }
  17. }
  18.  
  19. Widget build(BuildContext build) {
  20. return Container(
  21. decoration: BoxDecoration(
  22. borderRadius: BorderRadius.all(const Radius.circular(10)),
  23. color: Colors.white,
  24. boxShadow: [
  25. BoxShadow(
  26. color: Colors.grey[300],
  27. blurRadius: 20,
  28. spreadRadius: 3,
  29. offset: Offset(5, 5))
  30. ]),
  31. child: Column(
  32. children: <Widget>[
  33. Padding(
  34. padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
  35. child: Column(
  36. crossAxisAlignment: CrossAxisAlignment.stretch,
  37. children: <Widget>[
  38. widget.newsArticle.urlToImage == null
  39. ? AssetImage(Constants.NEWS_PLACEHOLDER_IMAGE_ASSET_URL)
  40. : CachedNetworkImage(
  41. imageUrl: widget.newsArticle.urlToImage),
  42. Padding(padding: const EdgeInsets.symmetric(vertical: 5)),
  43. Text(
  44. widget.newsArticle.title,
  45. textAlign: TextAlign.left,
  46. style: TextStyle(
  47. fontSize: 25,
  48. fontWeight: FontWeight.w700,
  49. height: 0.8,
  50. ),
  51. ),
  52. Padding(padding: const EdgeInsets.symmetric(vertical: 3)),
  53. expanded ? Text("Hello") : Container(),
  54. Platform.isIOS
  55. ? CupertinoButton.filled(
  56. child: Text(
  57. "Learn More",
  58. style: TextStyle(fontSize: 17),
  59. ),
  60. onPressed: () => navigateToUrl(widget.newsArticle.url),
  61. pressedOpacity: 0.6,
  62. )
  63. : RaisedButton(
  64. onPressed: () => navigateToUrl(widget.newsArticle.url),
  65. color: Color.fromRGBO(0, 122, 255, 1.0),
  66. animationDuration: Duration(milliseconds: 1000),
  67. child: Text(
  68. "Learn More",
  69. style: TextStyle(fontSize: 16, color: Colors.white),
  70. ),
  71. ),
  72. widget.expanded
  73. ? IconButton(
  74. icon: Icon(Icons.keyboard_arrow_up),
  75. onPressed: () {
  76. setState(() {
  77. widget.expanded = !widget.expanded;
  78. debugPrint(widget.expanded.toString());
  79. });
  80. },
  81. )
  82. : IconButton(
  83. icon: Icon(Icons.keyboard_arrow_down),
  84. onPressed: () {
  85. setState(() {
  86. widget.expanded = !widget.expanded;
  87. debugPrint(widget.expanded.toString());
  88. });
  89. })
  90. ],
  91. ),
  92. ),
  93. ],
  94. ),
  95. );
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement