import 'package:flutter/material.dart';

import '../../helper/helper.dart';
import '../../helper/widget/style.dart';

class CategoryList extends StatefulWidget {
  const CategoryList({
    Key? key,
  }) : super(key: key);

  @override
  State<CategoryList> createState() => _CategoryListState();
}

class _CategoryListState extends State<CategoryList> {
  int selectedIndex = 0;
  List<String> catMenu = [
    'All Item',
    'New',
    'Discount',
    'Food',
    'Beverage',
    'Additional'
  ];
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      scrollDirection: Axis.horizontal,
      itemCount: catMenu.length,
      itemBuilder: (context, i) {
        return Container(
          margin: EdgeInsets.only(
              left: (i == 0) ? 0 : 28.335,
              right: (i == catMenu.length - 1) ? 0 : 28.335),
          child: GestureDetector(
            onTap: () {
              setState(() {
                selectedIndex = i;
              });
            },
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                defaultText(
                  context,
                  catMenu[i],
                  style: catNameStyle(),
                ),
                AnimatedSwitcher(
                  duration: Duration(milliseconds: animatedTime),
                  transitionBuilder:
                      (Widget child, Animation<double> animation) {
                    return ScaleTransition(scale: animation, child: child);
                  },
                  child: (selectedIndex == i)
                      ? Container(
                          key: const Key('underline'),
                          margin: const EdgeInsets.only(top: 27),
                          width: 30,
                          height: 2,
                          color: buttonColor)
                      : const SizedBox(
                          key: Key('underline'),
                        ),
                )
              ],
            ),
          ),
        );
      },
    );
  }
}
