import 'package:flutter/material.dart';

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

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

  @override
  State<FavoriteList> createState() => _FavoriteListState();
}

class _FavoriteListState extends State<FavoriteList> {
  int selectedIndex = 0;
  List<String> favMenu = [
    'All',
    'Popular',
    'Favorite This Month',
    'Menu Lainnya',
    'Menu Lainnya',
    'Menu Lainnya'
  ];
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      scrollDirection: Axis.horizontal,
      itemCount: favMenu.length,
      itemBuilder: (context, i) {
        return Container(
          margin: EdgeInsets.only(
              left: (i == 0) ? 0 : 12.5,
              right: (i == favMenu.length - 1) ? 0 : 12.5),
          child: GestureDetector(
            onTap: () {
              setState(() {
                selectedIndex = i;
              });
            },
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                defaultText(
                  context,
                  favMenu[i],
                  style: favNameStyle(),
                ),
                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: 2),
                          width: 30,
                          height: 2,
                          color: buttonColor)
                      : const SizedBox(
                          key: Key('underline'),
                        ),
                )
              ],
            ),
          ),
        );
      },
    );
  }
}
