56 lines
1.6 KiB
Dart
56 lines
1.6 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import 'package:ui_kit/ui_kit.dart';
|
|
|
|
class CategoriesWidget extends StatefulWidget {
|
|
const CategoriesWidget({super.key, required this.itemsList});
|
|
final List<String> itemsList;
|
|
|
|
@override
|
|
State<CategoriesWidget> createState() => _CategoriesWidgetState();
|
|
}
|
|
|
|
class _CategoriesWidgetState extends State<CategoriesWidget> {
|
|
late String selectedItem;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
selectedItem = widget.itemsList[0];
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: width(context) * 100,
|
|
child: ListView.builder(
|
|
scrollDirection: Axis.horizontal,
|
|
itemCount: widget.itemsList.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
final currentItem = widget.itemsList[index];
|
|
Color currentItemColor = selectedItem == widget.itemsList[index]
|
|
? primaryColor
|
|
: inputBgColor;
|
|
return Container(
|
|
margin: EdgeInsets.only(right: 16),
|
|
child: Chips(
|
|
onPressed: () => {
|
|
setState(() {
|
|
print(currentItem);
|
|
selectedItem = currentItem;
|
|
}),
|
|
},
|
|
buttonText: widget.itemsList[index],
|
|
buttonStyle: textMedium.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
color: selectedItem == widget.itemsList[index]
|
|
? whiteColor
|
|
: descColor,
|
|
),
|
|
bgColor: currentItemColor,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|