Advertisement
Wolf2012

CategoryItemComponent

Jun 24th, 2021
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.27 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:fooddelivery/models/CategoryModel.dart';
  3. import 'package:nb_utils/nb_utils.dart';
  4.  
  5. class CategoryItemComponent extends StatefulWidget {
  6.   final CategoryModel? category;
  7.   final int initialPosition;
  8.   final int index;
  9.   final Function(int index) onSelected;
  10.  
  11.   CategoryItemComponent({
  12.     required this.category,
  13.     required this.onSelected,
  14.     this.initialPosition = 0,
  15.     required this.index,
  16.   });
  17.  
  18.   @override
  19.   _CategoryItemComponentState createState() => _CategoryItemComponentState();
  20. }
  21.  
  22. class _CategoryItemComponentState extends State<CategoryItemComponent> {
  23.   late int current;
  24.  
  25.   @override
  26.   void initState() {
  27.     super.initState();
  28.     current = widget.initialPosition;
  29.   }
  30.  
  31.   @override
  32.   Widget build(BuildContext context) {
  33.     Size size = MediaQuery.of(context).size;
  34.     return GestureDetector(
  35.         onTap: () async {
  36.           setState(() => current = widget.index);
  37.           widget.onSelected(widget.index);
  38.         },
  39.         child: Stack(
  40.           alignment: Alignment.topCenter,
  41.           children: <Widget>[
  42.             Align(
  43.               alignment: Alignment.bottomCenter,
  44.               child: Container(
  45.                 height: size.height / 7,
  46.                 width: size.width / 5,
  47.                 decoration: boxDecorationWithRoundedCorners(
  48.                   //backgroundColor: Color(0xFF71B24D),
  49.                   backgroundColor: Colors.white,
  50.                 ),
  51.                 child: Column(
  52.                   mainAxisAlignment: MainAxisAlignment.spaceAround,
  53.                   children: <Widget>[
  54.                     Container(
  55.                       height: size.height / 14,
  56.                       //width: size.width / 5,
  57.                       decoration: BoxDecoration(
  58.                         image: DecorationImage(
  59.                             image:
  60.                                 Image.network(widget.category!.image.validate())
  61.                                     .image,
  62.                             fit: BoxFit.cover),
  63.                         shape: BoxShape.circle,
  64.                         color: Colors.white,
  65.                         boxShadow: defaultBoxShadow(
  66.                             spreadRadius: 0.0, blurRadius: 0.0),
  67.                       ),
  68.                     ),
  69.                     Text(
  70.                       widget.category!.categoryName.validate(),
  71.                       style: primaryTextStyle(
  72.                           color: Colors.black,
  73.                           fontFamily: 'Comfortaa',
  74.                           size: 12),
  75.                       maxLines: 2,
  76.                       textAlign: TextAlign.center,
  77.                       overflow: TextOverflow.ellipsis,
  78.                     ).paddingTop(3),
  79.                     Container(
  80.                         height: size.height / 60,
  81.                         width: size.width / 60,
  82.                         decoration: new BoxDecoration(
  83.                           color: Color(0xFF71B24D),
  84.                           shape: BoxShape.circle,
  85.                         )).visible(widget.index == current),
  86.                   ],
  87.                 ).paddingOnly(top: 5, left: 5, right: 5),
  88.               ),
  89.             ),
  90.           ],
  91.         ).paddingOnly(left: 5, right: 10));
  92.   }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement