Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:wrapwidgets/model/filter_chip_data.dart';
- class FilterChips {
- static final all = <FilterChipData>[
- const FilterChipData(
- label: ' Budget Sport',
- image: 'assets/images/budgetsportlogo.png',
- isSelected: false,
- color: Colors.green,
- ),
- const FilterChipData(
- label: ' Intersport ',
- image: 'assets/images/intersport.jpg',
- isSelected: false,
- color: Colors.red,
- ),
- const FilterChipData(
- label: ' Luhta',
- image: 'assets/images/luhta2.jpg',
- isSelected: false,
- color: Colors.blue,
- ),
- const FilterChipData(
- label: ' Partioaitta ',
- image: 'assets/images/partioaitta.png',
- isSelected: false,
- color: Colors.orange,
- ),
- const FilterChipData(
- label: ' XXL',
- image: 'assets/images/xxl.png',
- isSelected: false,
- color: Colors.green,
- ),
- ];
- }
- import 'package:flutter/material.dart';
- import 'package:wrapwidgets/Data/filter_chips_second.dart';
- import 'package:wrapwidgets/model/company_list.dart';
- import 'package:wrapwidgets/model/filter_chip_data.dart';
- class WrapWidgetDemo extends StatefulWidget {
- //
- final String title = 'Wrap Widget & Chips';
- @override
- State<StatefulWidget> createState() => _WrapWidgetDemoState();
- }
- class _WrapWidgetDemoState extends State<WrapWidgetDemo> {
- //
- List<FilterChipData> filterChips = FilterChips.all;
- @override
- void initState() {
- super.initState();
- }
- final double spacing = 8;
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- centerTitle: true,
- title: Text(
- widget.title,
- ),
- ),
- body: Center(
- child: Column(
- children: <Widget>[
- const Divider(
- height: 40,
- ),
- const Padding(
- padding: EdgeInsets.all(8.0),
- child: Text(
- 'What kind of sales offer whould you like to receive?',
- style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
- ),
- ),
- const Text(
- 'Tap your favorite below to be the first to know when there are new offers.'),
- const Divider(
- height: 80,
- ),
- Container(child: buildFilterChips()),
- /* Wrap(
- children: companyWidgets.toList(),
- ), */
- const Divider(
- height: 60,
- ),
- Text(
- 'Selected: ${filterChips.join(', ')}',
- style: const TextStyle(fontWeight: FontWeight.bold),
- ),
- ],
- ),
- ),
- );
- }
- Widget buildFilterChips() => Wrap(
- runSpacing: spacing,
- spacing: spacing,
- children: filterChips
- .map((filterChip) => FilterChip(
- avatar: CircleAvatar(
- radius: 60.0,
- child: ClipRRect(
- borderRadius: BorderRadius.circular(50),
- child: Image.asset(filterChip.image),
- )
- //backgroundImage: AssetImage(filterChip.image),
- ),
- label: Text(filterChip.label),
- labelStyle: TextStyle(
- fontWeight: FontWeight.bold,
- color: filterChip.color,
- ),
- backgroundColor: filterChip.color.withOpacity(0.1),
- onSelected: (isSelected) => setState(() {
- filterChips = filterChips.map((otherChip) {
- return filterChip == otherChip
- ? otherChip.copy(isSelected: isSelected)
- : otherChip;
- }).toList();
- }),
- selected: filterChip.isSelected,
- checkmarkColor: filterChip.color,
- selectedColor: filterChip.color.withOpacity(0.25),
- ))
- .toList(),
- );
- }
- import 'package:flutter/material.dart';
- class FilterChipData {
- final String label;
- final String image;
- final Color color;
- final bool isSelected;
- const FilterChipData({
- required this.label,
- required this.image,
- required this.color,
- this.isSelected = false,
- });
- FilterChipData copy({
- String? label,
- String? image,
- Color? color,
- bool? isSelected,
- }) =>
- FilterChipData(
- label: label ?? this.label,
- image: image ?? this.image,
- color: color ?? this.color,
- isSelected: isSelected ?? this.isSelected,
- );
- @override
- bool operator ==(Object other) =>
- identical(this, other) ||
- other is FilterChipData &&
- runtimeType == other.runtimeType &&
- label == other.label &&
- image == other.image &&
- color == other.color &&
- isSelected == other.isSelected;
- @override
- int get hashCode =>
- label.hashCode ^ image.hashCode ^ color.hashCode ^ isSelected.hashCode;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement