Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.92 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'customIcons.dart';
  3. import 'data.dart';
  4. import 'dart:math';
  5.  
  6. void main() => runApp(MaterialApp(
  7.       home: MyApp(),
  8.       theme: ThemeData(
  9.         inputDecorationTheme: const InputDecorationTheme(
  10.           enabledBorder: OutlineInputBorder(
  11.           borderSide: BorderSide(color: Colors.white)),)
  12.       ),
  13.       debugShowCheckedModeBanner: false,
  14.     ));
  15.  
  16. class MyApp extends StatefulWidget {
  17.   @override
  18.   _MyAppState createState() => new _MyAppState();
  19. }
  20.  
  21. var cardAspectRatio = 12.0 / 16.0;
  22. var widgetAspectRatio = cardAspectRatio * 1.2;
  23.  
  24. class _MyAppState extends State<MyApp> {
  25.   var currentPage = images.length - 1.0;
  26.  
  27.   @override
  28.   Widget build(BuildContext context) {
  29.     PageController controller = PageController(initialPage: images.length - 1);
  30.     controller.addListener(() {
  31.       setState(() {
  32.         currentPage = controller.page;
  33.       });
  34.     });
  35.  
  36.     return Container(
  37.       decoration: BoxDecoration(
  38.           gradient: LinearGradient(
  39.               colors: [
  40.             Color(0xFF1b1e44),
  41.             Color(0xFF2d3447),
  42.           ],
  43.               begin: Alignment.bottomCenter,
  44.               end: Alignment.topCenter,
  45.               tileMode: TileMode.clamp)),
  46.       child: Scaffold(
  47.         backgroundColor: Colors.transparent,
  48.         body: SingleChildScrollView(
  49.           child: Column(
  50.             children: <Widget>[
  51.               Padding(
  52.                 padding: const EdgeInsets.only(
  53.                     left: 12.0, right: 12.0, top: 30.0, bottom: 8.0),
  54.                 child: Row(
  55.                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  56.                   children: <Widget>[
  57.                     IconButton(
  58.                       icon: Icon(
  59.                         CustomIcons.menu,
  60.                         color: Colors.white,
  61.                         size: 30.0,
  62.                       ),
  63.                       onPressed: () {},
  64.                     ),
  65.                    
  66.                   ],
  67.                 ),
  68.               ),
  69.               Padding(
  70.                 padding: EdgeInsets.symmetric(horizontal: 20.0),
  71.                 child: Row(
  72.                   mainAxisAlignment: MainAxisAlignment.start,
  73.                   children: <Widget>[
  74.                     Text("R\$ Conversor",
  75.                         style: TextStyle(
  76.                           color: Colors.white,
  77.                           fontSize: 36.0,
  78.                           fontFamily: "Calibre-Semibold",
  79.                           letterSpacing: 1.0,
  80.                         )),
  81.                    
  82.                   ],
  83.                 ),
  84.               ),
  85.                Padding(
  86.                 padding: EdgeInsets.symmetric(horizontal: 20.0),
  87.                 child: Row(
  88.                   crossAxisAlignment: CrossAxisAlignment.stretch,
  89.                   children: <Widget>[
  90.                     TextFormField(
  91.                       focusNode: FocusNode(),
  92.                       autocorrect: false,
  93.                       style: null,
  94.                       decoration: InputDecoration(
  95.                         fillColor: Colors.transparent,
  96.                         border: OutlineInputBorder(),
  97.                         focusedBorder: OutlineInputBorder(
  98.                             borderRadius: BorderRadius.all(Radius.circular(5.0)),
  99.                             borderSide: BorderSide(color: Colors.white)),
  100.                         filled: true,
  101.                         contentPadding:
  102.                             EdgeInsets.only(bottom: 10.0, left: 10.0, right: 10.0),
  103.                         labelText:"R\$",
  104.                         labelStyle: TextStyle(color: Colors.white),
  105.                       ),
  106.                     )
  107.                   ],
  108.                 )
  109.               ),
  110.              
  111.          
  112.               Padding(
  113.                 padding: EdgeInsets.symmetric(horizontal: 20.0),
  114.                 child:Container()
  115.                
  116.               ),
  117.              
  118.               Stack(
  119.                 children: <Widget>[
  120.                   CardScrollWidget(currentPage),
  121.                   Positioned.fill(
  122.                     child: PageView.builder(
  123.                       itemCount: images.length,
  124.                       controller: controller,
  125.                       reverse: true,
  126.                       itemBuilder: (context, index) {
  127.                         return Container();
  128.                       },
  129.                     ),
  130.                   )
  131.                 ],
  132.               ),
  133.              
  134.             ],
  135.           ),
  136.         ),
  137.       ),
  138.     );
  139.   }
  140. }
  141.  
  142. class CardScrollWidget extends StatelessWidget {
  143.   var currentPage;
  144.   var padding = 20.0;
  145.   var verticalInset = 20.0;
  146.  
  147.   CardScrollWidget(this.currentPage);
  148.  
  149.   @override
  150.   Widget build(BuildContext context) {
  151.     return new AspectRatio(
  152.       aspectRatio: widgetAspectRatio,
  153.       child: LayoutBuilder(builder: (context, contraints) {
  154.         var width = contraints.maxWidth;
  155.         var height = contraints.maxHeight;
  156.  
  157.         var safeWidth = width - 2 * padding;
  158.         var safeHeight = height - 2 * padding;
  159.  
  160.         var heightOfPrimaryCard = safeHeight;
  161.         var widthOfPrimaryCard = heightOfPrimaryCard * cardAspectRatio;
  162.  
  163.         var primaryCardLeft = safeWidth - widthOfPrimaryCard;
  164.         var horizontalInset = primaryCardLeft / 2;
  165.  
  166.         List<Widget> cardList = new List();
  167.  
  168.         for (var i = 0; i < images.length; i++) {
  169.           var delta = i - currentPage;
  170.           bool isOnRight = delta > 0;
  171.  
  172.           var start = padding +
  173.               max(
  174.                   primaryCardLeft -
  175.                       horizontalInset * -delta * (isOnRight ? 15 : 1),
  176.                   0.0);
  177.  
  178.           var cardItem = Positioned.directional(
  179.             top: padding + verticalInset * max(-delta, 0.0),
  180.             bottom: padding + verticalInset * max(-delta, 0.0),
  181.             start: start,
  182.             textDirection: TextDirection.rtl,
  183.             child: ClipRRect(
  184.               borderRadius: BorderRadius.circular(16.0),
  185.               child: Container(
  186.                 decoration: BoxDecoration(color: Colors.white, boxShadow: [
  187.                   BoxShadow(
  188.                       color: Colors.black12,
  189.                       offset: Offset(3.0, 6.0),
  190.                       blurRadius: 10.0)
  191.                 ]),
  192.                 child: AspectRatio(
  193.                   aspectRatio: cardAspectRatio,
  194.                   child: Stack(
  195.                     fit: StackFit.expand,
  196.                     children: <Widget>[
  197.                       Image.asset(images[i], fit: BoxFit.cover),
  198.                       Align(
  199.                         alignment: Alignment.bottomLeft,
  200.                         child: Column(
  201.                           mainAxisSize: MainAxisSize.min,
  202.                           crossAxisAlignment: CrossAxisAlignment.start,
  203.                           children: <Widget>[
  204.                             Text("Teste", style: TextStyle(color: Colors.white, fontSize: 40),),
  205.                             Padding(
  206.                               padding: EdgeInsets.symmetric(
  207.                                   horizontal: 16.0, vertical: 8.0),
  208.                               child: Text(title[i],
  209.                                   style: TextStyle(
  210.                                       color: Colors.white,
  211.                                       fontSize: 25.0,
  212.                                       fontFamily: "SF-Pro-Text-Regular")),
  213.                             ),
  214.                             SizedBox(
  215.                               height: 10.0,
  216.                             ),
  217.                            
  218.                           ],
  219.                         ),
  220.                       )
  221.                     ],
  222.                   ),
  223.                 ),
  224.               ),
  225.             ),
  226.           );
  227.           cardList.add(cardItem);
  228.         }
  229.         return Stack(
  230.           children: cardList,
  231.         );
  232.       }),
  233.     );
  234.   }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement