Untitled
unknown
plain_text
2 years ago
1.1 kB
14
Indexable
import 'package:flutter/material.dart';
class Categories extends StatefulWidget {
@override
CategoriesState createState() => CategoriesState();
}
class CategoriesState extends State<Categories> {
List<String> categories = [
"Hot Coffees",
"Cold Coffees",
"Hot Teas",
"Hot Drinks",
"Iced Teas",
"Specials",
];
int selectedIndex = 0;
@override
Widget build(BuildContext context) {
return SizedBox(
height: 75.0,
child: ListView.builder(
itemCount: categories.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => buildCategory(index),
),
);
}
Widget buildCategory(int index) {
return GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
categories[index],
style: TextStyle(
fontWeight: index == selectedIndex ? FontWeight.bold : FontWeight.normal,
),
),
),
);
}
}
Editor is loading...