m0rph3us

test2.dart

Aug 31st, 2021
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 10.06 KB | None | 0 0
  1. import 'package:cloud_firestore/cloud_firestore.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:lottie/lottie.dart';
  5. import 'package:pokemania_io/data/data.dart';
  6. import 'package:pokemania_io/widgets/previews.dart';
  7. import 'package:firebase_core/firebase_core.dart';
  8. import 'Screens/Detail.dart';
  9.  
  10. void main() async {
  11.   WidgetsFlutterBinding.ensureInitialized();
  12.   await Firebase.initializeApp();
  13.   SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  14.     statusBarColor: Colors.black38,
  15.     statusBarIconBrightness: Brightness.light,
  16.   ));
  17.   runApp(MyApp());
  18. }
  19.  
  20. class Homepage extends StatefulWidget {
  21.   @override
  22.   _HomepageState createState() => _HomepageState();
  23. }
  24.  
  25. class MyApp extends StatelessWidget {
  26.   // This widget is the root of your application.
  27.   @override
  28.   Widget build(BuildContext context) {
  29.     return MaterialApp(
  30.       debugShowCheckedModeBanner: false,
  31.       title: 'PokéMania',
  32.       theme: ThemeData.dark(),
  33.       home: Homepage(),
  34.     );
  35.   }
  36. }
  37.  
  38.  
  39.  
  40. class CustomAppBar extends StatelessWidget {
  41.   final double scrollOffset;
  42.  
  43.   const CustomAppBar({
  44.     Key key,
  45.     this.scrollOffset = 0.0,
  46.   }) : super(key: key);
  47.  
  48.  
  49.  
  50.   @override
  51.   Widget build(BuildContext context) {
  52.     return Container(
  53.         padding: const EdgeInsets.symmetric(
  54.           horizontal: 10.0,
  55.         ),
  56.         color: Colors.black
  57.             .withOpacity((scrollOffset / 350).clamp(0, 1).toDouble()),
  58.         child: SafeArea(
  59.             child: Row(
  60.           children: [
  61.             Image.asset(
  62.               'icons/logo.png',
  63.             ),
  64.             Padding(
  65.               padding: const EdgeInsets.only(left: 8.0),
  66.               child: Text('',
  67.                   style: TextStyle(
  68.                     color: Colors.white,
  69.                     fontFamily: 'font',
  70.                     fontSize: 18.0,
  71.                   )),
  72.             )
  73.           ],
  74.         )));
  75.   }
  76. }
  77.  
  78. class _HomepageState extends State<Homepage> {
  79.   ScrollController _scrollController;
  80.   double _scrollOffset = 0.0;
  81.  
  82.  
  83.   @override
  84.   void initState() {
  85.     _scrollController = ScrollController()
  86.       ..addListener(() {
  87.         setState(() {
  88.           _scrollOffset = _scrollController.offset;
  89.         });
  90.       });
  91.     super.initState();
  92.   }
  93.  
  94.   @override
  95.   void dispose() {
  96.     _scrollController.dispose();
  97.     super.dispose();
  98.   }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.   @override
  105.   Widget build(BuildContext context) {
  106.     final Size screenSize = MediaQuery.of(context).size;
  107.     routeToDetail(DocumentSnapshot infoDocumentSnapshot) {
  108.       Navigator.push(
  109.           context,
  110.           MaterialPageRoute(
  111.               builder: (context) => Detail(info: infoDocumentSnapshot)));
  112.     }
  113.  
  114.     return Scaffold(
  115.       backgroundColor: Colors.black,
  116.       extendBodyBehindAppBar: true,
  117.       appBar: PreferredSize(
  118.         preferredSize: Size(screenSize.width, 40.0),
  119.         child: CustomAppBar(
  120.           scrollOffset: _scrollOffset,
  121.         ),
  122.       ),
  123.       body: CustomScrollView(
  124.         controller: _scrollController,
  125.         slivers: [
  126.           SliverToBoxAdapter(
  127.               child: Stack(
  128.             alignment: Alignment.center,
  129.             children: [
  130.               Container(
  131.                 height: 500.0,
  132.                 decoration: BoxDecoration(
  133.                   image: DecorationImage(
  134.                     image: AssetImage('images/bgwall.jpg'),
  135.                     fit: BoxFit.cover,
  136.                   ),
  137.                 ),
  138.               ),
  139.               Container(
  140.                   height: 500.0,
  141.                   decoration: const BoxDecoration(
  142.                     gradient: LinearGradient(
  143.                       colors: [Colors.black, Colors.transparent],
  144.                       begin: Alignment.bottomCenter,
  145.                       end: Alignment.topCenter,
  146.                     ),
  147.                   )),
  148.               Positioned(
  149.                 bottom: 20.0,
  150.                 child: SizedBox(
  151.                     width: 250.0, child: Image.asset('images/pokelogo.png')),
  152.               )
  153.             ],
  154.           )),
  155.           SliverToBoxAdapter(
  156.             child: Padding(
  157.               padding: const EdgeInsets.only(top: 20.0),
  158.               child: Row(
  159.                 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  160.                 children: <Widget>[
  161.                   MaterialButton(
  162.                     onPressed: null,
  163.                     child: Column(
  164.                       children: <Widget>[
  165.                         Padding(
  166.                           padding: const EdgeInsets.only(top: 8.0),
  167.                           child: Image.asset('images/add.png',
  168.                               scale: 22.0, color: Colors.white),
  169.                         ),
  170.                         Padding(
  171.                           padding: const EdgeInsets.only(top: 8.0),
  172.                           child: Text(
  173.                             'My List',
  174.                             style:
  175.                                 TextStyle(color: Colors.white, fontSize: 18.0),
  176.                           ),
  177.                         )
  178.                       ],
  179.                     ),
  180.                   ),
  181.                   Container(
  182.                     decoration: BoxDecoration(
  183.                         color: Colors.white,
  184.                         borderRadius: BorderRadius.circular(5)),
  185.                     child: FlatButton.icon(
  186.                         onPressed: () {
  187.                         },
  188.                         icon: Padding(
  189.                           padding: const EdgeInsets.only(left: 15.0),
  190.                           child: Image.asset(
  191.                             'images/play.png',
  192.                             scale: 22.0,
  193.                             color: Colors.black,
  194.                           ),
  195.                         ),
  196.                         label: Text(
  197.                           '',
  198.                           style: TextStyle(color: Colors.black, fontSize: 18.0),
  199.                         )),
  200.                   ),
  201.                   MaterialButton(
  202.                     onPressed: null,
  203.                     child: Column(
  204.                       children: <Widget>[
  205.                         Padding(
  206.                           padding: const EdgeInsets.only(top: 8.0),
  207.                           child: Image.asset('images/inf.png',
  208.                               scale: 22.0, color: Colors.white),
  209.                         ),
  210.                         Padding(
  211.                           padding: const EdgeInsets.only(top: 8.0),
  212.                           child: Text(
  213.                             'Info',
  214.                             style:
  215.                                 TextStyle(color: Colors.white, fontSize: 18.0),
  216.                           ),
  217.                         )
  218.                       ],
  219.                     ),
  220.                   ),
  221.                 ],
  222.               ),
  223.             ),
  224.           ),
  225.           SliverPadding(
  226.             padding: const EdgeInsets.only(top: 20.0),
  227.             sliver: SliverToBoxAdapter(
  228.               child: Previews(
  229.                 title: 'Available Seasons',
  230.                 contentList: previews,
  231.               ),
  232.             ),
  233.           ),
  234.           SliverToBoxAdapter(
  235.             child: Padding(
  236.               padding: const EdgeInsets.only(top: 10.0),
  237.               child: SizedBox(
  238.                 height: 200,
  239.                 child: Column(
  240.                   children: <Widget>[
  241.                     Padding(
  242.                       padding: const EdgeInsets.only(right: 0.0),
  243.                       child: Text(
  244.                         'Season 1: Indigo League',
  245.                         style: TextStyle(
  246.                             color: Colors.white,
  247.                             fontSize: 16.0,
  248.                             fontWeight: FontWeight.bold),
  249.                         textAlign: TextAlign.start,
  250.                       ),
  251.                     ),
  252.                     SizedBox(
  253.                       height: 170.0,
  254.                       child: StreamBuilder<QuerySnapshot>(
  255.                         stream: FirebaseFirestore.instance
  256.                             .collection('Season 1: Indigo League')
  257.                             .orderBy('name')
  258.                             .snapshots(),
  259.                         builder: (context, snapshot) {
  260.                           if (snapshot.connectionState ==
  261.                               ConnectionState.waiting) {
  262.                             return Center(
  263.                                 child: Lottie.asset('animation/loading.json'));
  264.                           } else {
  265.                             final infoDocumentSnapshot = snapshot.data;
  266.  
  267.                             return new ListView.builder(
  268.                                 scrollDirection: Axis.horizontal,
  269.                                 itemCount: snapshot.data.docs.length,
  270.                                 itemBuilder: (_, index) {
  271.                                   return GestureDetector(
  272.                                     key: ValueKey("mylist_$index"),
  273.                                     onTap: () => routeToDetail(
  274.                                         infoDocumentSnapshot.docs[index]),
  275.                                     child: Padding(
  276.                                       padding: const EdgeInsets.all(8.0),
  277.                                       child: SizedBox(
  278.                                         height: 150.0,
  279.                                         width: 150.0,
  280.                                         child: Image.network(
  281.                                           snapshot.data.docs[index]
  282.                                               .data()['image'],
  283.                                           fit: BoxFit.cover,
  284.                                         ),
  285.                                       ),
  286.                                     ),
  287.                                   );
  288.                                 });
  289.                           }
  290.                         },
  291.                       ),
  292.                     )
  293.                   ],
  294.                 ),
  295.               ),
  296.             ),
  297.           ),
Add Comment
Please, Sign In to add comment