Advertisement
esiribiz

Untitled

Jul 27th, 2021
1,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.19 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:wrapwidgets/model/filter_chip_data.dart';
  3.  
  4. class FilterChips {
  5.   static final all = <FilterChipData>[
  6.     const FilterChipData(
  7.       label: ' Budget Sport',
  8.       image: 'assets/images/budgetsportlogo.png',
  9.       isSelected: false,
  10.       color: Colors.green,
  11.     ),
  12.     const FilterChipData(
  13.       label: ' Intersport ',
  14.       image: 'assets/images/intersport.jpg',
  15.       isSelected: false,
  16.       color: Colors.red,
  17.     ),
  18.     const FilterChipData(
  19.       label: ' Luhta',
  20.       image: 'assets/images/luhta2.jpg',
  21.       isSelected: false,
  22.       color: Colors.blue,
  23.     ),
  24.     const FilterChipData(
  25.       label: ' Partioaitta ',
  26.       image: 'assets/images/partioaitta.png',
  27.       isSelected: false,
  28.       color: Colors.orange,
  29.     ),
  30.     const FilterChipData(
  31.       label: ' XXL',
  32.       image: 'assets/images/xxl.png',
  33.       isSelected: false,
  34.       color: Colors.green,
  35.     ),
  36.  ];
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. import 'package:flutter/material.dart';
  44. import 'package:wrapwidgets/Data/filter_chips_second.dart';
  45. import 'package:wrapwidgets/model/company_list.dart';
  46. import 'package:wrapwidgets/model/filter_chip_data.dart';
  47.  
  48. class WrapWidgetDemo extends StatefulWidget {
  49.   //
  50.   final String title = 'Wrap Widget & Chips';
  51.  
  52.   @override
  53.   State<StatefulWidget> createState() => _WrapWidgetDemoState();
  54. }
  55.  
  56. class _WrapWidgetDemoState extends State<WrapWidgetDemo> {
  57.   //
  58.  
  59.   List<FilterChipData> filterChips = FilterChips.all;
  60.  
  61.   @override
  62.   void initState() {
  63.     super.initState();
  64.   }
  65.  
  66.   final double spacing = 8;
  67.  
  68.   @override
  69.   Widget build(BuildContext context) {
  70.     return Scaffold(
  71.       appBar: AppBar(
  72.         centerTitle: true,
  73.         title: Text(
  74.           widget.title,
  75.         ),
  76.       ),
  77.       body: Center(
  78.         child: Column(
  79.           children: <Widget>[
  80.             const Divider(
  81.               height: 40,
  82.             ),
  83.             const Padding(
  84.               padding: EdgeInsets.all(8.0),
  85.               child: Text(
  86.                 'What kind of sales offer whould you like to receive?',
  87.                 style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  88.               ),
  89.             ),
  90.             const Text(
  91.                 'Tap your favorite below to be the first to know when there are new offers.'),
  92.             const Divider(
  93.               height: 80,
  94.             ),
  95.             Container(child: buildFilterChips()),
  96.             /* Wrap(
  97.               children: companyWidgets.toList(),
  98.             ), */
  99.             const Divider(
  100.               height: 60,
  101.             ),
  102.             Text(
  103.               'Selected: ${filterChips.join(', ')}',
  104.               style: const TextStyle(fontWeight: FontWeight.bold),
  105.             ),
  106.           ],
  107.         ),
  108.       ),
  109.     );
  110.   }
  111.  
  112.   Widget buildFilterChips() => Wrap(
  113.         runSpacing: spacing,
  114.         spacing: spacing,
  115.         children: filterChips
  116.             .map((filterChip) => FilterChip(
  117.                   avatar: CircleAvatar(
  118.                       radius: 60.0,
  119.                       child: ClipRRect(
  120.                         borderRadius: BorderRadius.circular(50),
  121.                         child: Image.asset(filterChip.image),
  122.                       )
  123.                       //backgroundImage: AssetImage(filterChip.image),
  124.                       ),
  125.                   label: Text(filterChip.label),
  126.                   labelStyle: TextStyle(
  127.                     fontWeight: FontWeight.bold,
  128.                     color: filterChip.color,
  129.                   ),
  130.                   backgroundColor: filterChip.color.withOpacity(0.1),
  131.                   onSelected: (isSelected) => setState(() {
  132.                     filterChips = filterChips.map((otherChip) {
  133.                       return filterChip == otherChip
  134.                           ? otherChip.copy(isSelected: isSelected)
  135.                           : otherChip;
  136.                     }).toList();
  137.                   }),
  138.                   selected: filterChip.isSelected,
  139.                   checkmarkColor: filterChip.color,
  140.                   selectedColor: filterChip.color.withOpacity(0.25),
  141.                 ))
  142.             .toList(),
  143.       );
  144. }
  145.  
  146.  
  147.  
  148. import 'package:flutter/material.dart';
  149.  
  150. class FilterChipData {
  151.   final String label;
  152.   final String image;
  153.   final Color color;
  154.   final bool isSelected;
  155.  
  156.   const FilterChipData({
  157.     required this.label,
  158.     required this.image,
  159.     required this.color,
  160.     this.isSelected = false,
  161.   });
  162.  
  163.   FilterChipData copy({
  164.     String? label,
  165.     String? image,
  166.     Color? color,
  167.     bool? isSelected,
  168.   }) =>
  169.       FilterChipData(
  170.         label: label ?? this.label,
  171.         image: image ?? this.image,
  172.         color: color ?? this.color,
  173.         isSelected: isSelected ?? this.isSelected,
  174.       );
  175.  
  176.   @override
  177.   bool operator ==(Object other) =>
  178.       identical(this, other) ||
  179.       other is FilterChipData &&
  180.           runtimeType == other.runtimeType &&
  181.           label == other.label &&
  182.           image == other.image &&
  183.           color == other.color &&
  184.           isSelected == other.isSelected;
  185.  
  186.   @override
  187.   int get hashCode =>
  188.       label.hashCode ^ image.hashCode ^ color.hashCode ^ isSelected.hashCode;
  189. }
  190.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement