majjin

featredCard

Oct 6th, 2020
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.15 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:makola_market/Models/product.dart';
  6. import 'package:makola_market/Pages/Content%20Cards/contentCard.dart';
  7. import 'package:makola_market/api.dart';
  8.  
  9. import '../../constants.dart';
  10. import '../productPage.dart';
  11.  
  12. class FeaturedCard extends StatefulWidget {
  13.   @override
  14.   State<StatefulWidget> createState() => _FeaturedCardState();
  15. }
  16.  
  17. class _FeaturedCardState extends State<FeaturedCard> {
  18.   @override
  19.   Widget build(BuildContext context) {
  20.     //Future<List<Product>> products = productsRandom(count: 3);
  21.     return FutureBuilder(
  22.       future: productsRandom(count: 3),
  23.       builder: (context, snapshot) {
  24.         if (snapshot.hasData) {
  25.           var images = <Widget>{};
  26.           for (var product in snapshot.data) {
  27.             images.add(GestureDetector(
  28.                 onTap: () => Navigator.pushNamed(context, ProductPage.routeName,
  29.                     arguments: product),
  30.                 child: Image(
  31.                     image: MemoryImage(
  32.                         base64Decode((product as Product).imageStr),
  33.                         scale: 2.5))));
  34.           }
  35.           return ContentCard(
  36.             Align(
  37.                 child: Text(
  38.                   'Featured Products',
  39.                   style: contentCardTitle,
  40.                 ),
  41.                 alignment: Alignment.centerLeft),
  42.             Row(
  43.               children: images.toList(),
  44.               mainAxisAlignment: MainAxisAlignment.spaceBetween,
  45.             ),
  46.             Container(
  47.               key: Key('FeaturedCardFooter'),
  48.             ),
  49.           );
  50.         } else if (snapshot.hasError) {
  51.           return Text(
  52.             snapshot.error.toString(),
  53.             style: optionStyle,
  54.           );
  55.         } else {
  56.           return ContentCard(
  57.             Text(
  58.               'Featured Products',
  59.               style: contentCardText,
  60.             ),
  61.             CircularProgressIndicator(),
  62.             Container(
  63.               key: Key('FeaturedCardFooter'),
  64.             ),
  65.           );
  66.         }
  67.       },
  68.     );
  69.   }
  70. }
  71.  
Add Comment
Please, Sign In to add comment