Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NewsItem extends StatefulWidget {
- NewsItem(this.newsArticle);
- final NewsArticle newsArticle;
- final bool expanded = false;
- @override
- createState() => NewsItemState();
- }
- class NewsItemState extends State<NewsItem> {
- void navigateToUrl(String url) async {
- if (await canLaunch(url)) {
- await launch(url);
- } else {
- throw 'Could not launch $url';
- }
- }
- Widget build(BuildContext build) {
- return Container(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(const Radius.circular(10)),
- color: Colors.white,
- boxShadow: [
- BoxShadow(
- color: Colors.grey[300],
- blurRadius: 20,
- spreadRadius: 3,
- offset: Offset(5, 5))
- ]),
- child: Column(
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: <Widget>[
- widget.newsArticle.urlToImage == null
- ? AssetImage(Constants.NEWS_PLACEHOLDER_IMAGE_ASSET_URL)
- : CachedNetworkImage(
- imageUrl: widget.newsArticle.urlToImage),
- Padding(padding: const EdgeInsets.symmetric(vertical: 5)),
- Text(
- widget.newsArticle.title,
- textAlign: TextAlign.left,
- style: TextStyle(
- fontSize: 25,
- fontWeight: FontWeight.w700,
- height: 0.8,
- ),
- ),
- Padding(padding: const EdgeInsets.symmetric(vertical: 3)),
- expanded ? Text("Hello") : Container(),
- Platform.isIOS
- ? CupertinoButton.filled(
- child: Text(
- "Learn More",
- style: TextStyle(fontSize: 17),
- ),
- onPressed: () => navigateToUrl(widget.newsArticle.url),
- pressedOpacity: 0.6,
- )
- : RaisedButton(
- onPressed: () => navigateToUrl(widget.newsArticle.url),
- color: Color.fromRGBO(0, 122, 255, 1.0),
- animationDuration: Duration(milliseconds: 1000),
- child: Text(
- "Learn More",
- style: TextStyle(fontSize: 16, color: Colors.white),
- ),
- ),
- widget.expanded
- ? IconButton(
- icon: Icon(Icons.keyboard_arrow_up),
- onPressed: () {
- setState(() {
- widget.expanded = !widget.expanded;
- debugPrint(widget.expanded.toString());
- });
- },
- )
- : IconButton(
- icon: Icon(Icons.keyboard_arrow_down),
- onPressed: () {
- setState(() {
- widget.expanded = !widget.expanded;
- debugPrint(widget.expanded.toString());
- });
- })
- ],
- ),
- ),
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement