Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 16.52 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'dart:convert';
  4. import 'package:http/http.dart' as http;
  5. import 'package:after_layout/after_layout.dart';
  6.  
  7. final link =
  8.     "****";
  9.  
  10. Future<String> getData() async {
  11.   var res = await http
  12.       .get(Uri.encodeFull(link), headers: {"Accept": "application/json"});
  13.   if (res.statusCode == 200) {
  14.     var data = json.decode(res.body);
  15.     var page = data["page"] as Map;
  16.     //var container = data["container"] as List;
  17.     //var item = data["item"] as List;
  18.     //print(page["title"]);
  19.     var attributes = page["attributes"] as List;
  20.     //print(attributes[11]["value"]);
  21.     //print(container[0]["title"]);
  22.  
  23.     for (var i = 0; i < attributes.length; i++) {
  24.       if (attributes[i]["key"] == "image") {
  25.         return attributes[i]["value"].toString();
  26.       }
  27.     }
  28.   }
  29.  
  30.   return "https://picsum.photos/200/300";
  31. }
  32.  
  33. void main() {
  34.   runApp(MaterialApp(
  35.     home: HomeScreen(),
  36.   ));
  37. }
  38.  
  39. class HomeScreen extends StatefulWidget {
  40.   @override
  41.   HomeScreenState createState() => new HomeScreenState();
  42. }
  43.  
  44. class HomeScreenState extends State<HomeScreen> {
  45.   @override
  46.   Widget build(BuildContext context) {
  47.     Size screenSize = MediaQuery.of(context).size;
  48.     FutureBuilder<String>(
  49.       future: getData(), // if you mean this method well return image url
  50.  
  51.       builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
  52.         return Image.network(snapshot.data);
  53.       },
  54.     );
  55.     return Scaffold(
  56.         backgroundColor: Colors.black,
  57.         body: CustomScrollView(
  58.           slivers: <Widget>[
  59.             SliverAppBar(
  60.               primary: true,
  61.               expandedHeight: 430.0,
  62.               backgroundColor: Colors.black,
  63.               flexibleSpace: FlexibleSpaceBar(
  64.                 collapseMode: CollapseMode.pin,
  65.                 background: Container(
  66.                   child: Stack(
  67.                     fit: StackFit.loose,
  68.                     children: <Widget>[
  69.                       Container(
  70.                         width: screenSize.width,
  71.                         height: 220,
  72.                         child: Center(
  73.                           child: Container(
  74.                             height: 64.0,
  75.                             width: 64.0,
  76.                             child: OutlineButton(
  77.                               padding: EdgeInsets.all(0.0),
  78.                               onPressed: () => print('play'),
  79.                               shape: RoundedRectangleBorder(
  80.                                 borderRadius: BorderRadius.all(
  81.                                   Radius.circular(32.0),
  82.                                 ),
  83.                               ),
  84.                               child: Container(
  85.                                 height: 64.0,
  86.                                 width: 64.0,
  87.                                 decoration: BoxDecoration(
  88.                                   color: Color.fromRGBO(0, 0, 0, 0.3),
  89.                                   borderRadius: BorderRadius.circular(32.0),
  90.                                 ),
  91.                                 child: Icon(
  92.                                   Icons.play_arrow,
  93.                                   color: Colors.white,
  94.                                   size: 48.0,
  95.                                 ),
  96.                               ),
  97.                             ),
  98.                           ),
  99.                         ),
  100.                         decoration: BoxDecoration(
  101.                           image: DecorationImage(
  102.                             image: NetworkImage("https://picsum.photos/200/300"
  103.                                 //getData().toString(),
  104.                                 ),
  105.                             fit: BoxFit.fitWidth,
  106.                           ),
  107.                         ),
  108.                       ),
  109.                       Container(
  110.                         width: screenSize.width,
  111.                         height: 220,
  112.                         child: DecoratedBox(
  113.                           decoration: BoxDecoration(
  114.                             gradient: LinearGradient(
  115.                               begin: FractionalOffset.topCenter,
  116.                               end: FractionalOffset.bottomCenter,
  117.                               stops: [0.1, 0.4, 1.0],
  118.                               colors: [
  119.                                 Colors.black54,
  120.                                 Colors.transparent,
  121.                                 Colors.black
  122.                               ],
  123.                             ),
  124.                           ),
  125.                           child: Padding(
  126.                             padding: EdgeInsets.only(
  127.                                 left: 8.0, right: 8.0, bottom: 20.0),
  128.                             child: Column(
  129.                               mainAxisAlignment: MainAxisAlignment.end,
  130.                               crossAxisAlignment: CrossAxisAlignment.start,
  131.                               children: <Widget>[
  132.                                 Text(
  133.                                   "widget.item.name",
  134.                                   maxLines: 3,
  135.                                   textAlign: TextAlign.left,
  136.                                   style: TextStyle(
  137.                                     color: Colors.white,
  138.                                     fontWeight: FontWeight.w700,
  139.                                     fontSize: 18.0,
  140.                                   ),
  141.                                 )
  142.                               ],
  143.                             ),
  144.                           ),
  145.                         ),
  146.                       ),
  147.                       Positioned(
  148.                         top: 220,
  149.                         child: Container(
  150.                           padding: EdgeInsets.only(left: 8.0, right: 30.0),
  151.                           width: screenSize.width,
  152.                           child: Row(
  153.                             mainAxisAlignment: MainAxisAlignment.spaceBetween,
  154.                             children: <Widget>[
  155.                               Text(
  156.                                 'de coicidencia',
  157.                                 textAlign: TextAlign.left,
  158.                                 style: TextStyle(
  159.                                   color: Color.fromRGBO(0, 255, 0, 0.8),
  160.                                   fontWeight: FontWeight.w600,
  161.                                   fontSize: 15.0,
  162.                                 ),
  163.                               ),
  164.                               Text(
  165.                                 "widget.item.date.year.toString()",
  166.                                 textAlign: TextAlign.left,
  167.                                 style: TextStyle(
  168.                                   color: Color.fromRGBO(255, 255, 255, 0.3),
  169.                                   fontWeight: FontWeight.w400,
  170.                                   fontSize: 12.0,
  171.                                 ),
  172.                               ),
  173.                               Text(
  174.                                 '16 +',
  175.                                 textAlign: TextAlign.left,
  176.                                 style: TextStyle(
  177.                                   color: Color.fromRGBO(255, 255, 255, 0.3),
  178.                                   fontWeight: FontWeight.w400,
  179.                                   fontSize: 12.0,
  180.                                 ),
  181.                               ),
  182.                               Text(
  183.                                 'temporadas',
  184.                                 textAlign: TextAlign.left,
  185.                                 style: TextStyle(
  186.                                   color: Color.fromRGBO(255, 255, 255, 0.3),
  187.                                   fontWeight: FontWeight.w400,
  188.                                   fontSize: 12.0,
  189.                                 ),
  190.                               ),
  191.                             ],
  192.                           ),
  193.                         ),
  194.                       ),
  195.                       Positioned(
  196.                         top: 240,
  197.                         child: Container(
  198.                           padding: EdgeInsets.symmetric(horizontal: 8.0),
  199.                           width: screenSize.width,
  200.                           child: Column(
  201.                             mainAxisAlignment: MainAxisAlignment.start,
  202.                             crossAxisAlignment: CrossAxisAlignment.start,
  203.                             children: <Widget>[
  204.                               Padding(
  205.                                 padding: EdgeInsets.only(top: 8.0),
  206.                                 child: Container(
  207.                                   child: Text(
  208.                                     "widget.item.description",
  209.                                     overflow: TextOverflow.ellipsis,
  210.                                     maxLines: 3,
  211.                                     textAlign: TextAlign.left,
  212.                                     style: TextStyle(
  213.                                       color: Color.fromRGBO(255, 255, 255, 0.8),
  214.                                       fontWeight: FontWeight.w400,
  215.                                       fontSize: 12.0,
  216.                                     ),
  217.                                   ),
  218.                                 ),
  219.                               ),
  220.                               Padding(
  221.                                 padding: EdgeInsets.only(top: 8.0),
  222.                                 child: Container(
  223.                                   child: RichText(
  224.                                     maxLines: 2,
  225.                                     overflow: TextOverflow.ellipsis,
  226.                                     text: TextSpan(
  227.                                       style: TextStyle(
  228.                                         color:
  229.                                             Color.fromRGBO(255, 255, 255, 0.3),
  230.                                         fontWeight: FontWeight.w400,
  231.                                         fontSize: 12.0,
  232.                                       ),
  233.                                       children: <TextSpan>[
  234.                                         TextSpan(
  235.                                           text: 'Protagonizada por: ',
  236.                                           style: TextStyle(
  237.                                               fontWeight: FontWeight.bold),
  238.                                         ),
  239.                                         TextSpan(
  240.                                             text:
  241.                                                 "widget.item.cast.join(', ')"),
  242.                                       ],
  243.                                     ),
  244.                                   ),
  245.                                 ),
  246.                               ),
  247.                               Padding(
  248.                                 padding: EdgeInsets.only(top: 8.0),
  249.                                 child: Row(
  250.                                   children: <Widget>[
  251.                                     FlatButton(
  252.                                       textColor: Colors.white70,
  253.                                       onPressed: () => print('Mi Lista'),
  254.                                       child: Container(
  255.                                         height: 50.0,
  256.                                         child: Column(
  257.                                           mainAxisAlignment:
  258.                                               MainAxisAlignment.spaceAround,
  259.                                           children: <Widget>[
  260.                                             Icon(
  261.                                               Icons.add,
  262.                                               size: 32.0,
  263.                                             ),
  264.                                             Text(
  265.                                               'Mi Lista',
  266.                                               style: TextStyle(fontSize: 10.0),
  267.                                             )
  268.                                           ],
  269.                                         ),
  270.                                       ),
  271.                                     ),
  272.                                     FlatButton(
  273.                                       textColor: Colors.white70,
  274.                                       onPressed: () => print('calificar'),
  275.                                       child: Container(
  276.                                         height: 50.0,
  277.                                         child: Column(
  278.                                           mainAxisAlignment:
  279.                                               MainAxisAlignment.spaceAround,
  280.                                           children: <Widget>[
  281.                                             Icon(
  282.                                               Icons.thumb_up,
  283.                                               size: 24.0,
  284.                                             ),
  285.                                             Text(
  286.                                               'Calificar',
  287.                                               style: TextStyle(fontSize: 10.0),
  288.                                             )
  289.                                           ],
  290.                                         ),
  291.                                       ),
  292.                                     ),
  293.                                     FlatButton(
  294.                                       textColor: Colors.white70,
  295.                                       onPressed: () => print('Compartir'),
  296.                                       child: Container(
  297.                                         height: 50.0,
  298.                                         child: Column(
  299.                                           mainAxisAlignment:
  300.                                               MainAxisAlignment.spaceAround,
  301.                                           children: <Widget>[
  302.                                             Icon(
  303.                                               Icons.share,
  304.                                               size: 20.0,
  305.                                             ),
  306.                                             Text(
  307.                                               'Compartir',
  308.                                               style: TextStyle(fontSize: 10.0),
  309.                                             )
  310.                                           ],
  311.                                         ),
  312.                                       ),
  313.                                     ),
  314.                                   ],
  315.                                 ),
  316.                               ),
  317.                               Padding(
  318.                                 padding: EdgeInsets.only(top: 8.0),
  319.                                 child: Container(
  320.                                   child: Text(
  321.                                     'EPISODIOS',
  322.                                     overflow: TextOverflow.ellipsis,
  323.                                     maxLines: 3,
  324.                                     textAlign: TextAlign.left,
  325.                                     style: TextStyle(
  326.                                       color: Color.fromRGBO(255, 255, 255, 0.8),
  327.                                       fontWeight: FontWeight.w700,
  328.                                       fontSize: 15.0,
  329.                                     ),
  330.                                   ),
  331.                                 ),
  332.                               ),
  333.                               FlatButton(
  334.                                 padding: EdgeInsets.all(0.0),
  335.                                 child: Row(
  336.                                   children: <Widget>[
  337.                                     Text(
  338.                                       'Temporada ',
  339.                                       overflow: TextOverflow.ellipsis,
  340.                                       maxLines: 3,
  341.                                       textAlign: TextAlign.left,
  342.                                       style: TextStyle(
  343.                                         color:
  344.                                             Color.fromRGBO(255, 255, 255, 0.6),
  345.                                         fontWeight: FontWeight.w500,
  346.                                         fontSize: 15.0,
  347.                                       ),
  348.                                     ),
  349.                                   ],
  350.                                 ),
  351.                               ),
  352.                             ],
  353.                           ),
  354.                         ),
  355.                       ),
  356.                     ],
  357.                   ),
  358.                 ),
  359.               ),
  360.             ),
  361.           ],
  362.         ));
  363.   }
  364. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement