Advertisement
Wolf2012

ChipsTakingFood

Jun 24th, 2021
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.79 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:nb_utils/nb_utils.dart';
  3.  
  4. class ChipsTakingFood extends StatefulWidget {
  5.   final List<String> values;
  6.   final int initialPosition;
  7.   final Function(int index) onSelected;
  8.  
  9.   ChipsTakingFood(
  10.       {required this.values,
  11.       required this.onSelected,
  12.       this.initialPosition = 0});
  13.  
  14.   @override
  15.   _RadioChipsState createState() => _RadioChipsState();
  16. }
  17.  
  18. class _RadioChipsState extends State<ChipsTakingFood> {
  19.   late int current;
  20.  
  21.   @override
  22.   void initState() {
  23.     super.initState();
  24.     current = widget.initialPosition;
  25.   }
  26.  
  27.   @override
  28.   Widget build(BuildContext context) {
  29.     Size size = MediaQuery.of(context).size;
  30.     return Container(
  31.       height: size.height / 15,
  32.       width: size.width / 1,
  33.       alignment: Alignment.center,
  34.       decoration: boxDecorationWithRoundedCorners(
  35.         //backgroundColor: Color(0xFF463E44),
  36.         borderRadius: BorderRadius.circular(0),
  37.       ),
  38.       child: Row(
  39.         mainAxisSize: MainAxisSize.min,
  40.         crossAxisAlignment: CrossAxisAlignment.center,
  41.         children: List.generate(
  42.           widget.values.length,
  43.           (index) {
  44.             return GestureDetector(
  45.               onTap: () async {
  46.                 setState(() => current = index);
  47.                 widget.onSelected(index);
  48.               },
  49.               child: Container(
  50.                 height: size.height / 15,
  51.                 width: size.width / 3.5,
  52.                 alignment: Alignment.center,
  53.                 margin: const EdgeInsets.symmetric(horizontal: 4),
  54.                 padding: const EdgeInsets.symmetric(horizontal: 20),
  55.                 decoration: BoxDecoration(
  56.                   borderRadius: const BorderRadius.all(Radius.circular(15)),
  57.                   color:
  58.                       index == current ? Color(0xFF71B24D) : Colors.grey[400],
  59.                 ),
  60.                 child: Column(
  61.                   mainAxisAlignment: MainAxisAlignment.center,
  62.                   children: [
  63.                     Icon(
  64.                       Icons.breakfast_dining_outlined,
  65.                       color: Colors.white,
  66.                     ).visible(index == 0),
  67.                     Icon(
  68.                       Icons.ramen_dining_outlined,
  69.                       color: Colors.white,
  70.                     ).visible(index == 1),
  71.                     Icon(
  72.                       Icons.dinner_dining_outlined,
  73.                       color: Colors.white,
  74.                     ).visible(index == 2),
  75.                     Text(widget.values[index],
  76.                         style: TextStyle(
  77.                             color: Colors.white, fontFamily: 'Comfortaa')),
  78.                   ],
  79.                 ),
  80.               ),
  81.             );
  82.           },
  83.         ),
  84.       ),
  85.     );
  86.   }
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement